bdd-helper 0.0.1 → 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ class BrowserUtilMethods
2
+
3
+ def scroll_to(element)
4
+ script = <<-JS
5
+ arguments[0].scrollIntoView(true);
6
+ JS
7
+ page.execute_script(script, element.native)
8
+ end
9
+
10
+ rescue StandardError => e
11
+ puts e
12
+ end
@@ -0,0 +1,178 @@
1
+ begin
2
+ When(/^scroll (\d+) px (down) the page$/) do |pixel, arg|
3
+ "
4
+ This scrolls down the page by the given amount of pixel.
5
+ "
6
+ # E.g : And scroll 500 px down the page
7
+ page.execute_script("window.scrollBy(0,#{pixel})")
8
+ end
9
+
10
+ When(/^scroll (\d+) px (up) the page$/) do |pixel, arg|
11
+ "
12
+ This scrolls up the page by the given amount of pixel.
13
+ "
14
+ # E.g : And scroll 500 px up the page
15
+ page.execute_script("window.scrollBy(0,#{-pixel})")
16
+ end
17
+
18
+ When(/^scroll (bottom) of the page$/) do |arg|
19
+ "
20
+ This scrolls the page to the bottom
21
+ "
22
+ # E.g : And scroll bottom of the page
23
+ page.execute_script('window.scrollTo(0, document.body.scrollHeight)')
24
+ end
25
+
26
+ When(/^scroll (top) of the page$/) do |arg|
27
+ "
28
+ This scrolls the page to the top
29
+ "
30
+ # E.g : And scroll top of the page
31
+ page.execute_script('window.scrollTo(document.body.scrollHeight,0)')
32
+ end
33
+
34
+ When(/^focus to element by "([^"]*)" text$/) do |text|
35
+ # E.g : And focus to element by "Agree Button" text
36
+ scroll_to(find(xpath: "//*[contains(text(), '#{text}')]"))
37
+ end
38
+
39
+ When(/^refresh the page$/) do
40
+ "
41
+ This refreshes the current page
42
+ "
43
+ # E.g : And refresh the page
44
+ page.evaluate_script('window.location.reload()')
45
+ end
46
+
47
+ When(/^open a (new window)$/) do |args|
48
+ # E.g : And open a new window
49
+ open_new_window(:window)
50
+ end
51
+
52
+ When(/^open a (new tab)$/) do |args|
53
+ # E.g : And open a new tab
54
+ open_new_window
55
+ end
56
+
57
+ When(/^switch to (last window|last tab)$/) do |arg|
58
+ # E.g : And switch to last window
59
+ # E.g : And switch to last tab
60
+ page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)
61
+ end
62
+
63
+ When(/^switch to (first window|first tab)$/) do |arg|
64
+ # E.g : And switch to first window
65
+ # E.g : And switch to first tab
66
+ page.driver.browser.switch_to.window(page.driver.browser.window_handles.first)
67
+ end
68
+
69
+ When(/^switch to window by "([^"]*)" title$/) do |window_title|
70
+ "
71
+ Window title should be title of the target window
72
+ "
73
+ # E.g : And switch to window by "Welcome" title
74
+ switch_to_window { title == window_title }
75
+ end
76
+
77
+ When(/^resize window to (\d+) width (\d+) height$/) do |width, height|
78
+ "
79
+ This resize to the current window by the given width and height
80
+ "
81
+ # E.g : And resize window to 1280 width 720 height
82
+ page.driver.browser.manage.window.resize_to(width, height)
83
+ end
84
+
85
+ When(/^get window size$/) do
86
+ "
87
+ This gets the current window's size then defines it to the global variable
88
+ "
89
+ # E.g : And get window size
90
+ $window_size = page.driver.browser.manage.window.size
91
+ end
92
+
93
+ When(/^close window$/) do
94
+ "
95
+ This closes the current window
96
+ "
97
+ # E.g : And close window
98
+ page.driver.browser.close
99
+ end
100
+
101
+ When(/^get current url$/) do
102
+ "
103
+ This get full URL of the current page then defines it to the global variable
104
+ "
105
+ # E.g : And get current url
106
+ $current_url = current_url
107
+ end
108
+
109
+ When(/^go back$/) do
110
+ "
111
+ This move back a single entry in the browser's history
112
+ "
113
+ # E.g : And go back
114
+ go_back
115
+ end
116
+
117
+ When(/^go forward$/) do
118
+ "
119
+ This move forward a single entry in the browser's history
120
+ "
121
+ # E.g : And go forward
122
+ go_forward
123
+ end
124
+
125
+ When(/^visit base page$/) do
126
+ "
127
+ Should configure base_url from bdd-helper config
128
+ "
129
+ # E.g : And visit base page
130
+ visit BddHelper.base_url
131
+ end
132
+
133
+ When(/^visit "([^"]*)" url$/) do |url|
134
+ "
135
+ The URL can either be a relative URL or an absolute URL
136
+ "
137
+ # E.g : And visit "http://www.example.com" url
138
+ visit url
139
+ end
140
+
141
+ When(/^visit relative url "([^"]*)"$/) do |url|
142
+ "
143
+ The URL can be a relative URL
144
+ "
145
+ # E.g : And visit relative url '/login'
146
+ visit BddHelper.base_url + url
147
+ end
148
+
149
+ When(/^maximize window$/) do
150
+ "
151
+ This maximizes the current window
152
+ "
153
+ # E.g : And maximize window
154
+ page.driver.browser.manage.window.maximize
155
+ end
156
+
157
+ When(/^accept alert$/) do
158
+ # E.g : And accept alert
159
+ page.driver.browser.switch_to.alert.accept
160
+ end
161
+
162
+ When(/^dismiss alert$/) do
163
+ # E.g : And dismiss alert
164
+ page.driver.browser.switch_to.alert.dismiss
165
+ end
166
+
167
+ When(/^get window title$/) do
168
+ "
169
+ This gets title of the current page then defines it to the global variable
170
+ "
171
+ # E.g : And get window title
172
+ $page_title = title
173
+ end
174
+
175
+ rescue StandardError => e
176
+ puts e
177
+ end
178
+
metadata CHANGED
@@ -1,36 +1,116 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bdd-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
- - Mehmet Ali Aydin
8
- autorequire:
7
+ - kloia
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-22 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Package of helper step defitions for BDD testing with Gherkin and Cucumber
14
- email: maaydin@gmail.com
11
+ date: 2022-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.36'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.36'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cucumber
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '7.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.10'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: selenium-webdriver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 4.0.3
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '4.0'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 4.0.3
75
+ - !ruby/object:Gem::Dependency
76
+ name: faker
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.19'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.19'
89
+ description: Package of helper steps for BDD testing with Cucumber
90
+ email: burak@kloia.com
15
91
  executables: []
