ruby_raider 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/lib/generators/files/automation_file_generator.rb +31 -130
  4. data/lib/generators/files/common_file_generator.rb +22 -150
  5. data/lib/generators/files/cucumber_file_generator.rb +22 -70
  6. data/lib/generators/files/file_generator.rb +7 -5
  7. data/lib/generators/files/helpers_file_generator.rb +46 -227
  8. data/lib/generators/files/rspec_file_generator.rb +19 -49
  9. data/lib/generators/projects/cucumber_project_generator.rb +17 -15
  10. data/lib/generators/projects/project_generator.rb +7 -5
  11. data/lib/generators/projects/rspec_project_generator.rb +13 -11
  12. data/lib/generators/templates/automation/abstract_component_template.rb +22 -0
  13. data/lib/generators/templates/automation/abstract_page_template.rb +48 -0
  14. data/lib/generators/templates/automation/component_template.rb +16 -0
  15. data/lib/generators/templates/automation/page_template.rb +51 -0
  16. data/lib/generators/templates/common/config_template.rb +9 -0
  17. data/lib/generators/templates/common/gemfile_template.rb +29 -0
  18. data/lib/generators/templates/common/rake_file_template.rb +16 -0
  19. data/lib/generators/templates/common/read_me_template.rb +104 -0
  20. data/lib/generators/templates/cucumber/env_template.rb +38 -0
  21. data/lib/generators/templates/cucumber/example_feature_template.rb +15 -0
  22. data/lib/generators/templates/cucumber/example_steps_template.rb +21 -0
  23. data/lib/generators/templates/helpers/allure_helper_template.rb +47 -0
  24. data/lib/generators/templates/helpers/browser_helper_template.rb +26 -0
  25. data/lib/generators/templates/helpers/driver_helper_template.rb +24 -0
  26. data/lib/generators/templates/helpers/pom_helper_template.rb +25 -0
  27. data/lib/generators/templates/helpers/raider_helper_template.rb +15 -0
  28. data/lib/generators/templates/helpers/selenium_helper_template.rb +42 -0
  29. data/lib/generators/templates/helpers/spec_helper_template.rb +35 -0
  30. data/lib/generators/templates/helpers/watir_helper_template.rb +24 -0
  31. data/lib/generators/templates/rspec/base_spec_template.rb +13 -0
  32. data/lib/generators/templates/rspec/example_spec_template.rb +33 -0
  33. data/lib/generators/templates/template.rb +14 -0
  34. data/ruby_raider.gemspec +1 -1
  35. data/spec/automation_file_generator_spec.rb +14 -5
  36. data/spec/common_file_generator_spec.rb +12 -3
  37. data/spec/cucumber_file_generator_spec.rb +26 -0
  38. data/spec/cucumber_project_generator_spec.rb +60 -0
  39. data/spec/helpers_file_generator_spec.rb +58 -16
  40. data/spec/rspec_file_generator_spec.rb +11 -2
  41. data/spec/rspec_project_generator_spec.rb +18 -9
  42. data/spec/spec_helper.rb +2 -12
  43. metadata +26 -3
  44. data/spec/menu_generator_spec.rb +0 -8
