ruby_raider 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8d336aefa187b06c4299321d8a8a4b66235dfd14974845e70006632a6450899
4
- data.tar.gz: 10228a61500f16e12590d59f84363b7b85d186e79bf1cfb2967b63ae7788d00b
3
+ metadata.gz: 2b0c6d3fae74a6d921b96f3aeb216fef51378824aa78a24cbb5f9bb8a2f7c22e
4
+ data.tar.gz: 274ef6e35550c02473a6e6d6ffee85ca88f3a9279e379241da6b0177c7c1210e
5
5
  SHA512:
6
- metadata.gz: b87195baaa2521f54deddc1c6e62ebf04a52f13f6e8880c5071f5a6ea43e3282ee14b7d121a98eee8435eb2d584fa4a5190675771eab8061409d7aeffb3d1e54
7
- data.tar.gz: '0425969814d7f081fcacb71b510d5b5aa79d195a53511ab1b3028be602212533ad74e0150b53091ebbc43e27161c535e68c819ce483ffa8d2e423a9c1f2e814a'
6
+ metadata.gz: 0bc058b73aff5b99a92a06220c5d6f84e3314fca9eb99cb8a02f983308f755de245c751133fc9f9357bad8836c7cf575e0dddfd9ee83c2231e2ed5934ad71dc2
7
+ data.tar.gz: 5d45ba62bde3a8e3f317ec0392d3b7448b2b2ae56896f6d143916dcee9b4b37847b7fcc3e5e5dee2f1dcd8e1a735812744bc7c18943c08c4a130bffe0f653686
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- ruby_raider-*.gem
1
+ ruby_raider-*.gem
2
+ .idea/
data/README.md CHANGED
@@ -1,9 +1,18 @@
1
1
  # ruby_raider
2
2
  This is a gem to make setup and start of UI automation projects easier
3
3
 
4
- In order to run ruby raider you need to run the executable,
5
- after you can select the automation framework of your choice and the test framework of your choice.
4
+ Just do:
5
+
6
+ gem install ruby_raider
7
+
8
+ then do raider [name_of_project]
9
+
10
+ and you will have a new project in the folder you are in
6
11
 
7
12
  Currently we only support Watir with Rspec.
8
13
 
9
14
  We have only tested this in mac and linux, so it works in both platforms.
15
+
16
+ If you wanna follow the development progress
17
+
18
+ https://trello.com/b/Nj7UPy0w/ruby-raider
@@ -2,25 +2,31 @@ require_relative 'file_generator'
2
2
 
3
3
  module RubyRaider
4
4
  class HelpersFileGenerator < FileGenerator
5
- def self.generate_helper_files(name)
6
- generate_file('raider.rb', "#{name}/helpers", generate_raider_helper)
5
+ def self.generate_helper_files(name, automation)
6
+ generate_file('raider.rb', "#{name}/helpers", generate_raider_helper((automation)))
7
7
  generate_file('allure_helper.rb', "#{name}/helpers", generate_allure_helper)
8
- generate_file('browser_helper.rb', "#{name}/helpers", generate_browser_helper)
9
8
  generate_file('pom_helper.rb', "#{name}/helpers", generate_pom_helper)
10
- generate_file('watir_helper.rb', "#{name}/helpers", generate_watir_helper)
11
- generate_file('spec_helper.rb', "#{name}/helpers", generate_spec_helper)
9
+ generate_file('spec_helper.rb', "#{name}/helpers", generate_spec_helper((automation)))
10
+ if automation == 'watir'
11
+ generate_file('watir_helper.rb', "#{name}/helpers", generate_watir_helper)
12
+ generate_file('browser_helper.rb', "#{name}/helpers", generate_browser_helper)
13
+ else
14
+ generate_file('selenium_helper.rb', "#{name}/helpers", generate_selenium_helper)
15
+ generate_file('driver_helper.rb', "#{name}/helpers", generate_driver_helper)
16
+ end
12
17
  end
13
18
 
14
- def self.generate_raider_helper
19
+ def self.generate_raider_helper(automation)
15
20
  spec = ERB.new <<~EOF
16
21
  module Raider
17
22
  require_relative 'spec_helper'
18
- require_relative 'watir_helper'
23
+ require_relative '#{automation}_helper'
19
24
  require_relative 'pom_helper'
20
- require_relative 'browser_helper'
25
+ require_relative '#{automation == 'watir' ? 'browser_helper' : 'driver_helper'}'
21
26
  require_relative 'allure_helper'
