ruby_raider 0.1.5 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/lib/generators/files/automation_file_generator.rb +53 -129
- data/lib/generators/files/common_file_generator.rb +24 -148
- data/lib/generators/files/cucumber_file_generator.rb +22 -70
- data/lib/generators/files/file_generator.rb +7 -5
- data/lib/generators/files/helpers_file_generator.rb +51 -225
- data/lib/generators/files/rspec_file_generator.rb +20 -49
- data/lib/generators/menu_generator.rb +44 -29
- data/lib/generators/projects/cucumber_project_generator.rb +25 -15
- data/lib/generators/projects/project_generator.rb +21 -5
- data/lib/generators/projects/rspec_project_generator.rb +17 -11
- data/lib/generators/templates/automation/abstract_component_template.rb +22 -0
- data/lib/generators/templates/automation/abstract_page_template.rb +82 -0
- data/lib/generators/templates/automation/appium_settings_template.rb +16 -0
- data/lib/generators/templates/automation/component_template.rb +16 -0
- data/lib/generators/templates/automation/confirmation_page_template.rb +26 -0
- data/lib/generators/templates/automation/home_page_template.rb +26 -0
- data/lib/generators/templates/automation/login_page_template.rb +113 -0
- data/lib/generators/templates/common/config_template.rb +9 -0
- data/lib/generators/templates/common/gemfile_template.rb +52 -0
- data/lib/generators/templates/common/rake_file_template.rb +16 -0
- data/lib/generators/templates/common/read_me_template.rb +104 -0
- data/lib/generators/templates/cucumber/env_template.rb +38 -0
- data/lib/generators/templates/cucumber/example_feature_template.rb +15 -0
- data/lib/generators/templates/cucumber/example_steps_template.rb +21 -0
- data/lib/generators/templates/helpers/allure_helper_template.rb +47 -0
- data/lib/generators/templates/helpers/browser_helper_template.rb +26 -0
- data/lib/generators/templates/helpers/driver_helper_template.rb +54 -0
- data/lib/generators/templates/helpers/pom_helper_template.rb +25 -0
- data/lib/generators/templates/helpers/raider_helper_template.rb +27 -0
- data/lib/generators/templates/helpers/selenium_helper_template.rb +42 -0
- data/lib/generators/templates/helpers/spec_helper_template.rb +74 -0
- data/lib/generators/templates/helpers/watir_helper_template.rb +24 -0
- data/lib/generators/templates/rspec/base_spec_template.rb +13 -0
- data/lib/generators/templates/rspec/example_spec_template.rb +56 -0
- data/lib/generators/templates/template.rb +14 -0
- data/ruby_raider.gemspec +1 -1
- data/spec/automation_file_generator_spec.rb +48 -14
- data/spec/common_file_generator_spec.rb +12 -3
- data/spec/cucumber_file_generator_spec.rb +26 -0
- data/spec/cucumber_project_generator_spec.rb +60 -0
- data/spec/helpers_file_generator_spec.rb +58 -16
- data/spec/rspec_file_generator_spec.rb +11 -2
- data/spec/rspec_project_generator_spec.rb +55 -25
- data/spec/spec_helper.rb +2 -12
- metadata +30 -4
- data/spec/menu_generator_spec.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dcbe671c993c24b4869fb0243906a8cd5d4614d7ea4690e0292cdb8c67a0b58
|
4
|
+
data.tar.gz: 39018ac4bf1d1148ad6a5308ca251d54de216154f774955c9c0c5c966b836019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c9ae7dce2543807cf14ed1e51f0d81e015ef40b0e9d791209432cc954d55bb3fe39fe297fb43c4a7a07381431bd069ed4b33de98b30328f161ef25538d5ee6d
|
7
|
+
data.tar.gz: caefa842f497505b6dcfc64e1e35cd27ba4f31f41ec11ac635359acae7540296251b9523054e01fe75d3c247373707a8f669b39eaa2fff3130fc2a8a9e5eef15
|
data/.gitignore
CHANGED
@@ -1,137 +1,61 @@
|
|
1
1
|
require_relative 'file_generator'
|
2
|
+
require_relative '../templates/automation/abstract_page_template'
|
3
|
+
require_relative '../templates/automation/abstract_component_template'
|
4
|
+
require_relative '../templates/automation/appium_settings_template'
|
5
|
+
require_relative '../templates/automation/component_template'
|
6
|
+
require_relative '../templates/automation/confirmation_page_template'
|
7
|
+
require_relative '../templates/automation/login_page_template'
|
8
|
+
require_relative '../templates/automation/home_page_template'
|
2
9
|
|
3
10
|
module RubyRaider
|
4
11
|
class AutomationFileGenerator < FileGenerator
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
require_relative '../components/header_component'
|
17
|
-
|
18
|
-
class LoginPage < AbstractPage
|
19
|
-
|
20
|
-
using #{automation == 'watir' ? 'Raider::WatirHelper' : 'Raider::SeleniumHelper'}
|
21
|
-
|
22
|
-
def url(_page)
|
23
|
-
'index.php?rt=account/login'
|
24
|
-
end
|
25
|
-
|
26
|
-
# Actions
|
27
|
-
|
28
|
-
def login(username, password)
|
29
|
-
username_field.send_keys username
|
30
|
-
password_field.send_keys password
|
31
|
-
login_button.click_when_present
|
32
|
-
end
|
33
|
-
|
34
|
-
# Components
|
35
|
-
|
36
|
-
def header
|
37
|
-
HeaderComponent.new(#{element}(class: 'menu_text'))
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
# Elements
|
43
|
-
|
44
|
-
def username_field
|
45
|
-
#{element}(id: 'loginFrm_loginname')
|
46
|
-
end
|
47
|
-
|
48
|
-
def password_field
|
49
|
-
#{element}(id: 'loginFrm_password')
|
50
|
-
end
|
51
|
-
|
52
|
-
def login_button
|
53
|
-
#{element}(xpath: "//button[@title='Login']")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
EOF
|
57
|
-
page_file.result(binding)
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.abstract_page(automation, framework)
|
61
|
-
browser = "def browser
|
62
|
-
Raider::BrowserHelper.browser
|
63
|
-
end"
|
64
|
-
driver = "def driver
|
65
|
-
Raider::DriverHelper.driver
|
66
|
-
end"
|
67
|
-
visit = automation == 'watir' ? 'browser.goto full_url(page.first)' : 'driver.navigate.to full_url(page.first)'
|
68
|
-
raider = if framework == 'rspec'
|
69
|
-
"require_relative '../../helpers/raider'"
|
70
|
-
else
|
71
|
-
"require_relative '../../features/support/helpers/raider'"
|
72
|
-
end
|
73
|
-
abstract_file = ERB.new <<~EOF
|
74
|
-
require 'rspec'
|
75
|
-
#{raider}
|
76
|
-
|
77
|
-
class AbstractPage
|
78
|
-
|
79
|
-
include RSpec::Matchers
|
80
|
-
extend Raider::PomHelper
|
81
|
-
|
82
|
-
#{automation == 'watir' ? browser : driver}
|
83
|
-
|
84
|
-
def visit(*page)
|
85
|
-
#{visit}
|
86
|
-
end
|
87
|
-
|
88
|
-
def full_url(*page)
|
89
|
-
"#\{base_url}#\{url(*page)}"
|
90
|
-
end
|
91
|
-
|
92
|
-
def base_url
|
93
|
-
'https://automationteststore.com/'
|
94
|
-
end
|
95
|
-
|
96
|
-
def url(_page)
|
97
|
-
raise 'Url must be defined on child pages'
|
98
|
-
end
|
99
|
-
end
|
100
|
-
EOF
|
101
|
-
abstract_file.result(binding)
|
102
|
-
end
|
103
|
-
|
104
|
-
def self.example_component
|
105
|
-
page_file = ERB.new <<~EOF
|
106
|
-
require_relative '../abstract/abstract_component'
|
107
|
-
|
108
|
-
class HeaderComponent < AbstractComponent
|
109
|
-
|
110
|
-
def customer_name
|
111
|
-
@component.text
|
112
|
-
end
|
113
|
-
end
|
114
|
-
EOF
|
115
|
-
page_file.result(binding)
|
116
|
-
end
|
117
|
-
|
118
|
-
def self.abstract_component(framework)
|
119
|
-
raider = if framework == 'rspec'
|
120
|
-
"require_relative '../../helpers/raider'"
|
121
|
-
else
|
122
|
-
"require_relative '../../features/support/helpers/raider'"
|
123
|
-
end
|
124
|
-
abstract_file = ERB.new <<~EOF
|
125
|
-
#{raider}
|
126
|
-
|
127
|
-
class AbstractComponent
|
128
|
-
|
129
|
-
def initialize(component)
|
130
|
-
@component = component
|
131
|
-
end
|
12
|
+
class << self
|
13
|
+
def generate_automation_files(automation, name, framework)
|
14
|
+
generate_login_page(automation, name)
|
15
|
+
generate_abstract_page(automation, framework, name)
|
16
|
+
if %w[selenium watir].include?(automation)
|
17
|
+
generate_example_component(name)
|
18
|
+
generate_abstract_component(framework, name)
|
19
|
+
else
|
20
|
+
generate_home_page(name)
|
21
|
+
generate_confirmation_page(name)
|
22
|
+
generate_appium_settings(name)
|
132
23
|
end
|
133
|
-
|
134
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate_login_page(automation, name)
|
27
|
+
generate_file('login_page.rb', "#{name}/page_objects/pages",
|
28
|
+
LoginPageTemplate.new(automation: automation, name: name).parsed_body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_abstract_page(automation, framework, name)
|
32
|
+
generate_file('abstract_page.rb', "#{name}/page_objects/abstract",
|
33
|
+
AbstractPageTemplate.new(automation: automation, framework: framework, name: name).parsed_body)
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_home_page(name)
|
37
|
+
generate_file('home_page.rb', "#{name}/page_objects/pages",
|
38
|
+
HomePageTemplate.new.parsed_body)
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_confirmation_page(name)
|
42
|
+
generate_file('confirmation_page.rb', "#{name}/page_objects/pages",
|
43
|
+
ConfirmationPageTemplate.new.parsed_body)
|
44
|
+
end
|
45
|
+
|
46
|
+
def generate_example_component(name)
|
47
|
+
generate_file('header_component.rb', "#{name}/page_objects/components",
|
48
|
+
ComponentTemplate.new.parsed_body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_abstract_component(framework, name)
|
52
|
+
generate_file('abstract_component.rb', "#{name}/page_objects/abstract",
|
53
|
+
AbstractComponentTemplate.new(framework: framework).parsed_body)
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_appium_settings(name)
|
57
|
+
generate_file('appium.txt', name.to_s, AppiumSettingsTemplate.new.parsed_body)
|
58
|
+
end
|
135
59
|
end
|
136
60
|
end
|
137
61
|
end
|
@@ -1,162 +1,38 @@
|
|
1
|
+
require_relative '../templates/common/config_template'
|
2
|
+
require_relative '../templates/common/gemfile_template'
|
3
|
+
require_relative '../templates/common/rake_file_template'
|
4
|
+
require_relative '../templates/common/read_me_template'
|
1
5
|
require_relative 'file_generator'
|
2
6
|
|
3
7
|
module RubyRaider
|
4
8
|
class CommonFileGenerator < FileGenerator
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.readme_file
|
13
|
-
rake_file = ERB.new <<~EOF
|
14
|
-
What is Raider?
|
15
|
-
===========
|
16
|
-
|
17
|
-
Raider is a tool to make the setup and start of automation projects in ruby easier, with one command you are
|
18
|
-
ready to go
|
19
|
-
|
20
|
-
# Pre-requisites:
|
21
|
-
|
22
|
-
Install RVM:
|
23
|
-
https://rvm.io/rvm/install
|
24
|
-
|
25
|
-
# How to use the framework:
|
26
|
-
|
27
|
-
If you want to run all the tests from your terminal do:
|
28
|
-
*rspec spec/*
|
29
|
-
|
30
|
-
If you want to run all the tests in parallel do:
|
31
|
-
*parallel_rspec spec/*
|
32
|
-
|
33
|
-
# How are specs organized:
|
34
|
-
|
35
|
-
We use 'context' as the highest grouping level to indicate in which part of the application we are as an example:
|
36
|
-
|
37
|
-
*context 'On the login page'/*
|
38
|
-
|
39
|
-
We use 'describe' from the user perspective to describe an action that the user can or cannot take:
|
40
|
-
|
41
|
-
*describe 'A user can'/*
|
42
|
-
|
43
|
-
or
|
44
|
-
|
45
|
-
*describe 'A user cannot'/*
|
46
|
-
|
47
|
-
This saves us repetition and forces us into an structure
|
48
|
-
|
49
|
-
At last we use 'it' for the specific action the user can or cannot perform:
|
50
|
-
|
51
|
-
it 'login with right credentials'
|
52
|
-
|
53
|
-
If we group all of this together it will look like
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
context 'On the login page' do
|
57
|
-
describe 'A user can' do
|
58
|
-
it 'login with the right credentials' do
|
59
|
-
end
|
60
|
-
#{' '}
|
61
|
-
end
|
62
|
-
#{' '}
|
63
|
-
describe 'A user cannot' do
|
64
|
-
it 'login with the wrong credentials' do
|
65
|
-
end
|
66
|
-
end
|
9
|
+
class << self
|
10
|
+
def generate_common_files(automation, name, framework)
|
11
|
+
if %w[selenium watir].include?(automation)
|
12
|
+
generate_config_file(name)
|
13
|
+
generate_rake_file(name)
|
67
14
|
end
|
68
|
-
```
|
69
|
-
#{' '}
|
70
|
-
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'
|
71
|
-
|
72
|
-
# How pages are organized:
|
73
|
-
|
74
|
-
```ruby#{' '}
|
75
|
-
require_relative '../abstract/base_page'
|
76
|
-
|
77
|
-
class MainPage < BasePage
|
78
15
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
'/'
|
83
|
-
end
|
84
|
-
|
85
|
-
# Actions
|
86
|
-
|
87
|
-
def change_currency(currency)
|
88
|
-
currency_dropdown.select currency
|
89
|
-
end
|
90
|
-
|
91
|
-
# Validations
|
92
|
-
|
93
|
-
def validate_currency(currency)
|
94
|
-
expect(currency_dropdown.include?(currency)).to be true
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
|
99
|
-
# Elements
|
100
|
-
|
101
|
-
def currency_dropdown
|
102
|
-
browser.select(class: %w[dropdown-menu currency])
|
103
|
-
end
|
104
|
-
end
|
105
|
-
```
|
106
|
-
|
107
|
-
Pages are organized in Actions (things a user can perform on the page), Validations (assertions), and Elements.
|
108
|
-
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
|
109
|
-
|
110
|
-
EOF
|
111
|
-
rake_file.result(binding)
|
112
|
-
end
|
113
|
-
|
114
|
-
def self.config_file
|
115
|
-
config_file = ERB.new <<~EOF
|
116
|
-
browser: :chrome
|
117
|
-
EOF
|
118
|
-
config_file.result(binding)
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.rake_file
|
122
|
-
rake_file = ERB.new <<~EOF
|
123
|
-
require 'yaml'
|
124
|
-
|
125
|
-
desc 'Selects browser for automation run'
|
126
|
-
task :select_browser, [:browser] do |_t, args|
|
127
|
-
config = YAML.load_file('config/config.yml')
|
128
|
-
config['browser'] = args.browser
|
129
|
-
File.write('config/config.yml', config.to_yaml)
|
130
|
-
end
|
131
|
-
EOF
|
132
|
-
rake_file.result(binding)
|
133
|
-
end
|
16
|
+
generate_readme_file(name)
|
17
|
+
generate_gemfile(automation, framework, name)
|
18
|
+
end
|
134
19
|
|
135
|
-
|
136
|
-
|
137
|
-
allure_cucumber = "gem 'allure-cucumber'"
|
138
|
-
rspec = "gem 'rspec'"
|
20
|
+
def generate_readme_file(name)
|
21
|
+
generate_file('Readme.md', name.to_s, ReadMeTemplate.new.parsed_body)
|
139
22
|
end
|
140
23
|
|
141
|
-
|
142
|
-
#
|
24
|
+
def generate_config_file(name)
|
25
|
+
generate_file('config.yml', "#{name}/config", ConfigTemplate.new.parsed_body)
|
26
|
+
end
|
143
27
|
|
144
|
-
|
28
|
+
def generate_rake_file(name)
|
29
|
+
generate_file('Rakefile', name.to_s, RakeFileTemplate.new.parsed_body)
|
30
|
+
end
|
145
31
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
gem 'parallel_split_test'
|
151
|
-
gem 'parallel_tests'
|
152
|
-
gem 'rake'
|
153
|
-
gem '#{framework}'
|
154
|
-
#{rspec}
|
155
|
-
gem 'selenium-webdriver'
|
156
|
-
gem 'watir'
|
157
|
-
gem 'webdrivers'
|
158
|
-
EOF
|
159
|
-
gemfile.result(binding)
|
32
|
+
def generate_gemfile(automation, framework, name)
|
33
|
+
generate_file('Gemfile',name.to_s,
|
34
|
+
GemfileTemplate.new(automation: automation, framework: framework).parsed_body)
|
35
|
+
end
|
160
36
|
end
|
161
37
|
end
|
162
38
|
end
|
@@ -1,81 +1,33 @@
|
|
1
|
+
require_relative '../templates/cucumber/env_template'
|
2
|
+
require_relative '../templates/cucumber/example_feature_template'
|
3
|
+
require_relative '../templates/cucumber/example_steps_template'
|
1
4
|
require_relative 'file_generator'
|
2
5
|
|
3
6
|
module RubyRaider
|
4
7
|
class CucumberFileGenerator < FileGenerator
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def self.example_feature
|
15
|
-
gemfile = ERB.new <<~EOF
|
16
|
-
Feature: Login Page
|
17
|
-
|
18
|
-
Scenario: A user can login
|
19
|
-
Given I'm a registered user on the login page
|
20
|
-
When I login with my credentials
|
21
|
-
Then I can see the main page
|
22
|
-
|
23
|
-
EOF
|
24
|
-
gemfile.result(binding)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.example_steps
|
28
|
-
gemfile = ERB.new <<~EOF
|
29
|
-
require_relative '../../page_objects/pages/login_page'
|
30
|
-
|
31
|
-
Given("I'm a registered user on the login page") do
|
32
|
-
LoginPage.visit
|
33
|
-
end
|
34
|
-
|
35
|
-
When('I login with my credentials') do
|
36
|
-
LoginPage.login('aguspe', '12341234')
|
37
|
-
end
|
38
|
-
|
39
|
-
When('I can see the main page') do
|
40
|
-
expect(LoginPage.header.customer_name).to eq 'Welcome back Agustin'
|
41
|
-
end
|
42
|
-
EOF
|
43
|
-
gemfile.result(binding)
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.env(automation)
|
47
|
-
if automation == 'watir'
|
48
|
-
helper = 'helpers/browser_helper'
|
49
|
-
browser = 'Raider::BrowserHelper.new_browser'
|
50
|
-
get_browser = 'browser = Raider::BrowserHelper.new_browser'
|
51
|
-
screenshot = 'browser.screenshot.save("allure-results/screenshots/#{scenario.name}.png")'
|
52
|
-
quit = 'browser.quit'
|
53
|
-
else
|
54
|
-
helper = 'helpers/driver_helper'
|
55
|
-
browser = 'Raider::DriverHelper.new_driver'
|
56
|
-
get_browser = 'driver = Raider::DriverHelper.driver'
|
57
|
-
screenshot = 'driver.save_screenshot("allure-results/screenshots/#{scenario.name}.png")'
|
58
|
-
quit = 'driver.quit'
|
8
|
+
class << self
|
9
|
+
def generate_cucumber_files(automation, name)
|
10
|
+
AutomationFileGenerator.generate_automation_files(automation, name, 'framework')
|
11
|
+
CommonFileGenerator.generate_common_files(automation, name, 'cucumber')
|
12
|
+
HelpersFileGenerator.generate_helper_files(automation, name, 'cucumber')
|
13
|
+
generate_env_file(automation, name)
|
14
|
+
generate_example_feature(name)
|
15
|
+
generate_example_steps(name)
|
59
16
|
end
|
60
17
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
require_relative '#{helper}'
|
18
|
+
def generate_example_feature(name)
|
19
|
+
generate_file('login.feature', "#{name}/features", ExampleFeatureTemplate.new.parsed_body)
|
20
|
+
end
|
65
21
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
22
|
+
def generate_example_steps(name)
|
23
|
+
generate_file('login_steps.rb', "#{name}/features/step_definitions",
|
24
|
+
ExampleStepsTemplate.new.parsed_body)
|
25
|
+
end
|
70
26
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#{quit}
|
76
|
-
end
|
77
|
-
EOF
|
78
|
-
gemfile.result(binding)
|
27
|
+
def generate_env_file(automation, name)
|
28
|
+
generate_file('env.rb', "#{name}/features/support",
|
29
|
+
EnvTemplate.new(automation: automation).parsed_body)
|
30
|
+
end
|
79
31
|
end
|
80
32
|
end
|
81
33
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module RubyRaider
|
2
2
|
class FileGenerator
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
class << self
|
4
|
+
def generate_file(name, path, content)
|
5
|
+
file_path = "#{path}/#{name}"
|
6
|
+
File.new(file_path, 'w+')
|
7
|
+
File.write(file_path, content)
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
9
|
-
end
|
11
|
+
end
|