selenium-cucumber 0.1.1 → 1.1.1
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.
- checksums.yaml +4 -4
- data/bin/generate.rb +20 -20
- data/bin/helper.rb +50 -50
- data/bin/selenium-cucumber +30 -29
- data/doc/canned_steps.md +8 -0
- data/doc/installation.md +16 -16
- data/doc/selenium-cucumber-help.md +18 -18
- data/example/Gemfile +5 -0
- data/example/Gemfile.lock +36 -0
- data/{Example/image_difference → example/features/actual_images}/test.png +0 -0
- data/{Example → example}/features/assertion_steps_Ex.feature +22 -10
- data/{Example → example}/features/click_steps_Ex.feature +0 -0
- data/{Example → example}/features/configuration_step_Ex.feature +1 -2
- data/example/features/expected_images/logo-PNG.png +0 -0
- data/example/features/expected_images/original_image.jpg +0 -0
- data/{Example/screenshots → example/features/image_difference}/test.png +0 -0
- data/{Example → example}/features/input_steps_Ex.feature +0 -0
- data/{Example → example}/features/javascript_steps_Ex.feature +0 -0
- data/{Example → example}/features/navigation_steps_Ex.feature +3 -3
- data/{Example → example}/features/progress_step_Ex.feature +0 -0
- data/{Example → example}/features/screenshot_step_Ex.feature +5 -1
- data/example/features/screenshots/test.png +0 -0
- data/{Example → example}/features/step_definitions/custom_steps.rb +0 -0
- data/{Example → example}/features/support/env.rb +0 -1
- data/{Example → example}/features/support/hooks.rb +0 -0
- data/example/run_features.rb +42 -0
- data/example/test_page.html +218 -0
- data/features-skeleton/actual_images/test.png +0 -0
- data/features-skeleton/my_first.feature +5 -5
- data/features-skeleton/step_definitions/custom_steps.rb +4 -4
- data/features-skeleton/support/env.rb +38 -38
- data/features-skeleton/support/hooks.rb +37 -33
- data/lib/selenium-cucumber.rb +2 -2
- data/lib/selenium-cucumber/assertion_steps.rb +25 -27
- data/lib/selenium-cucumber/click_elements_steps.rb +9 -12
- data/lib/selenium-cucumber/configuration_steps.rb +3 -4
- data/lib/selenium-cucumber/input_steps.rb +26 -26
- data/lib/selenium-cucumber/javascript_handling_steps.rb +3 -3
- data/lib/selenium-cucumber/methods/assertion_methods.rb +197 -160
- data/lib/selenium-cucumber/methods/click_elements_methods.rb +8 -8
- data/lib/selenium-cucumber/methods/configuration_methods.rb +10 -5
- data/lib/selenium-cucumber/methods/input_methods.rb +32 -45
- data/lib/selenium-cucumber/methods/javascript_handling_methods.rb +7 -7
- data/lib/selenium-cucumber/methods/misc_methods.rb +6 -6
- data/lib/selenium-cucumber/methods/navigate_methods.rb +37 -41
- data/lib/selenium-cucumber/methods/progress_methods.rb +8 -8
- data/lib/selenium-cucumber/methods/required_files.rb +1 -1
- data/lib/selenium-cucumber/methods/screenshot_methods.rb +3 -3
- data/lib/selenium-cucumber/navigation_steps.rb +20 -22
- data/lib/selenium-cucumber/progress_steps.rb +5 -8
- data/lib/selenium-cucumber/screenshot_steps.rb +2 -2
- data/lib/selenium-cucumber/version.rb +1 -1
- metadata +23 -27
- data/Example/expected_images/flower.png +0 -0
- data/Example/expected_images/flower1.png +0 -0
- data/Example/features/new.feature +0 -7
- data/Example/image_difference/difference_20140814210820942.png +0 -0
- data/Example/image_difference/difference_20140815095331224.png +0 -0
- data/Example/image_difference/difference_20140815100021133.png +0 -0
- data/Example/image_difference/difference_20140815100348774.png +0 -0
- data/Example/run_features.rb +0 -42
- data/Example/screenshots/screenshot20140815095553337.png +0 -0
- data/Example/screenshots/screenshot20140815100120197.png +0 -0
- data/Example/screenshots/screenshot20140815100446914.png +0 -0
- data/Example/test_page.html +0 -206
@@ -1,19 +1,19 @@
|
|
1
1
|
require_relative 'required_files'
|
2
2
|
|
3
3
|
|
4
|
-
def click(access_type,access_name)
|
5
|
-
|
4
|
+
def click(access_type, access_name)
|
5
|
+
WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.click
|
6
6
|
end
|
7
7
|
|
8
8
|
def click_forcefully(access_type, access_name)
|
9
|
-
|
9
|
+
$driver.execute_script('arguments[0].click();', WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") })
|
10
10
|
end
|
11
11
|
|
12
|
-
def double_click(access_type,access_value)
|
13
|
-
|
14
|
-
|
12
|
+
def double_click(access_type, access_value)
|
13
|
+
element = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_value}") }
|
14
|
+
$driver.action.double_click(element).perform
|
15
15
|
end
|
16
16
|
|
17
|
-
def submit(access_type,access_name)
|
18
|
-
|
17
|
+
def submit(access_type, access_name)
|
18
|
+
WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.submit
|
19
19
|
end
|
@@ -1,9 +1,14 @@
|
|
1
1
|
require_relative 'required_files'
|
2
2
|
|
3
|
-
#method to print configuration
|
3
|
+
# method to print configuration
|
4
4
|
|
5
5
|
def print_congifugartion
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
puts ''
|
7
|
+
puts "Date : #{Time.now.strftime("%d-%B-%Y")}"
|
8
|
+
puts "Time : #{Time.now.strftime("%I:%M:%S:%p")}"
|
9
|
+
puts 'Operating System : ' + Selenium::WebDriver::Platform.os.to_s.upcase
|
10
|
+
puts 'Browser : ' + $driver.capabilities.browser_name.to_s.upcase + " " + $driver.capabilities.version.to_s
|
11
|
+
puts ''
|
12
|
+
end
|
13
|
+
|
14
|
+
|
@@ -1,80 +1,67 @@
|
|
1
1
|
require_relative 'required_files'
|
2
2
|
|
3
3
|
# method to enter text into textfield
|
4
|
-
def enter_text(access_type,text,access_name)
|
5
|
-
|
4
|
+
def enter_text(access_type, text, access_name)
|
5
|
+
WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.send_keys text
|
6
6
|
end
|
7
7
|
|
8
8
|
# method to clear text from textfield
|
9
|
-
def clear_text(access_type,access_name)
|
10
|
-
|
9
|
+
def clear_text(access_type, access_name)
|
10
|
+
WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.clear
|
11
11
|
end
|
12
12
|
|
13
13
|
# method to select option from dropdwon list
|
14
14
|
def select_option_from_dropdown(access_type, by, option, access_name)
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
dropdown = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }
|
16
|
+
select_list = Selenium::WebDriver::Support::Select.new(dropdown)
|
17
|
+
select_list.select_by(:"#{by}", "#{option}")
|
18
18
|
end
|
19
19
|
|
20
20
|
# method to select all option from dropdwon list
|
21
21
|
def select_all_option_from_multiselect_dropdown(access_type, access_name)
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
dropdown = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }
|
23
|
+
select_list = Selenium::WebDriver::Support::Select.new(dropdown)
|
24
|
+
select_list.select_all
|
25
25
|
end
|
26
26
|
|
27
27
|
# method to unselect all option from dropdwon list
|
28
28
|
def unselect_all_option_from_multiselect_dropdown(access_type, access_name)
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
dropdown = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }
|
30
|
+
select_list = Selenium::WebDriver::Support::Select.new(dropdown)
|
31
|
+
select_list.deselect_all
|
32
32
|
end
|
33
33
|
|
34
|
-
#method to check checkbox
|
34
|
+
# method to check checkbox
|
35
35
|
def check_checkbox(access_type, access_name)
|
36
|
-
|
37
|
-
|
38
|
-
if !checkbox.selected?
|
39
|
-
checkbox.click
|
40
|
-
end
|
36
|
+
checkbox = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }
|
37
|
+
checkbox.click unless checkbox.selected?
|
41
38
|
end
|
42
39
|
|
43
|
-
#method to uncheck checkbox
|
40
|
+
# method to uncheck checkbox
|
44
41
|
def uncheck_checkbox(access_type, access_name)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
checkbox = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }
|
43
|
+
|
44
|
+
if checkbox.selected?
|
45
|
+
checkbox.click
|
46
|
+
end
|
50
47
|
end
|
51
48
|
|
52
|
-
#method to select radio button
|
49
|
+
# method to select radio button
|
53
50
|
def toggle_checkbox(access_type, access_name)
|
54
|
-
|
51
|
+
WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.click
|
55
52
|
end
|
56
53
|
|
57
|
-
#method to select radio button
|
54
|
+
# method to select radio button
|
58
55
|
def select_radio_button(access_type, access_name)
|
59
|
-
|
60
|
-
|
61
|
-
if !radio_button.selected?
|
62
|
-
radio_button.click
|
63
|
-
end
|
56
|
+
radio_button = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }
|
57
|
+
radio_button.click unless radio_button.selected?
|
64
58
|
end
|
65
59
|
|
66
|
-
#method to select option from radio button group
|
60
|
+
# method to select option from radio button group
|
67
61
|
def select_option_from_radio_button_group(access_type, by, option, access_name)
|
62
|
+
radio_button_group = WAIT.until { $driver.find_elements(:"#{access_type}" => "#{access_name}") }
|
68
63
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
ele = radio_button_group.find { |rb| getter.call(rb, by)==option }
|
74
|
-
|
75
|
-
if !ele.selected?
|
76
|
-
ele.click
|
77
|
-
end
|
64
|
+
getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text }
|
65
|
+
ele = radio_button_group.find { |rb| getter.call(rb, by) == option }
|
66
|
+
ele.click unless ele.selected?
|
78
67
|
end
|
79
|
-
|
80
|
-
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require_relative 'required_files'
|
2
2
|
|
3
|
-
def handle_alert
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
def handle_alert(decesion)
|
4
|
+
if decesion == 'accept'
|
5
|
+
$driver.switch_to.alert.accept
|
6
|
+
else
|
7
|
+
$driver.switch_to.alert.dismiss
|
8
|
+
end
|
9
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
|
2
|
-
#custome exception class
|
2
|
+
# custome exception class
|
3
3
|
class TestCaseFailed < Exception
|
4
4
|
end
|
5
5
|
|
6
6
|
# WAIT instance for explicit wait
|
7
7
|
WAIT = Selenium::WebDriver::Wait.new(:timeout => 30)
|
8
8
|
|
9
|
-
#method to validate locator
|
9
|
+
# method to validate locator
|
10
10
|
def valid_locator_type? type
|
11
11
|
%w(id class css name xpath).include? type
|
12
12
|
end
|
13
13
|
|
14
14
|
def validate_locator type
|
15
|
-
|
15
|
+
raise "Invalid locator type - #{type}" unless valid_locator_type? type
|
16
16
|
end
|
17
17
|
|
18
|
-
#method to validate dropdown selector
|
18
|
+
# method to validate dropdown selector
|
19
19
|
def valid_option_by? option_by
|
20
20
|
%w(text value index).include? option_by
|
21
21
|
end
|
22
22
|
|
23
23
|
def validate_option_by option_by
|
24
|
-
|
25
|
-
end
|
24
|
+
raise "Invalid option by - #{option_by}" unless valid_option_by? option_by
|
25
|
+
end
|
@@ -1,89 +1,86 @@
|
|
1
1
|
require_relative 'required_files'
|
2
2
|
|
3
|
-
#method to open link
|
3
|
+
# method to open link
|
4
4
|
def navigate_to(link)
|
5
|
-
|
5
|
+
$driver.get link
|
6
6
|
end
|
7
7
|
|
8
|
-
#method to navigate back & forword
|
8
|
+
# method to navigate back & forword
|
9
9
|
def navigate(direction)
|
10
|
-
if direction==
|
11
|
-
|
10
|
+
if direction == 'back'
|
11
|
+
$driver.navigate.back
|
12
12
|
else
|
13
13
|
$driver.navigate.forward
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
#method to quite webdriver instance
|
17
|
+
# method to quite webdriver instance
|
18
18
|
def close_driver
|
19
|
-
|
19
|
+
$driver.quit
|
20
20
|
end
|
21
21
|
|
22
|
-
#method to return key by os wise
|
22
|
+
# method to return key by os wise
|
23
23
|
def get_key
|
24
|
-
os=Selenium::WebDriver::Platform.os
|
25
|
-
if os.to_s==
|
26
|
-
return
|
27
|
-
elsif os.to_s==
|
28
|
-
return
|
24
|
+
os = Selenium::WebDriver::Platform.os
|
25
|
+
if os.to_s == 'windows'
|
26
|
+
return 'control'
|
27
|
+
elsif os.to_s == 'macosx'
|
28
|
+
return 'command'
|
29
29
|
else
|
30
|
-
raise
|
30
|
+
raise 'Invalid OS'
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
#Method to zoom in/out page
|
34
|
+
# Method to zoom in/out page
|
35
35
|
def zoom_in_out(in_out)
|
36
36
|
$driver.action.key_down(:"#{get_key}").send_keys(:"#{in_out}").key_up(:"#{get_key}").perform
|
37
37
|
end
|
38
38
|
|
39
|
-
#Method to zoom in/out web page until web element displyas
|
39
|
+
# Method to zoom in/out web page until web element displyas
|
40
40
|
def zoom_in_out_till_element_display(access_type, in_out, access_name)
|
41
|
-
|
42
41
|
while true
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
42
|
+
if WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.displayed?
|
43
|
+
break
|
44
|
+
else
|
45
|
+
$driver.action.key_down(:"#{get_key}").send_keys(:"#{in_out}").key_up(:"#{get_key}").perform
|
46
|
+
end
|
49
47
|
end
|
50
|
-
|
51
48
|
end
|
52
49
|
|
53
|
-
#Method to resize browser
|
54
|
-
def resize_browser(width,heigth)
|
55
|
-
$driver.manage.window.resize_to(width,heigth)
|
50
|
+
# Method to resize browser
|
51
|
+
def resize_browser(width, heigth)
|
52
|
+
$driver.manage.window.resize_to(width, heigth)
|
56
53
|
end
|
57
54
|
|
58
|
-
#Method to maximize browser
|
55
|
+
# Method to maximize browser
|
59
56
|
def maximize_browser
|
60
|
-
$driver.manage
|
57
|
+
$driver.manage.window.maximize
|
61
58
|
end
|
62
59
|
|
63
|
-
#Method to hover on element
|
64
|
-
def hover_over_element(access_type,access_name)
|
60
|
+
# Method to hover on element
|
61
|
+
def hover_over_element(access_type, access_name)
|
65
62
|
element = WAIT.until {$driver.find_element(:"#{access_type}" => "#{access_name}")}
|
66
63
|
$driver.action.move_to(element).perform
|
67
64
|
end
|
68
65
|
|
69
|
-
#Method to scroll page to perticular element
|
70
|
-
def scroll_to_element(access_type,access_name)
|
66
|
+
# Method to scroll page to perticular element
|
67
|
+
def scroll_to_element(access_type, access_name)
|
71
68
|
ele_scroll = WAIT.until {$driver.find_element(:"#{access_type}" => "#{access_name}")}
|
72
69
|
ele_scroll.location_once_scrolled_into_view
|
73
70
|
end
|
74
71
|
|
75
|
-
#method to scroll page to top or end
|
72
|
+
# method to scroll page to top or end
|
76
73
|
def scroll_page(to)
|
77
|
-
if to==
|
78
|
-
$driver.execute_script(
|
79
|
-
elsif to==
|
80
|
-
$driver.execute_script(
|
74
|
+
if to == 'end'
|
75
|
+
$driver.execute_script('window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));')
|
76
|
+
elsif to == 'top'
|
77
|
+
$driver.execute_script('window.scrollTo(Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight),0);')
|
81
78
|
else
|
82
79
|
raise "Exception : Invalid Direction (only scroll \"top\" or \"end\")"
|
83
80
|
end
|
84
81
|
end
|
85
82
|
|
86
|
-
$old_win=nil
|
83
|
+
$old_win = nil
|
87
84
|
|
88
85
|
# Method to switch to new window
|
89
86
|
def switch_to_new_window
|
@@ -92,7 +89,6 @@ def switch_to_new_window
|
|
92
89
|
end
|
93
90
|
|
94
91
|
# Method to switch to old window
|
95
|
-
|
96
92
|
def switch_to_old_window
|
97
93
|
$driver.switch_to.window($old_win)
|
98
|
-
end
|
94
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require_relative 'required_files'
|
2
2
|
|
3
3
|
def wait(time)
|
4
|
-
|
4
|
+
sleep time.to_i
|
5
5
|
end
|
6
6
|
|
7
|
-
def wait_for_element_to_display(access_type,access_name,duration)
|
8
|
-
|
9
|
-
|
7
|
+
def wait_for_element_to_display(access_type, access_name, duration)
|
8
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i) # seconds
|
9
|
+
wait.until { $driver.find_element(:"#{access_type}" => "#{access_name}").displayed? }
|
10
10
|
end
|
11
11
|
|
12
|
-
def wait_for_element_to_enable(access_type,access_name,duration)
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
def wait_for_element_to_enable(access_type, access_name, duration)
|
13
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i) # seconds
|
14
|
+
wait.until { $driver.find_element(:"#{access_type}" => "#{access_name}").enabled? }
|
15
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'required_files'
|
2
2
|
|
3
3
|
def take_screenshot
|
4
|
-
|
5
|
-
|
6
|
-
end
|
4
|
+
cur_time = Time.now.strftime('%Y%m%d%H%M%S%L')
|
5
|
+
$driver.save_screenshot('./features/screenshots/screenshot' + cur_time + '.png')
|
6
|
+
end
|
@@ -1,32 +1,32 @@
|
|
1
1
|
require_relative 'methods/navigate_methods'
|
2
2
|
|
3
3
|
Then(/^I navigate to "([^\"]*)"$/)do |link|
|
4
|
-
|
4
|
+
navigate_to(link)
|
5
5
|
end
|
6
6
|
|
7
7
|
Then(/^I navigate forward/) do
|
8
|
-
|
8
|
+
navigate('forward')
|
9
9
|
end
|
10
10
|
|
11
11
|
Then(/^I navigate back/) do
|
12
|
-
|
12
|
+
navigate('back')
|
13
13
|
end
|
14
14
|
|
15
15
|
Then(/^I close browser$/) do
|
16
|
-
|
16
|
+
close_driver
|
17
17
|
end
|
18
18
|
|
19
|
-
#step to resize browser
|
19
|
+
# step to resize browser
|
20
20
|
Then(/^I resize browser window size to width (\d+) and height (\d+)$/) do |width, heigth|
|
21
21
|
resize_browser(width, heigth)
|
22
22
|
end
|
23
23
|
|
24
|
-
#step to maximize browser
|
24
|
+
# step to maximize browser
|
25
25
|
Then(/^I maximize browser window$/) do
|
26
26
|
maximize_browser
|
27
27
|
end
|
28
28
|
|
29
|
-
#steps to refresh page
|
29
|
+
# steps to refresh page
|
30
30
|
Then(/^I refresh page$/) do
|
31
31
|
$driver.navigate.refresh
|
32
32
|
end
|
@@ -39,41 +39,39 @@ Then(/^I switch to previous window$/) do
|
|
39
39
|
switch_to_old_window
|
40
40
|
end
|
41
41
|
|
42
|
-
#steps to scroll to element
|
42
|
+
# steps to scroll to element
|
43
43
|
Then(/^I scroll to element having (.+) "(.*?)"$/) do |type, access_name|
|
44
|
-
|
45
|
-
|
44
|
+
validate_locator type
|
45
|
+
scroll_to_element(type, access_name)
|
46
46
|
end
|
47
47
|
|
48
|
-
#steps to scroll web page to top or end
|
48
|
+
# steps to scroll web page to top or end
|
49
49
|
Then(/^I scroll to (top|end) of page$/) do |to|
|
50
50
|
scroll_page(to)
|
51
51
|
end
|
52
52
|
|
53
|
-
#
|
53
|
+
# step to hover over a element Note: Doesn't work on Windows firefox
|
54
54
|
When(/^I hover over element having (.+) "(.*?)"$/) do |type, access_name|
|
55
55
|
validate_locator type
|
56
56
|
hover_over_element(type, access_name)
|
57
57
|
end
|
58
58
|
|
59
|
-
#steps to zoom in page
|
59
|
+
# steps to zoom in page
|
60
60
|
Then(/^I zoom in page$/) do
|
61
|
-
zoom_in_out(
|
61
|
+
zoom_in_out('add')
|
62
62
|
end
|
63
63
|
|
64
|
-
#steps to zoom out page
|
64
|
+
# steps to zoom out page
|
65
65
|
Then(/^I zoom out page$/) do
|
66
|
-
zoom_in_out(
|
66
|
+
zoom_in_out('subtract')
|
67
67
|
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
Then(/^I zoom out page till I see element having (.+) "(.*?)"$/) do |type,access_name|
|
69
|
+
# steps to zoom out till element displays
|
70
|
+
Then(/^I zoom out page till I see element having (.+) "(.*?)"$/) do |type, access_name|
|
72
71
|
validate_locator type
|
73
|
-
zoom_in_out_till_element_display(type,
|
72
|
+
zoom_in_out_till_element_display(type, 'subtract', access_name)
|
74
73
|
end
|
75
74
|
|
76
|
-
|
77
75
|
Then(/^I reset page view$/) do
|
78
|
-
zoom_in_out(
|
76
|
+
zoom_in_out('numpad0')
|
79
77
|
end
|