22
27
  end
23
28
  EOF
29
+
24
30
  spec.result(binding)
25
31
  end
26
32
 
@@ -105,12 +111,12 @@ module RubyRaider
105
111
  spec.result(binding)
106
112
  end
107
113
 
108
- def self.generate_spec_helper
114
+ def self.generate_spec_helper(automation)
109
115
  spec = ERB.new <<~EOF
110
116
  require 'active_support/all'
111
117
  require 'rspec'
112
118
  require_relative 'allure_helper'
113
- require_relative 'browser_helper'
119
+ require_relative '#{automation == 'watir' ? 'browser_helper' : 'driver_helper'}'
114
120
 
115
121
  module Raider
116
122
  module SpecHelper
@@ -120,16 +126,16 @@ module RubyRaider
120
126
  RSpec.configure do |config|
121
127
  config.formatter = AllureHelper.formatter
122
128
  config.before(:each) do
123
- BrowserHelper.new_browser
129
+ #{automation == 'watir' ? 'BrowserHelper.new_browser' : 'DriverHelper.new_driver'}
124
130
  end
125
131
 
126
132
  config.after(:each) do
127
- browser = BrowserHelper.browser
133
+ #{automation == 'watir' ? 'browser = BrowserHelper.browser' : 'driver = DriverHelper.driver'}
128
134
  example_name = self.class.descendant_filtered_examples.first.description
129
135
  status = self.class.descendant_filtered_examples.first.execution_result.status
130
- browser.save_screenshot("allure-results/screenshots/#\{example_name}.png") if status == :failed
136
+ #{automation == 'watir' ? 'browser' : 'driver'}.save_screenshot("allure-results/screenshots/#\{example_name}.png") if status == :failed
131
137
  AllureHelper.add_screenshot example_name if status == :failed
132
- browser.quit
138
+ #{automation == 'watir' ? 'browser.quit' : 'driver.quit'}
133
139
  end
134
140
  end
135
141
  end
@@ -159,5 +165,70 @@ module RubyRaider
159
165
  EOF
160
166
  spec.result(binding)
161
167
  end
168
+
169
+ def self.generate_selenium_helper
170
+ spec = ERB.new <<~EOF
171
+ require 'selenium-webdriver'
172
+ require_relative 'driver_helper'
173
+
174
+ module ExampleDsl
175
+ module SeleniumHelper
176
+ def click_when_present
177
+ # This is an example of an implicit wait in selenium
178
+ wait = Selenium::WebDriver::Wait.new(timeout: 15)
179
+ wait.until { present? }
180
+ click
181
+ end
182
+
183
+ def select_by(key, value)
184
+ # Creates new Select object to use the select by method
185
+ dropdown = Selenium::WebDriver::Support::Select.new self
186
+ dropdown.select_by(key, value)
187
+ end
188
+
189
+ def hover
190
+ # Using actions to move the mouse over an element
191
+ DriverHelper.driver.action.move_to(self).perform
192
+ end
193
+
194
+ # How to perform right click through the context click method
195
+ def right_click
196
+ DriverHelper.driver.action.context_click(self).perform
197
+ end
198
+ end
199
+
200
+ # Here we are opening the selenium class and adding our custom method
201
+ class Selenium::WebDriver::Element
202
+ include SeleniumHelper
203
+ end
204
+ end
205
+
206
+ EOF
207
+ spec.result(binding)
208
+ end
209
+
210
+ def self.generate_driver_helper
211
+ spec = ERB.new <<~EOF
212
+ require 'selenium-webdriver'
213
+ require 'watir'
214
+ require 'webdrivers'
215
+ require 'yaml'
216
+
217
+ module Raider
218
+ module DriverHelper
219
+ class << self
220
+ attr_reader :driver
221
+
222
+ def new_driver
223
+ @driver = Selenium::WebDriver.for :chrome
224
+ end
225
+ end
226
+ end
227
+ end
228
+
229
+
230
+ EOF
231
+ spec.result(binding)
232
+ end
162
233
  end
163
234
  end
@@ -1,19 +1,20 @@
1
1
  require_relative 'common_file_generator'
2
2
  require_relative 'file_generator'
3
3
  require_relative 'helpers_file_generator'
4
+ require_relative 'selenium_file_generator'
4
5
  require_relative 'watir_file_generator'
5
6
 
6
7
  module RubyRaider
7
8
  class RspecFileGenerator < FileGenerator