@@ -0,0 +1,104 @@
1
+ require_relative '../template'
2
+
3
+ class ReadMeTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ What is Raider?
7
+ ===========
8
+
9
+ Raider is a tool to make the setup and start of automation projects in ruby easier, with one command you are
10
+ ready to go
11
+
12
+ # Pre-requisites:
13
+
14
+ Install RVM:
15
+ https://rvm.io/rvm/install
16
+
17
+ # How to use the framework:
18
+
19
+ If you want to run all the tests from your terminal do:
20
+ *rspec spec/*
21
+
22
+ If you want to run all the tests in parallel do:
23
+ *parallel_rspec spec/*
24
+
25
+ # How are specs organized:
26
+
27
+ We use 'context' as the highest grouping level to indicate in which part of the application we are as an example:
28
+
29
+ *context 'On the login page'/*
30
+
31
+ We use 'describe' from the user perspective to describe an action that the user can or cannot take:
32
+
33
+ *describe 'A user can'/*
34
+
35
+ or
36
+
37
+ *describe 'A user cannot'/*
38
+
39
+ This saves us repetition and forces us into an structure
40
+
41
+ At last we use 'it' for the specific action the user can or cannot perform:
42
+
43
+ it 'login with right credentials'
44
+
45
+ If we group all of this together it will look like
46
+
47
+ ```ruby
48
+ context 'On the login page' do
49
+ describe 'A user can' do
50
+ it 'login with the right credentials' do
51
+ end
52
+ #{' '}
53
+ end
54
+ #{' '}
55
+ describe 'A user cannot' do
56
+ it 'login with the wrong credentials' do
57
+ end
58
+ end
59
+ end
60
+ ```
61
+ #{' '}
62
+ This is readed as 'On the login page a user can login with the right credentials' and 'On the login page a user cannot login with the wrong credentials'
63
+
64
+ # How pages are organized:
65
+
66
+ ```ruby#{' '}
67
+ require_relative '../abstract/base_page'
68
+
69
+ class MainPage < BasePage
70
+
71
+ using Raider::WatirHelper
72
+
73
+ def url(_page)
74
+ '/'
75
+ end
76
+
77
+ # Actions
78
+
79
+ def change_currency(currency)
80
+ currency_dropdown.select currency
81
+ end
82
+
83
+ # Validations
84
+
85
+ def validate_currency(currency)
86
+ expect(currency_dropdown.include?(currency)).to be true
87
+ end
88
+
89
+ private
90
+
91
+ # Elements
92
+
93
+ def currency_dropdown
94
+ browser.select(class: %w[dropdown-menu currency])
95
+ end
96
+ end
97
+ ```
98
+
99
+ Pages are organized in Actions (things a user can perform on the page), Validations (assertions), and Elements.
100
+ Each page has to have a url define, and each page is using the module WatirHelper to add methods on runtime to the Watir elements
101
+
102
+ EOF
103
+ end
104
+ end
@@ -0,0 +1,38 @@
1
+ require_relative '../template'
2
+
3
+ class EnvTemplate < Template
4
+ def body
5
+
6
+ if @automation == 'watir'
7
+ helper = 'helpers/browser_helper'
8
+ browser = 'Raider::BrowserHelper.new_browser'
9
+ get_browser = 'browser = Raider::BrowserHelper.new_browser'
10
+ screenshot = 'browser.screenshot.save("allure-results/screenshots/#{scenario.name}.png")'
11
+ quit = 'browser.quit'
12
+ else
13
+ helper = 'helpers/driver_helper'
14
+ browser = 'Raider::DriverHelper.new_driver'
15
+ get_browser = 'driver = Raider::DriverHelper.driver'
16
+ screenshot = 'driver.save_screenshot("allure-results/screenshots/#{scenario.name}.png")'
17
+ quit = 'driver.quit'
18
+ end
19
+
20
+ <<~EOF
21
+ require 'active_support/all'
22
+ require_relative 'helpers/allure_helper'
23
+ require_relative '#{helper}'
24
+
25
+ Before do
26
+ Raider::AllureHelper.configure
27
+ #{browser}
28
+ end
29
+
30
+ After do |scenario|
31
+ #{get_browser}
32
+ #{screenshot}
33
+ Raider::AllureHelper.add_screenshot(scenario.name)
34
+ #{quit}
35
+ end
36
+ EOF
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../template'
2
+
3
+ class ExampleFeatureTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ Feature: Login Page
7
+
8
+ Scenario: A user can login
9
+ Given I'm a registered user on the login page
10
+ When I login with my credentials
11
+ Then I can see the main page
12
+
13
+ EOF
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../template'
2
+
3
+ class ExampleStepsTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ require_relative '../../page_objects/pages/login_page'
7
+
8
+ Given("I'm a registered user on the login page") do
9
+ LoginPage.visit
10
+ end
11
+
12
+ When('I login with my credentials') do
13
+ LoginPage.login('aguspe', '12341234')
14
+ end
15
+
16
+ When('I can see the main page') do
17
+ expect(LoginPage.header.customer_name).to eq 'Welcome back Agustin'
18
+ end
19
+ EOF
20
+ end
21
+ end
@@ -0,0 +1,47 @@
1
+ require_relative '../template'
2
+
3
+ class AllureHelperTemplate < Template
4
+ def body
5
+ if @framework == 'cucumber'
6
+ gems = "require 'allure-cucumber'"
7
+ allure = 'AllureCucumber'
8
+ else
9
+ gems = "require 'allure-ruby-commons'
10
+ require 'allure-rspec'"
11
+ allure = 'AllureRspec'
12
+ end
13
+ <<~EOF
14
+ #{gems}
15
+
16
+ module Raider
17
+ module AllureHelper
18
+ class << self
19
+
20
+ def configure
21
+ #{allure}.configure do |config|
22
+ config.results_directory = 'allure-results'
23
+ config.clean_results_directory = true
24
+ end
25
+ end
26
+
27
+ def add_screenshot(screenshot_name)
28
+ Allure.add_attachment(
29
+ name: name,
30
+ source: "File.open(allure-results/screenshots/\#{screenshot_name}.png)",
31
+ type: Allure::ContentType::PNG,
32
+ test_case: true
33
+ )
34
+ end
35
+
36
+ #{
37
+ if @framework == 'rspec'
38
+ 'def formatter
39
+ AllureRspecFormatter
40
+ end'
41
+ end }
42
+ end
43
+ end
44
+ end
45
+ EOF
46
+ end
47
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../template'
2
+
3
+ class BrowserHelperTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ require 'yaml'
7
+ require 'selenium-webdriver'
8
+ require 'watir'
9
+ require 'webdrivers'
10
+
11
+ module Raider
12
+ module BrowserHelper
13
+ class << self
14
+ attr_reader :browser
15
+
16
+ def new_browser
17
+ config = YAML.load_file('config/config.yml')
18
+ @browser = Watir::Browser.new config['browser']
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ EOF
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../template'
2
+
3
+ class DriverHelperTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ require 'selenium-webdriver'
7
+ require 'watir'
8
+ require 'webdrivers'
9
+ require 'yaml'
10
+
11
+ module Raider
12
+ module DriverHelper
13
+ class << self
14
+ attr_reader :driver
15
+
16
+ def new_driver
17
+ @driver = Selenium::WebDriver.for :chrome
18
+ end
19
+ end
20
+ end
21
+ end
22
+ EOF
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require_relative '../template'
2
+
3
+ class PomHelperTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ module Raider
7
+ module PomHelper
8
+ def instance
9
+ @instance ||= new
10
+ end
11
+
12
+ def method_missing(message, *args, &block)
13
+ return super unless instance.respond_to?(message)
14
+
15
+ instance.public_send(message, *args, &block)
16
+ end
17
+
18
+ def respond_to_missing?(method, *_args, &block)
19
+ instance.respond_to?(method) || super
20
+ end
21
+ end
22
+ end
23
+ EOF
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../template'
2
+
3
+ class RaiderHelperTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ module Raider
7
+ #{"require_relative 'spec_helper'" if @framework == 'rspec'}
8
+ require_relative '#{@automation}_helper'
9
+ require_relative 'pom_helper'
10
+ require_relative '#{@automation == 'watir' ? 'browser_helper' : 'driver_helper'}'
11
+ require_relative 'allure_helper'
12
+ end
13
+ EOF
14
+ end
15
+ end
@@ -0,0 +1,42 @@
1
+ require_relative '../template'
2
+
3
+ class SeleniumHelperTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ require 'selenium-webdriver'
7
+ require_relative 'driver_helper'
8
+
9
+ module Raider
10
+ module SeleniumHelper
11
+ def click_when_present
12
+ # This is an example of an implicit wait in selenium
13
+ wait = Selenium::WebDriver::Wait.new(timeout: 15)
14
+ wait.until { present? }
15
+ click
16
+ end
17
+
18
+ def select_by(key, value)
19
+ # Creates new Select object to use the select by method
20
+ dropdown = Selenium::WebDriver::Support::Select.new self
21
+ dropdown.select_by(key, value)
22
+ end
23
+
24
+ def hover
25
+ # Using actions to move the mouse over an element
26
+ DriverHelper.driver.action.move_to(self).perform
27
+ end
28
+
29
+ # How to perform right click through the context click method
30
+ def right_click
31
+ DriverHelper.driver.action.context_click(self).perform
32
+ end
33
+ end
34
+
35
+ # Here we are opening the selenium class and adding our custom method
36
+ class Selenium::WebDriver::Element
37
+ include SeleniumHelper
38
+ end
39
+ end
40
+ EOF
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../template'
2
+
3
+ class SpecHelperTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ require 'active_support/all'
7
+ require 'rspec'
8
+ require_relative 'allure_helper'
9
+ require_relative '#{@automation == 'watir' ? 'browser_helper' : 'driver_helper'}'
10
+
11
+ module Raider
12
+ module SpecHelper
13
+
14
+ AllureHelper.configure
15
+
16
+ RSpec.configure do |config|
17
+ config.formatter = AllureHelper.formatter
18
+ config.before(:each) do
19
+ #{@automation == 'watir' ? 'BrowserHelper.new_browser' : 'DriverHelper.new_driver'}
20
+ end
21
+
22
+ config.after(:each) do
23
+ #{@automation == 'watir' ? 'browser = BrowserHelper.browser' : 'driver = DriverHelper.driver'}
24
+ example_name = self.class.descendant_filtered_examples.first.description
25
+ status = self.class.descendant_filtered_examples.first.execution_result.status
26
+ #{@automation == 'watir' ? 'browser' : 'driver'}.save_screenshot("allure-results/screenshots/#\{example_name}.png") if status == :failed
27
+ AllureHelper.add_screenshot example_name if status == :failed
28
+ #{@automation == 'watir' ? 'browser.quit' : 'driver.quit'}
29
+ end
30
+ end
31
+ end
32
+ end
33
+ EOF
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../template'
2
+
3
+ class WatirHelperTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ require 'watir'
7
+
8
+ module Raider
9
+ module WatirHelper
10
+ refine Watir::Element do
11
+ def click_when_present
12
+ wait_until_present
13
+ self.click
14
+ end
15
+
16
+ def wait_until_present
17
+ self.wait_until(&:present?)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ EOF
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../template'
2
+
3
+ class BaseSpecTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ require_relative '../helpers/raider'
7
+
8
+ class BaseSpec
9
+ include Raider::SpecHelper
10
+ end
11
+ EOF
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require_relative '../template'
2
+
3
+ class ExampleSpecTemplate < Template
4
+ def body
5
+ <<~EOF
6
+ require_relative 'base_spec'
7
+ require_relative '../page_objects/pages/login_page'
8
+
9
+ class LoginSpec < BaseSpec
10
+ context 'On the Login Page' do
11
+
12
+ before(:each) do
13
+ LoginPage.visit
14
+ end
15
+
16
+ describe 'A user can' do
17
+ it 'login with the right credentials', :JIRA_123 do
18
+ LoginPage.login('aguspe', '12341234')
19
+ expect(LoginPage.header.customer_name).to eq 'Welcome back Agustin'
20
+ end
21
+ end
22
+
23
+ describe 'A user cannot' do
24
+ it 'login with the wrong credentials', :JIRA_123 do
25
+ LoginPage.login('aguspe', 'wrongPassword')
26
+ expect(LoginPage.header.customer_name).to be_empty
27
+ end
28
+ end
29
+ end
30
+ end
31
+ EOF
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ require 'erb'
2
+
3
+ class Template
4
+ def initialize(args = {})
5
+ @automation = args[:automation]
6
+ @name = args[:name]
7
+ @framework = args[:framework]
8
+ end
9
+
10
+ def parsed_body
11
+ parsed_body = ERB.new body
12
+ parsed_body.result(binding)
13
+ end
14
+ end
data/ruby_raider.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ruby_raider'
3
- s.version = '0.1.5'
3
+ s.version = '0.1.7'
4
4
  s.summary = 'A gem to make setup and start of UI automation projects easier'
5
5
  s.description = 'This gem contents everything you need to start doing web automation in one simple package'
6
6
  s.authors = ['Agustin Pequeno']
@@ -2,24 +2,33 @@ require_relative '../lib/generators/files/automation_file_generator'
2
2
  require_relative 'spec_helper'
3
3
 
4
4
  describe RubyRaider::AutomationFileGenerator do
5
+ before(:all) do
6
+ @name = 'Rspec-watir-1'
7
+ RubyRaider::RspecProjectGenerator.generate_rspec_project(@name, automation: 'watir')
8
+ end
9
+
5
10
  it 'creates a login page file' do
6
- expect(File.exist?("#{@project_name}/page_objects/pages/login_page.rb")).to be_truthy
11
+ expect(File.exist?("#{@name}/page_objects/pages/login_page.rb")).to be_truthy
7
12
  end
8
13
 
9
14
  it 'creates an abstract page file' do
10
- expect(File.exist?("#{@project_name}/page_objects/abstract/abstract_page.rb")).to be_truthy
15
+ expect(File.exist?("#{@name}/page_objects/abstract/abstract_page.rb")).to be_truthy
11
16
  end
12
17
 
13
18
  it 'creates an abstract component file' do
14
- expect(File.exist?("#{@project_name}/page_objects/abstract/abstract_component.rb")).to be_truthy
19
+ expect(File.exist?("#{@name}/page_objects/abstract/abstract_component.rb")).to be_truthy
15
20
  end
16
21
 
17
22
  it 'creates a component file' do
18
- expect(File.exist?("#{@project_name}/page_objects/components/header_component.rb")).to be_truthy
23
+ expect(File.exist?("#{@name}/page_objects/components/header_component.rb")).to be_truthy
19
24
  end
20
25
 
21
26
  it 'creates a gemfile file' do
22
- expect(File.exist?("#{@project_name}/Gemfile")).to be_truthy
27
+ expect(File.exist?("#{@name}/Gemfile")).to be_truthy
28
+ end
29
+
30
+ after(:all) do
31
+ FileUtils.rm_rf(@name)
23
32
  end
24
33
  end
25
34
 
@@ -2,16 +2,25 @@ require_relative '../lib/generators/files/common_file_generator'
2
2
  require_relative 'spec_helper'
3
3
 
4
4
  describe RubyRaider::CommonFileGenerator do
5
+ before(:all) do
6
+ @name = 'Cucumber-watir-1'
7
+ RubyRaider::CucumberProjectGenerator.generate_cucumber_project(@name, automation: 'watir')
8
+ end
9
+
5
10
  it 'creates a config file' do
6
- expect(File.exist?("#{@project_name}/config/config.yml")).to be_truthy
11
+ expect(File.exist?("#{@name}/config/config.yml")).to be_truthy
7
12
  end
8
13
 
9
14
  it 'creates a rake file' do
10
- expect(File.exist?("#{@project_name}/Rakefile")).to be_truthy
15
+ expect(File.exist?("#{@name}/Rakefile")).to be_truthy
11
16
  end
12
17
 
13
18
  it 'creates a readMe file' do
14
- expect(File.exist?("#{@project_name}/Readme.md")).to be_truthy
19
+ expect(File.exist?("#{@name}/Readme.md")).to be_truthy
20
+ end
21
+
22
+ after(:all) do
23
+ FileUtils.rm_rf(@name)
15
24
  end
16
25
  end
17
26
 
@@ -0,0 +1,26 @@
1
+ require_relative '../lib/generators/files/rspec_file_generator'
2
+ require_relative 'spec_helper'
3
+
4
+ describe RubyRaider::RspecFileGenerator do
5
+ before(:all) do
6
+ @name = 'Cucumber-watir-2'
7
+ RubyRaider::CucumberProjectGenerator.generate_cucumber_project(@name, automation: 'watir')
8
+ end
9
+
10
+ it 'creates a feature file' do
11
+ expect(File.exist?("#{@name}/features/login.feature")).to be_truthy
12
+ end
13
+
14
+ it 'creates a step definitions file' do
15
+ expect(File.exist?("#{@name}/features/step_definitions/login_steps.rb")).to be_truthy
16
+ end
17
+
18
+ it 'creates an env file' do
19
+ expect(File.exist?("#{@name}/features/support/env.rb")).to be_truthy
20
+ end
21
+
22
+ after(:all) do
23
+ FileUtils.rm_rf(@name)
24
+ end
25
+ end
26
+
@@ -0,0 +1,60 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe RubyRaider::CucumberProjectGenerator do
4
+ before(:all) do
5
+ @name = 'Cucumber'
6
+ RubyRaider::CucumberProjectGenerator.generate_cucumber_project(@name, automation: 'selenium')
7
+ end
8
+
9
+ it 'creates a project folder' do
10
+ expect(Dir.exist?(@name)).to be_truthy
11
+ end
12
+
13
+ it 'creates a features folder' do
14
+ expect(Dir.exist?("#{@name}/features")).to be_truthy
15
+ end
16
+
17
+ it 'creates a config folder' do
18
+ expect(Dir.exist?("#{@name}/config")).to be_truthy
19
+ end
20
+
21
+ it 'creates a page_objects object folder' do
22
+ expect(Dir.exist?("#{@name}/page_objects")).to be_truthy
23
+ end
24
+
25
+ it 'creates an allure results folder' do
26
+ expect(Dir.exist?("#{@name}/allure-results")).to be_truthy
27
+ end
28
+
29
+ it 'creates a step definitions folder' do
30
+ expect(Dir.exist?("#{@name}/features/step_definitions")).to be_truthy
31
+ end
32
+
33
+ it 'creates a support folder' do
34
+ expect(Dir.exist?("#{@name}/features/support")).to be_truthy
35
+ end
36
+
37
+ it 'creates a helpers folder' do
38
+ expect(Dir.exist?("#{@name}/features/support/helpers")).to be_truthy
39
+ end
40
+
41
+ it 'creates an abstract folder' do
42
+ expect(Dir.exist?("#{@name}/page_objects/abstract")).to be_truthy
43
+ end
44
+
45
+ it 'creates a pages folder' do
46
+ expect(Dir.exist?("#{@name}/page_objects/pages")).to be_truthy
47
+ end
48
+
49
+ it 'creates a components folder' do
50
+ expect(Dir.exist?("#{@name}/page_objects/components")).to be_truthy
51
+ end
52
+
53
+ it 'creates a screenshot folder' do
54
+ expect(Dir.exist?("#{@name}/allure-results/screenshots")).to be_truthy
55
+ end
56
+
57
+ after(:all) do
58
+ FileUtils.rm_rf(@name)
59
+ end
60
+ end