Skip to content

Commit

Permalink
Add git ignore and web workflows (#66)
Browse files Browse the repository at this point in the history
* Add github actions and gitignore file

* Update tests and version

---------

Co-authored-by: aguspe <[email protected]>
  • Loading branch information
aguspe and aguspe authored Sep 16, 2023
1 parent ae6df38 commit 33395c2
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lib/generators/actions/actions_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require_relative '../generator'

class ActionsGenerator < Generator
def generate_actions_file
return unless web?

template('actions.tt', "#{name}/.github/workflows/test_pipeline.yml")
end
end
64 changes: 64 additions & 0 deletions lib/generators/actions/templates/actions.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: <%- if framework == 'cucumber' -%>Cucumber Tests<%- else -%>Rspec Tests<%- end -%>

on:
workflow_dispatch:
inputs:
browser:
type: choice
description: Which browser to test
required: true
options:
- chrome

jobs:
build:
name: CI
runs-on: ubuntu-latest

steps:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.0
bundler-cache: true

- name: Checkout repository
uses: actions/checkout@v3

- name: Install gems
run: bundle install

- name: Create allure-results folder
run: mkdir -p allure-results

- name: Create screenshots folder
run: mkdir -p allure-results/screenshots

- name: Build and test with rspec
run: <%- if framework == 'cucumber' -%>cucumber features --format pretty <%- else -%>bundle exec rspec spec --format documentation<%- end -%>

- name: Get Allure history
uses: actions/checkout@v2
if: always()
continue-on-error: true
with:
ref: gh-pages
path: gh-pages

- name: Allure Report
uses: simple-elf/allure-report-action@master
if: always()
id: allure-report
with:
allure_results: allure-results
gh_pages: gh-pages
allure_report: allure-report
allure_history: allure-history

- name: Deploy report to Github Pages
if: always()
uses: peaceiris/actions-gh-pages@v2
env:
PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: allure-history
4 changes: 4 additions & 0 deletions lib/generators/common_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def generate_rubocop_file
template('common/rubocop.tt', "#{name}/.rubocop.yml")
end

def generate_gitignore_file
template('common/git_ignore.tt', "#{name}/.gitignore")
end

def create_allure_folder
empty_directory "#{name}/allure-results"
end
Expand Down
6 changes: 4 additions & 2 deletions lib/generators/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class Generator < Thor::Group

def self.source_paths
base_path = File.dirname(__FILE__)
%W[#{base_path}/automation/templates #{base_path}/cucumber/templates #{base_path}/rspec/templates #{base_path}/templates]
%W[#{base_path}/automation/templates #{base_path}/cucumber/templates
#{base_path}/rspec/templates #{base_path}/templates #{base_path}/actions/templates ]
end

def args
Expand Down Expand Up @@ -53,13 +54,14 @@ def watir?
end

def web?
args.include?(%w[selenium watir])
(args & (%w[selenium watir])).count.positive?
end

private

def _initializer
@_initializer ||= super
end

alias initializer _initializer
end
3 changes: 2 additions & 1 deletion lib/generators/invoke_generators.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative 'actions/actions_generator'
require_relative 'automation/automation_generator'
require_relative 'common_generator'
require_relative 'cucumber/cucumber_generator'
Expand All @@ -8,7 +9,7 @@
# :reek:UtilityFunction { enabled: false }
module InvokeGenerators
def generate_framework(structure = {})
generators = %w[Automation Common Helpers]
generators = %w[Automation Actions Common Helpers]
framework = structure[:framework]
add_generator(generators, framework.capitalize)
generators.each do |generator|
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/rspec_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class RspecGenerator < Generator
def generate_login_spec
return if mobile?
return unless web?

template('spec.tt', "#{name}/spec/login_page_spec.rb")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/common/gemfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gem 'rubocop'
<% if framework == 'rspec' -%>
gem 'rubocop-rspec'
<% end -%>
gem 'ruby_raider', '~> 0.7.0'
gem 'ruby_raider', '~> 0.8.0'
<%= ERB.new(File.read(File.expand_path('./partials/automation_gems.tt', __dir__))).result(binding).strip! %>
<% if automation == 'sparkling_ios' -%>
gem 'sparkling_watir'
Expand Down
1 change: 1 addition & 0 deletions lib/generators/templates/common/git_ignore.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allure-results
2 changes: 1 addition & 1 deletion lib/ruby_raider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def new(project_name)
desc 'version', 'It shows the version of Ruby Raider you are currently using'

def version
puts 'The Ruby Raider version is 0.7.9, Happy testing!'
puts 'The Ruby Raider version is 0.8.0, Happy testing!'
end

map 'v' => 'version'
Expand Down
2 changes: 1 addition & 1 deletion ruby_raider.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = 'ruby_raider'
s.version = '0.7.9'
s.version = '0.8.0'
s.summary = 'A gem to make setup and start of UI automation projects easier'
s.description = 'This gem has everything you need to start working with test automation'
s.authors = ['Agustin Pequeno']
Expand Down
28 changes: 28 additions & 0 deletions spec/actions_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require_relative '../lib/generators/actions/actions_generator'
require_relative 'spec_helper'

describe ActionsGenerator do
shared_examples 'creates web automation framework' do |name|
it 'creates a github actions file' do
expect(File).to exist("#{name}/.github/workflows/test_pipeline.yml")
end
end

context 'with rspec and selenium' do
include_examples 'creates web automation framework', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}"
end

context 'with rspec and watir' do
include_examples 'creates web automation framework', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}"
end

context 'with cucumber and selenium' do
include_examples 'creates web automation framework', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[2]}"
end