8
9
  def self.generate_rspec_files(name, automation)
10
+ CommonFileGenerator.generate_common_files(name)
11
+ HelpersFileGenerator.generate_helper_files(name, automation)
12
+ generate_file('login_page_spec.rb', "#{name}/spec", generate_example_spec)
13
+ generate_file('base_spec.rb', "#{name}/spec", generate_base_spec)
9
14
  if automation == 'watir'
10
- CommonFileGenerator.generate_common_files(name)
11
15
  WatirFileGenerator.generate_watir_files(name)
12
- HelpersFileGenerator.generate_helper_files(name)
13
- generate_file('login_page_spec.rb', "#{name}/spec", generate_example_spec)
14
- generate_file('base_spec.rb', "#{name}/spec", generate_base_spec)
15
16
  else
16
- pp 'here goes selenium'
17
+ SeleniumFileGenerator.generate_selenium_files(name)
17
18
  end
18
19
  end
19
20
 
@@ -32,13 +33,14 @@ module RubyRaider
32
33
  describe 'A user can' do
33
34
  it 'login with the right credentials', :JIRA_123 do
34
35
  LoginPage.login('aguspe', '12341234')
35
- expect(LoginPage.customer_name).to eq 'Welcome back Agustin'
36
+ expect(LoginPage.header.customer_name).to eq 'Welcome back Agustin'
36
37
  end
37
38
  end
38
39
 
39
40
  describe 'A user cannot' do
40
41
  it 'login with the wrong credentials', :JIRA_123 do
41
- expect(LoginPage.customer_name).to eq 'Login or register'
42
+ LoginPage.login('aguspe', 'wrongPassword')
43
+ expect(LoginPage.header.customer_name).to be_empty
42
44
  end
43
45
  end
44
46
  end
@@ -0,0 +1,159 @@
1
+ require_relative 'file_generator'
2
+
3
+ module RubyRaider
4
+ class SeleniumFileGenerator < FileGenerator
5
+ def self.generate_selenium_files(name)
6
+ generate_file('abstract_page.rb', "#{name}/page_objects/abstract", abstract_page)
7
+ generate_file('abstract_page_object.rb', "#{name}/page_objects/abstract", abstract_page_object)
8
+ generate_file('abstract_component.rb', "#{name}/page_objects/abstract", abstract_component)
9
+ generate_file('login_page.rb', "#{name}/page_objects/pages", example_page)
10
+ generate_file('header_component.rb', "#{name}/page_objects/components", example_component)
11
+ generate_file('Gemfile', name.to_s, gemfile_template)
12
+ end
13
+
14
+ def self.gemfile_template
15
+ gemfile = ERB.new <<~EOF
16
+ # frozen_string_literal: true
17
+
18
+ source 'https://rubygems.org'
19
+
20
+ gem 'activesupport'
21
+ gem 'allure-rspec'
22
+ gem 'allure-ruby-commons'
23
+ gem 'parallel_split_test'
24
+ gem 'parallel_tests'
25
+ gem 'rake'
26
+ gem 'rspec'
27
+ gem 'selenium-webdriver'
28
+ gem 'webdrivers'
29
+
30
+ EOF
31
+ gemfile.result(binding)
32
+ end
33
+
34
+ def self.example_page
35
+ gemfile = ERB.new <<~EOF
36
+ require_relative '../abstract/abstract_page'
37
+ require_relative '../components/header_component'
38
+ require_relative '../../helpers/selenium_helper'
39
+
40
+ class LoginPage < AbstractPage
41
+
42
+ def url(_page)
43
+ 'index.php?rt=account/login'
44
+ end
45
+
46
+ # Actions
47
+
48
+ def login(username, password)
49
+ username_field.send_keys username
50
+ password_field.send_keys password
51
+ login_button.click_when_present
52
+ end
53
+
54
+ def header
55
+ HeaderComponent.new(driver.find_element(class: 'menu_text'))
56
+ end
57
+
58
+ private
59
+
60
+ # Elements
61
+
62
+ def username_field
63
+ driver.find_element(id: 'loginFrm_loginname')
64
+ end
65
+
66
+ def password_field
67
+ driver.find_element(id: 'loginFrm_password')
68
+ end
69
+
70
+ def login_button
71
+ driver.find_element(xpath: "//button[@title='Login']")
72
+ end
73
+ end
74
+
75
+
76
+
77
+ EOF
78
+ gemfile.result(binding)
79
+ end
80
+
81
+ def self.abstract_page
82
+ abstract_file = ERB.new <<~EOF
83
+ require_relative '../components/header_component'
84
+ require_relative 'abstract_page_object'
85
+ require 'rspec'
86
+
87
+ class AbstractPage < AbstractPageObject
88
+ include RSpec::Matchers
89
+
90
+ def visit(*page)
91
+ driver.navigate.to full_url(page.first)
92
+ end
93
+
94
+ def full_url(*page)
95
+ "\#{base_url}\#{url(*page)}"
96
+ end
97
+
98
+ def base_url
99
+ 'https://automationteststore.com/'
100
+ end
101
+
102
+ def url(_page)
103
+ raise 'Url must be defined on child pages'
104
+ end
105
+
106
+ def header
107
+ HeaderComponent.new(driver.find_element(css: 'header'))
108
+ end
109
+ end
110
+
111
+ EOF
112
+ abstract_file.result(binding)
113
+ end
114
+
115
+ def self.abstract_component
116
+ abstract_file = ERB.new <<~EOF
117
+ require_relative '../../helpers/raider'
118
+
119
+ class AbstractComponent
120
+ def initialize(component)
121
+ @component = component
122
+ end
123
+ end
124
+ EOF
125
+ abstract_file.result(binding)
126
+ end
127
+
128
+ def self.abstract_page_object
129
+ abstract_file = ERB.new <<~EOF
130
+ require_relative '../../helpers/raider'
131
+
132
+ class AbstractPageObject
133
+ extend Raider::PomHelper
134
+
135
+ def driver
136
+ Raider::DriverHelper.driver
137
+ end
138
+ end
139
+
140
+ EOF
141
+ abstract_file.result(binding)
142
+ end
143
+
144
+ def self.example_component
145
+ page_file = ERB.new <<~EOF
146
+ require_relative '../abstract/abstract_component'
147
+
148
+ class HeaderComponent < AbstractComponent
149
+
150
+ def customer_name
151
+ @component.text
152
+ end
153
+ end
154
+
155
+ EOF
156
+ page_file.result(binding)
157
+ end
158
+ end
159
+ end
@@ -35,7 +35,7 @@ module RubyRaider
35
35
  require_relative '../abstract/abstract_page'
