bdd-helper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e59073ed71889646cb4829a643aab0438ddab30
4
+ data.tar.gz: 884b1a964d59a4d697d9fec07ae15d67d9645e84
5
+ SHA512:
6
+ metadata.gz: 67c4c3012d2541f4dc87d51678dd7f2b4c043e3b0c767ae8d874d6e61585a8608b672560d894867adc521ed3da64dc15bec3ed3d8bf783de08d2a9a4e2924cde
7
+ data.tar.gz: 92ca80b4171db51531b3c3e0c501a8568a3f8b2559b5895223fc9b3baf2804dee29eefb88b4339b2116711d18adbf68685471bc3cb9d64a4f4b9d9b4ad455f93
data/lib/bdd-helper.rb ADDED
@@ -0,0 +1,5 @@
1
+ class BddHelper
2
+ def self.version
3
+ puts "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,93 @@
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
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,29 @@
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
@@ -0,0 +1,12 @@
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'
@@ -0,0 +1,56 @@
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
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,5 @@
1
+ module BaseConstants
2
+
3
+ @timeout = 20
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bdd-helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mehmet Ali Aydin
8
+ autorequire:
9
+ bindir: bin
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
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - 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
29
+ homepage: http://rubygems.org/gems/bdd-helper
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.6.11
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Helper step definitions for Gherkin
53
+ test_files: []