16
92
  extensions: []
17
93
  extra_rdoc_files: []
18
94
  files:
19
95
  - lib/bdd-helper.rb
20
- - lib/step_definitions/assertion.rb
21
- - lib/step_definitions/browser.rb
22
- - lib/step_definitions/check.rb
23
- - lib/step_definitions/click.rb
24
- - lib/step_definitions/env.rb
25
- - lib/step_definitions/fill.rb
26
- - lib/step_definitions/select.rb
27
- - lib/step_definitions/unclassified.rb
28
- - lib/support/config.rb
96
+ - lib/demo.feature
97
+ - lib/steps/action/check_steps.rb
98
+ - lib/steps/action/choose_steps.rb
99
+ - lib/steps/action/click_steps.rb
100
+ - lib/steps/action/fill_steps.rb
101
+ - lib/steps/action/key_action_steps.rb
102
+ - lib/steps/action/select_steps.rb
103
+ - lib/steps/assertion/assertion_steps.rb
104
+ - lib/steps/config.rb
105
+ - lib/steps/customized/customized_steps.rb
106
+ - lib/steps/global/global_context.rb
107
+ - lib/steps/util/browser_util_methods.rb
108
+ - lib/steps/util/browser_util_steps.rb
29
109
  homepage: http://rubygems.org/gems/bdd-helper
30
110
  licenses:
31
111
  - MIT
32
112
  metadata: {}
33
- post_install_message:
113
+ post_install_message:
34
114
  rdoc_options: []
35
115
  require_paths:
36
116
  - lib
@@ -45,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
125
  - !ruby/object:Gem::Version
46
126
  version: '0'
47
127
  requirements: []
48
- rubyforge_project:
49
- rubygems_version: 2.6.11
50
- signing_key:
128
+ rubygems_version: 3.2.22
129
+ signing_key:
51
130
  specification_version: 4
52
- summary: Helper step definitions for Gherkin
131
+ summary: Helper steps for client-based automation testing
53
132
  test_files: []