36
36
  require_relative '../components/header_component'
37
37
 
38
- class LoginPage < BasePage
38
+ class LoginPage < AbstractPage
39
39
 
40
40
  using Raider::WatirHelper
41
41
 
@@ -51,6 +51,12 @@ module RubyRaider
51
51
  login_button.click_when_present
52
52
  end
53
53
 
54
+ # Components
55
+
56
+ def header
57
+ HeaderComponent.new(browser.element(class: 'menu_text'))
58
+ end
59
+
54
60
  private
55
61
 
56
62
  # Elements
@@ -74,12 +80,10 @@ module RubyRaider
74
80
  def self.abstract_page
75
81
  abstract_file = ERB.new <<~EOF
76
82
  require 'rspec'
77
- require_relative '../components/header_component'
78
83
  require_relative '../../helpers/raider'
79
84
 
80
- class BasePage
85
+ class AbstractPage
81
86
 
82
- include HeaderComponent
83
87
  include RSpec::Matchers
84
88
  extend Raider::PomHelper
85
89
 
@@ -103,6 +107,7 @@ module RubyRaider
103
107
  raise 'Url must be defined on child pages'
104
108
  end
105
109
  end
110
+
106
111
  EOF
107
112
  abstract_file.result(binding)
108
113
  end
@@ -111,21 +116,10 @@ module RubyRaider
111
116
  page_file = ERB.new <<~EOF
112
117
  require_relative '../abstract/abstract_component'
113
118
 
114
- module HeaderComponent
115
-
116
- include BaseComponent
119
+ class HeaderComponent < AbstractComponent
117
120
 
118
121
  def customer_name
119
- sleep 2
120
- customer_menu.text
121
- end
122
-
123
- private
124
-
125
- # Elements
126
-
127
- def customer_menu
128
- browser.element(id: 'customer_menu_top')
122
+ @component.text
129
123
  end
130
124
  end
131
125
  EOF
@@ -136,7 +130,11 @@ module RubyRaider
136
130
  abstract_file = ERB.new <<~EOF
137
131
  require_relative '../../helpers/raider'
138
132
 
139
- module BaseComponent; end
133
+ class AbstractComponent
134
+ def initialize(component)
135
+ @component = component
136
+ end
137
+ end
140
138
  EOF