context 'with cucumber and watir' do
include_examples 'creates web automation framework', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[3]}"
end
end
18 changes: 18 additions & 0 deletions spec/common_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,71 +42,89 @@
end
end

shared_examples 'creates a gitignore file' do |name|
it 'creates a gitignore file' do
expect(File).to exist("#{name}/.gitignore")
end
end

context 'with rspec and selenium' do
include_examples 'creates common files', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}"
include_examples 'creates a config file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}"
end

context 'with rspec and watir' do
include_examples 'creates common files', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}"
include_examples 'creates a config file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}"
end

context 'with rspec, selenium and applitools' do
include_examples 'creates common files', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}_visual"
include_examples 'creates a config file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}_visual"
include_examples 'creates an options file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}_visual"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[2]}_visual"
end

context 'with rspec, watir and applitools' do
include_examples 'creates common files', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}_visual"
include_examples 'creates a config file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}_visual"
include_examples 'creates an options file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}_visual"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[3]}_visual"
end

context 'with cucumber and selenium' do
include_examples 'creates common files', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[2]}"
include_examples 'creates a config file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[2]}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[2]}"
end

context 'with cucumber and watir' do
include_examples 'creates common files', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[3]}"
include_examples 'creates a config file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[3]}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[3]}"
end

context 'with rspec and appium android' do
include_examples 'creates common files', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES.first}"
include_examples 'creates a capabilities file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES.first}"
include_examples "doesn't create a config file", "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES.first}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES.first}"
end

context 'with rspec and appium ios' do
include_examples 'creates common files', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[1]}"
include_examples 'creates a capabilities file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[1]}"
include_examples "doesn't create a config file", "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[1]}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES[1]}"
end

context 'with cucumber and appium android' do
include_examples 'creates common files', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES.first}"
include_examples 'creates a capabilities file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES.first}"
include_examples "doesn't create a config file", "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES.first}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES.first}"
end

context 'with cucumber and appium ios' do
include_examples 'creates common files', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[1]}"
include_examples 'creates a capabilities file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[1]}"
include_examples "doesn't create a config file", "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES[1]}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES.first}"
end

context 'with cucumber and appium cross platform' do
include_examples 'creates common files', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES.last}"
include_examples 'creates a capabilities file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES.last}"
include_examples 'creates a config file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES.last}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.first}_#{AUTOMATION_TYPES.last}"
end

context 'with rspec and appium cross platform' do
include_examples 'creates common files', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES.last}"
include_examples 'creates a capabilities file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES.last}"
include_examples 'creates a config file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES.last}"
include_examples 'creates a gitignore file', "#{FRAMEWORKS.last}_#{AUTOMATION_TYPES.last}"
end
end

0 comments on commit 33395c2

Please sign in to comment.