@@ -1,93 +0,0 @@
1
- require 'step_definitions/env'
2
- require 'support/config'
3
-
4
- include BaseConstants
5
-
6
- Then(/^page (should|should_not) contain "([^"]*)" content$/) do |condition, content|
7
- # E.g. : page should contain "Test" content
8
- # E.g. : page should_not contain "Test" content
9
- # page.should have_content(content, count: count, wait: @timeout)
10
- sleep 1
11
- if condition == 'should'
12
- page.should have_content(content, wait: @timeout)
13
-
14
- elsif condition == 'should_not'
15
- page.should_not have_content(content, wait: @timeout)
16
- end
17
- end
18
-
19
- Then(/^page (should|should_not) contain the following contents:$/) do |condition, table|
20
- sleep 1
21
- values = table.raw
22
- values.each {|raw|
23
- if condition == 'should'
24
- page.should have_content(raw[0], wait: @timeout)
25
- elsif condition == 'should_not'
26
- page.should_not have_content(raw[0], wait: @timeout)
27
- end
28
- }
29
- end
30
-
31
- Then(/^page (should|should_not) contain "([^"]*)" "([^"]*)" web element/) do |condition, web_element_type, web_element|
32
- # E.g. : page should contain "css" "#test .form" web element
33
- sleep 1
34
- if condition == 'should'
35
- page.should have_selector(:"#{web_element_type}", web_element, wait: @timeout)
36
-
37
- elsif condition == 'should_not'
38
- page.should_not have_selector(:"#{web_element_type}", web_element, wait: @timeout)
39
- end
40
- end
41
-
42
- Then(/^page (should|should_not) contain "([^"]*)" button$/) do |condition, button|
43
- # E.g. : page should contain "Save" button
44
- # E.g. : page should_not contain "Save" button
45
- # page.should have_content(content, count: count, wait: @timeout)
46
- sleep 1
47
- if condition == 'should'
48
- page.should have_button(button, wait: @timeout)
49
-
50
- elsif condition == 'should_not'
51
- page.should_not have_button(button, wait: @timeout)
52
- end
53
- end
54
-
55
- Then(/^"([^"]*)" button (should|should_not) be disabled$/) do |button, condition|
56
- sleep 1
57
- if condition == 'should'
58
- find_button button, disabled: true
59
-
60
- elsif condition == 'should_not'
61
- find_button button, disabled: false
62
- end
63
- end
64
-
65
- When(/^"([^"]*)" checkbox should be (checked|unchecked)$/) do |checkbox, condition|
66
- # E.g. : .. "Agree" checkbox should be checked
67
- # checkbox can be label, value or id
68
- if condition == 'checked'
69
- expect(page).to have_field(checkbox, checked: true, visible: true)
70
- elsif condition == 'unchecked'
71
- expect(page).to have_field(checkbox, checked: false, visible: true)
72
- end
73
- end
74
-
75
- When(/^"([^"]*)" radio button should be (selected|unselected)$/) do |radio_button, condition|
76
- # E.g. : .. "Yes" radio button should be selected
77
- # radio_button can be name, id or label
78
- if condition == 'checked'
79
- expect(page).to have_field(radio_button, checked: true, visible: true)
80
- elsif condition == 'unchecked'
81
- expect(page).to have_field(radio_button, checked: false, visible: true)
82
- end
83
- end
84
-
85
- Then(/^validation message should be "([^"]*)" about "([^"]*)" field$/) do |expected_message, element_value|
86
- sleep 1.5
87
- if page.has_css?(element_value)
88
- expected_message.should == page.execute_script("return document.querySelector('#{element_value}').innerHTML.trim();")
89
-
90
- elsif page.has_no_css?(element_value)
91
- expected_message.should == ''
92
- end
93
- end
@@ -1,48 +0,0 @@
1
- require 'step_definitions/env'
2
- require 'support/config'
3
-
4
- And(/^refresh the page$/) do
5
- page.evaluate_script('window.location.reload()')
6
- sleep 1
7
- # location = current_url
8
- # page.driver.browser.navigate.refresh
9
- # sleep 1
10
- # current_url.should == location
11
- end
12
-
13
- When(/^navigate browser to "([^"]*)" url$/) do |url|
14
- visit url
15
- #current_url.should == url
16
- end
17
-
18
- # When(/^navigate browser to "([^"]*)" path$/) do |path|
19
- # visit $URL + path
20
- # current_url.should == $URL + path
21
- # end
22
-
23
- And(/^switch window to (first|last) opened$/) do |condition|
24
- if condition == 'first'
25
- page.driver.browser.switch_to.window(page.driver.browser.window_handles.first)
26
- elsif condition == 'last'
27
- page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)
28
- end
29
- end
30
-
31
- Then(/^user should redirected to "([^"]*)" path$/) do |path|
32
- page.should have_current_path(path, wait: $TIMEOUT)
33
- end
34
-
35
- # Given(/^user on main page$/) do
36
- # current_url.should == @url + '/'
37
- # end
38
-
39
- Then(/^alert message (should|should_not) be "([^"]*)" seçiniz."$/) do |condition, message|
40
- if condition == 'should'
41
- resp = page.driver.browser.switch_to.alert.text
42
- resp.should == message
43
-
44
- elsif condition == 'should_not'
45
- resp = page.driver.browser.switch_to.alert.text
46
- resp.should_not == message
47
- end
48
- end
@@ -1,22 +0,0 @@
1
- require 'step_definitions/env'
2
-
3
- When(/^(check|uncheck) "([^"]*)" checkbox$/) do |condition, checkbox|
4
- # E.g. : .. check "Agree" checkbox
5
- # checkbox can be name, id or label
6
- if condition == 'check'
7
- check(checkbox)
8
- elsif condition == 'uncheck'
9
- uncheck(checkbox)
10
- end
11
- end
12
-
13
- When(/^choose "([^"]*)" radio button$/) do |radio_button|
14
- # E.g. : .. choose "Yes" radio button
15
- # radio_button can be name, id or label
16
- choose(radio_button)
17
- end
18
-
19
- And(/^check type "([^"]*)" value "([^"]*)" web element$/) do |web_element_type, web_element|
20
- page.should have_selector(:"#{web_element_type}", web_element, wait: @timeout)
21
- find(:"#{web_element_type}", web_element).set(true)
22
- end
@@ -1,29 +0,0 @@
1
- require 'step_definitions/env'
2
-
3
- When(/^click "([^"]*)" (link|button) by (id|title|text)$/) do |identifier, identifier_type, condition|
4
- # E.g: .. click "Save" button by text
5
- Capybara.ignore_hidden_elements = false
6
- if condition == 'title' || condition == 'text'
7
- page.should have_content(identifier)
8
-
9
- elsif condition == 'id'
10
- page.should have_selector(:id, identifier)
11
- end
12
-
13
- if identifier_type == 'link'
14
- # link can be id, title or text
15
- Capybara.ignore_hidden_elements = false
16
- click_link(identifier)
17
-
18
- elsif identifier_type == 'button'
19
- # button can be id, title, value or text
20
- Capybara.ignore_hidden_elements = false
21
- click_button(identifier)
22
- end
23
- end
24
-
25
- Then(/^click type "([^"]*)" value "([^"]*)" web element$/) do |web_element_type, web_element|
26
- # E.g: .. click type "id" value "save" web element
27
- page.should have_selector(:"#{web_element_type}", web_element)
28
- find(:"#{web_element_type}", web_element).click
29
- end
@@ -1,12 +0,0 @@
1
- require 'capybara'
2
- require 'capybara/cucumber'
3
- require 'capybara/dsl'
4
- #require 'capybara/poltergeist'
5
- require 'capybara/rspec'
6
- require 'rubygems'
7
- require 'rspec'
8
- require 'rspec/expectations'
9
- require 'rspec/matchers'
10
- require 'selenium-cucumber'
11
- require 'selenium/webdriver'
12
- require 'selenium/webdriver/common/wait'
@@ -1,56 +0,0 @@
1
- require 'step_definitions/env'
2
-
3
- And(/^fill "([^"]*)" with "([^"]*)"$/) do |field, value|
4
- # E.g : ..fill "Phone Number" with "5555555555"
5
- # field can be name, id or label
6
- fill_in(field, with: value)
7
- end
8
-
9
- And(/^fill input boxes with these values:$/) do |table|
10
- values = table.raw
11
- values.each {|raw| fill_in(raw[0], with: raw[1])}
12
- end
13
-
14
- Then(/^fill type "([^"]*)" value "([^"]*)" web element with "([^"]*)"$/) do |web_element_type, web_element, value|
15
- # E.g: .. click type "id" value "save" web element
16
- page.should have_selector(:"#{web_element_type}", web_element, wait: @timeout)
17
- find(:"#{web_element_type}", web_element).set(value)
18
- end
19
-
20
- # =scoping=
21
- # within("//li[@id='employee']") do
22
- # fill_in 'Name', :with => 'Jimmy'
23
- # end
24
- # within(:css, "li#employee") do
25
- # fill_in 'Name', :with => 'Jimmy'
26
- # end
27
- # within_fieldset('Employee') do
28
- # fill_in 'Name', :with => 'Jimmy'
29
- # end
30
- # within_table('Employee') do
31
- # fill_in 'Name', :with => 'Jimmy'
32
- # end
33
-
34
- And(/^fill "([^"]*)" with random (email|password|name|gsm)$/) do |field, condition|
35
- def generate_code(number, condition)
36
- if condition == 'email'
37
- charset = Array('A'..'Z') + Array('a'..'z') + Array(0..9)
38
- Array.new(number) {charset.sample}.join + "@gmail.com"
39
-
40
- elsif condition == 'password'
41
- charset = Array('A'..'Z') + Array('a'..'z') + Array(0..9)
42
- Array.new(number) {charset.sample}.join
43
-
44
- elsif condition == 'name'
45
- charset = Array('A'..'Z') + Array('a'..'z')
46
- Array.new(number) {charset.sample}.join
47
-
48
- elsif condition == 'gsm'
49
- charset = Array(0..9)
50
- Array.new(7) {charset.sample}.join
51
- end
52
- end
53
-
54
- var = generate_code(10, condition)
55
- fill_in(field, with: var)
56
- end
@@ -1,40 +0,0 @@
1
- require 'step_definitions/env'
2
-
3
- And(/^select "([^"]*)" as "([^"]*)" from dropdown$/) do |dropdown, option|
4
- # E.g : select "Country" as "United States" from dropdown
5
- # E.g : select "United States", from: "Country", :match => :first ===>> to select first matched option
6
- # dropdown can be id, name, label text
7
- select(option, from: dropdown) # OR ==>> find('#select_id').select('value')
8
- end
9
-
10
- Then /^"([^"]*)" (should|should_not) be selected for "([^"]*)" dropdown$/ do |selected_option, condition, dropdown|
11
- # E.g : "United States" should be selected for "Country" dropdown
12
- if condition == 'should'
13
- page.should have_select(dropdown, selected: selected_option)
14
-
15
- elsif condition == 'should_not'
16
- page.should_not have_select(dropdown, selected: selected_option)
17
- end
18
- end
19
-
20
- Then /^"([^"]*)" dropdown (should|should_not) contain "([^"]*)" option$/ do |dropdown, condition, option_text|
21
- # E.g : .. "Country" dropdown should contain "United States" option
22
- if condition == 'should'
23
- page.should have_select(dropdown, with_options: [option_text])
24
-
25
- elsif condition == 'should_not'
26
- page.should_not have_select(dropdown, with_options: [option_text])
27
- end
28
- end
29
-
30
- Then /^"([^"]*)" dropdown (should|should_not) contain following options:$/ do |dropdown, condition, table|
31
- values = table.raw
32
- sleep 1
33
- values.each {|raw|
34
- if condition == 'should'
35
- page.should have_select(dropdown, with_options: [raw[0]])
36
-
37
- elsif condition == 'should_not'
38
- page.should_not have_select(dropdown, with_options: [raw[0]])
39
- end}
40
- end
@@ -1,19 +0,0 @@
1
- require 'step_definitions/env'
2
-
3
- When(/^hover to "([^"]*)" value "([^"]*)" web element$/) do |web_element_type, web_element|
4
- find(:"#{web_element_type}", web_element).trigger(:mouseover)
5
- end
6
-
7
- When(/^wait "([^"]*)" seconds$/) do |sec_value|
8
- sleep sec_value.to_i
9
- end
10
-
11
- And(/^generate random string and type into "([^"]*)"$/) do |field|
12
- charset = (0...8).map {(65 + rand(26)).chr}.join
13
- fill_in(field, with: charset)
14
- end
15
-
16
- And(/^execute javascript code "([^"]*)"/) do |code|
17
- page.execute_script(code)
18
- sleep 2
19
- end
@@ -1,5 +0,0 @@
1
- module BaseConstants
2
-
3
- @timeout = 20
4
-
5
- end