141
139
  abstract_file.result(binding)
142
140
  end
@@ -7,8 +7,8 @@ module RubyRaider
7
7
  cli = HighLine.new
8
8
  cli.choose do |menu|
9
9
  menu.prompt = 'Please select your automation framework'
10
- menu.choice(:Selenium) { 'We are still working on supporting this' }
11
- menu.choice(:Watir) {choose_test_framework('watir', project_name) }
10
+ menu.choice(:Selenium) { choose_test_framework('selenium', project_name) }
11
+ menu.choice(:Watir) { choose_test_framework('watir', project_name) }
12
12
  menu.choice(:Quit, 'Exit program.') { exit }
13
13
  end
14
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.1'
3
+ s.version = '0.1.2'
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']
@@ -0,0 +1,29 @@
1
+ require_relative '../lib/generators/files/selenium_file_generator'
2
+ require_relative 'spec_helper'
3
+
4
+ describe RubyRaider::SeleniumFileGenerator do
5
+ it 'creates a login page file' do
6
+ expect(File.exist?("#{@project_name}/page_objects/pages/login_page.rb")).to be_truthy
7
+ end
8
+
9
+ it 'creates an abstract page file' do
10
+ expect(File.exist?("#{@project_name}/page_objects/abstract/abstract_page.rb")).to be_truthy
11
+ end
12
+
13
+ it 'creates an abstract page object file' do
14
+ expect(File.exist?("#{@project_name}/page_objects/abstract/abstract_page_object.rb")).to be_truthy
15
+ end
16
+
17
+ it 'creates an abstract component file' do
18
+ expect(File.exist?("#{@project_name}/page_objects/abstract/abstract_component.rb")).to be_truthy
19
+ end
20
+
21
+ it 'creates a component file' do
22
+ expect(File.exist?("#{@project_name}/page_objects/components/header_component.rb")).to be_truthy
23
+ end
24
+
25
+ it 'creates a gemfile file' do
26
+ expect(File.exist?("#{@project_name}/Gemfile")).to be_truthy
27
+ end
28
+ end
29
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_raider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agustin Pequeno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-04 00:00:00.000000000 Z
11
+ date: 2022-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -47,9 +47,6 @@ extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - ".gitignore"
50
- - ".idea/.gitignore"
51
- - ".idea/modules.xml"
52
- - ".idea/ruby_raider.iml"
53
50
  - README.md
54
51
  - Rakefile
55
52
  - bin/raider
@@ -57,6 +54,7 @@ files:
57
54
  - lib/generators/files/file_generator.rb
58
55
  - lib/generators/files/helpers_file_generator.rb
59
56
  - lib/generators/files/rspec_file_generator.rb
57
+ - lib/generators/files/selenium_file_generator.rb
60
58
  - lib/generators/files/watir_file_generator.rb
61
59
  - lib/generators/menu_generator.rb
62
60
  - lib/generators/projects/cucumber_project_generator.rb
@@ -69,6 +67,7 @@ files:
69
67
  - spec/menu_generator_spec.rb
70
68
  - spec/rspec_file_generator_spec.rb
71
69
  - spec/rspec_project_generator_spec.rb
70
+ - spec/selenium_file_generator_spec.rb
72
71
  - spec/spec_helper.rb
73
72
  - spec/watir_file_generator_spec.rb
74
73
  homepage: http://github.com/aguspe/ruby_raider
data/.idea/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- # Default ignored files
2
- /shelf/
3
- /workspace.xml
4
- # Editor-based HTTP Client requests
5
- /httpRequests/
6
- # Datasource local storage ignored files
7
- /dataSources/
8
- /dataSources.local.xml
data/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/ruby_raider.iml" filepath="$PROJECT_DIR$/.idea/ruby_raider.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,20 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="RUBY_MODULE" version="4">
3
- <component name="ModuleRunConfigurationManager">
4
- <shared />
5
- </component>
6
- <component name="NewModuleRootManager">
7
- <content url="file://$MODULE_DIR$">
8
- <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
- <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
- <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
- </content>
12
- <orderEntry type="jdk" jdkName="RVM: ruby-3.0.0" jdkType="RUBY_SDK" />
13
- <orderEntry type="sourceFolder" forTests="false" />
14
- </component>
15
- <component name="RakeTasksCache">
16
- <option name="myRootTask">
17
- <RakeTaskImpl id="rake" />
18
- </option>
19
- </component>
20
- </module>