selenium-cucumber 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/canned_steps.md +337 -76
- data/doc/installation.md +13 -13
- data/features-skeleton/my_first.feature +5 -5
- data/features-skeleton/step_definitions/custom_steps.rb +3 -3
- data/features-skeleton/support/env.rb +37 -29
- data/lib/selenium-cucumber.rb +8 -7
- data/lib/selenium-cucumber/assertion_steps.rb +436 -57
- data/lib/selenium-cucumber/configuration_steps.rb +7 -0
- data/lib/selenium-cucumber/input_steps.rb +322 -0
- data/lib/selenium-cucumber/javascript_handling_steps.rb +9 -0
- data/lib/selenium-cucumber/methods/assertion_methods.rb +165 -34
- data/lib/selenium-cucumber/methods/configuration_methods.rb +9 -0
- data/lib/selenium-cucumber/methods/input_methods.rb +87 -0
- data/lib/selenium-cucumber/methods/javascript_handling_methods.rb +6 -0
- data/lib/selenium-cucumber/methods/navigate_methods.rb +75 -11
- data/lib/selenium-cucumber/methods/press_button_methods.rb +6 -6
- data/lib/selenium-cucumber/methods/progress_methods.rb +15 -6
- data/lib/selenium-cucumber/methods/screenshot_methods.rb +7 -0
- data/lib/selenium-cucumber/navigation_steps.rb +104 -9
- data/lib/selenium-cucumber/press_button_steps.rb +37 -13
- data/lib/selenium-cucumber/progress_steps.rb +58 -0
- data/lib/selenium-cucumber/screenshot_steps.rb +5 -0
- data/lib/selenium-cucumber/version.rb +1 -1
- metadata +19 -11
- data/lib/selenium-cucumber/enter_text_steps.rb +0 -27
- data/lib/selenium-cucumber/methods/enter_text_methods.rb +0 -14
- data/lib/selenium-cucumber/progress_step.rb +0 -17
- data/lib/selenium-cucumber/screenshot_step.rb +0 -8
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "selenium-webdriver"
|
3
|
+
|
4
|
+
# method to enter text into textfield
|
5
|
+
def enter_text(access_type,text,access_name)
|
6
|
+
$driver.find_element(:"#{access_type}" => "#{access_name}").send_keys text
|
7
|
+
end
|
8
|
+
|
9
|
+
# method to clear text from textfield
|
10
|
+
def clear_text(access_type,access_name)
|
11
|
+
$driver.find_element(:"#{access_type}" => "#{access_name}").clear
|
12
|
+
end
|
13
|
+
|
14
|
+
# method to select option from dropdwon list
|
15
|
+
def select_option_from_dropdown(access_type, by, option, access_name)
|
16
|
+
dropdown = $driver.find_element(:"#{access_type}" => "#{access_name}")
|
17
|
+
select_list = Selenium::WebDriver::Support::Select.new(dropdown)
|
18
|
+
select_list.select_by(:"#{by}", "#{option}")
|
19
|
+
end
|
20
|
+
|
21
|
+
# method to unselect all option from dropdwon list
|
22
|
+
def unselect_option_from_dropdown(access_type, access_name)
|
23
|
+
dropdown = $driver.find_element(:"#{access_type}" => "#{access_name}")
|
24
|
+
select_list = Selenium::WebDriver::Support::Select.new(dropdown)
|
25
|
+
select_list.deselect_all()
|
26
|
+
end
|
27
|
+
|
28
|
+
#method to check checkbox
|
29
|
+
def check_checkbox(access_type, access_name)
|
30
|
+
checkbox = $driver.find_element(:"#{access_type}" => "#{access_name}")
|
31
|
+
|
32
|
+
if !checkbox.selected?
|
33
|
+
checkbox.click
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#method to uncheck checkbox
|
38
|
+
def uncheck_checkbox(access_type, access_name)
|
39
|
+
checkbox = $driver.find_element(:"#{access_type}" => "#{access_name}")
|
40
|
+
|
41
|
+
if checkbox.selected?
|
42
|
+
checkbox.click
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#method to select radio button
|
47
|
+
def toggle_checkbox(access_type, access_name)
|
48
|
+
$driver.find_element(:"#{access_type}" => "#{access_name}").click
|
49
|
+
end
|
50
|
+
|
51
|
+
#method to select radio button
|
52
|
+
def select_radio_button(access_type, access_name)
|
53
|
+
radio_button = $driver.find_element(:"#{access_type}" => "#{access_name}")
|
54
|
+
|
55
|
+
if !radio_button.selected?
|
56
|
+
radio_button.click
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
#method to select option from radio button group
|
61
|
+
def select_option_from_radio_button_group(access_type, by, option, access_name)
|
62
|
+
radio_button_group = $driver.find_elements(:"#{access_type}" => "#{access_name}")
|
63
|
+
|
64
|
+
i=0
|
65
|
+
|
66
|
+
if by=="value"
|
67
|
+
while i<radio_button_group.length
|
68
|
+
if radio_button_group[i].attribute("value")==option
|
69
|
+
if !radio_button_group[i].selected?
|
70
|
+
radio_button_group[i].click
|
71
|
+
end
|
72
|
+
break
|
73
|
+
end
|
74
|
+
i=i+1
|
75
|
+
end
|
76
|
+
else
|
77
|
+
while i<radio_button_group.length
|
78
|
+
if radio_button_group[i].text==option
|
79
|
+
if !radio_button_group[i].selected?
|
80
|
+
radio_button_group[i].click
|
81
|
+
end
|
82
|
+
break
|
83
|
+
end
|
84
|
+
i=i+1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -1,11 +1,75 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require "selenium-webdriver"
|
3
|
-
|
4
|
-
|
5
|
-
def navigate_to(link)
|
6
|
-
$driver.get link
|
7
|
-
end
|
8
|
-
|
9
|
-
def
|
10
|
-
$driver.
|
11
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require "selenium-webdriver"
|
3
|
+
|
4
|
+
|
5
|
+
def navigate_to(link)
|
6
|
+
$driver.get link
|
7
|
+
end
|
8
|
+
|
9
|
+
def navigate(direction)
|
10
|
+
$driver.navigate.direction
|
11
|
+
end
|
12
|
+
|
13
|
+
def close_driver
|
14
|
+
$driver.quit
|
15
|
+
end
|
16
|
+
|
17
|
+
def scroll_to_element(access_type,access_name)
|
18
|
+
ele_scroll = $driver.find_element(:"#{access_type}" => "#{access_name}")
|
19
|
+
ele_scroll.location_once_scrolled_into_view
|
20
|
+
end
|
21
|
+
|
22
|
+
def zoom_in_out(in_out)
|
23
|
+
if get_os=="windows"
|
24
|
+
key="control"
|
25
|
+
elsif get_os=="mac"
|
26
|
+
key="command"
|
27
|
+
end
|
28
|
+
|
29
|
+
$driver.action.key_down(:"#{key}").send_keys(:"#{in_out}").key_up(:"#{key}").perform
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def zoom_in_out_till_element_display(access_type, in_out, access_name)
|
34
|
+
|
35
|
+
if get_os=="windows"
|
36
|
+
key="control"
|
37
|
+
elsif get_os=="mac"
|
38
|
+
key="command"
|
39
|
+
end
|
40
|
+
|
41
|
+
while true
|
42
|
+
|
43
|
+
if $driver.find_element(:"#{access_type}" => "#{access_name}").displayed?
|
44
|
+
break
|
45
|
+
else
|
46
|
+
$driver.action.key_down(:"#{key}").send_keys(:"#{in_out}").key_up(:"#{key}").perform
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def get_os
|
54
|
+
case CONFIG['host_os']
|
55
|
+
when /mingw32|windows/i
|
56
|
+
# Windows
|
57
|
+
return "windows"
|
58
|
+
when /linux|arch/i
|
59
|
+
# Linux
|
60
|
+
return "linux"
|
61
|
+
when /sunos|solaris/i
|
62
|
+
# Solaris
|
63
|
+
return "solaris"
|
64
|
+
when /darwin/i
|
65
|
+
#MAC OS X
|
66
|
+
return "mac"
|
67
|
+
else
|
68
|
+
# whatever
|
69
|
+
return "Other"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def resize_browser(width,heigth)
|
74
|
+
$driver.manage.window.resize_to(width,heigth)
|
75
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require "selenium-webdriver"
|
3
|
-
|
4
|
-
def click(access_type,access_name)
|
5
|
-
element = $driver.find_element(:"#{access_type}" => "#{access_name}").click
|
6
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require "selenium-webdriver"
|
3
|
+
|
4
|
+
def click(access_type,access_name)
|
5
|
+
element = $driver.find_element(:"#{access_type}" => "#{access_name}").click
|
6
|
+
end
|
@@ -1,7 +1,16 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require "selenium-webdriver"
|
3
|
-
|
4
|
-
def
|
5
|
-
|
6
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require "selenium-webdriver"
|
3
|
+
|
4
|
+
def wait(time)
|
5
|
+
sleep time.to_i
|
6
|
+
end
|
7
|
+
|
8
|
+
def wait_for_element_to_display(access_type,access_name,duration)
|
9
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i) # seconds
|
10
|
+
wait.until { $driver.find_element(:"#{access_type}" => "#{access_name}").displayed? }
|
11
|
+
end
|
12
|
+
|
13
|
+
def wait_for_element_to_enable(access_type,access_name,duration)
|
14
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => duration.to_i) # seconds
|
15
|
+
wait.until { $driver.find_element(:"#{access_type}" => "#{access_name}").enabled? }
|
7
16
|
end
|
@@ -1,9 +1,104 @@
|
|
1
|
-
require_relative 'methods/navigate_methods'
|
2
|
-
|
3
|
-
Then(/^I navigate to "([^\"]*)"$/)do |link|
|
4
|
-
navigate_to(link)
|
5
|
-
end
|
6
|
-
|
7
|
-
Then(/^I
|
8
|
-
|
9
|
-
end
|
1
|
+
require_relative 'methods/navigate_methods'
|
2
|
+
|
3
|
+
Then(/^I navigate to "([^\"]*)"$/)do |link|
|
4
|
+
navigate_to(link)
|
5
|
+
end
|
6
|
+
|
7
|
+
Then(/^I navigate forward/) do
|
8
|
+
navigate("forward")
|
9
|
+
end
|
10
|
+
|
11
|
+
Then(/^I navigate back/) do
|
12
|
+
navigate("back")
|
13
|
+
end
|
14
|
+
|
15
|
+
Then(/^I close browser$/) do
|
16
|
+
close_driver
|
17
|
+
end
|
18
|
+
|
19
|
+
#step to resize browser
|
20
|
+
Then(/^I resize browser with width (\d+) and heigth (\d+)$/) do |width, heigth|
|
21
|
+
resize_browser(width,heigth)
|
22
|
+
end
|
23
|
+
|
24
|
+
#steps to refresh page
|
25
|
+
Then(/^I refresh page$/) do
|
26
|
+
$driver.navigate.refresh
|
27
|
+
end
|
28
|
+
|
29
|
+
#steps to scroll to element
|
30
|
+
Then(/^I scroll to the element having id "(.*?)"$/) do |access_name|
|
31
|
+
scroll_to_element("id",access_name)
|
32
|
+
end
|
33
|
+
|
34
|
+
Then(/^I scroll to the element having name "(.*?)"$/) do |access_name|
|
35
|
+
scroll_to_element("name",access_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
Then(/^I scroll to the element having class "(.*?)"$/) do |access_name|
|
39
|
+
scroll_to_element("class",access_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
Then(/^I scroll to the element having xpath "(.*?)"$/) do |access_name|
|
43
|
+
scroll_to_element("xpath",access_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
Then(/^I scroll to the element having css "(.*?)"$/) do |access_name|
|
47
|
+
scroll_to_element("css",access_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
#steps to zoom in page
|
51
|
+
Then(/^I zoom in page$/) do
|
52
|
+
zoom_in_out("add")
|
53
|
+
end
|
54
|
+
|
55
|
+
#steps to zoom out page
|
56
|
+
Then(/^I zoom out page$/) do
|
57
|
+
zoom_in_out("subtract")
|
58
|
+
end
|
59
|
+
|
60
|
+
#steps to zoom in till element displays
|
61
|
+
Then(/^I zoom in page till I see element having id "(.*?)"$/) do |access_name|
|
62
|
+
zoom_in_out_till_element_display("id", "add", access_name)
|
63
|
+
end
|
64
|
+
|
65
|
+
Then(/^I zoom in page till I see element having name "(.*?)"$/) do |access_name|
|
66
|
+
zoom_in_out_till_element_display("name", "add", access_name)
|
67
|
+
end
|
68
|
+
|
69
|
+
Then(/^I zoom in page till I see element having class "(.*?)"$/) do |access_name|
|
70
|
+
zoom_in_out_till_element_display("class", "add", access_name)
|
71
|
+
end
|
72
|
+
|
73
|
+
Then(/^I zoom in page till I see element having xpath "(.*?)"$/) do |access_name|
|
74
|
+
zoom_in_out_till_element_display("xpath", "add", access_name)
|
75
|
+
end
|
76
|
+
|
77
|
+
Then(/^I zoom in page till I see element having css "(.*?)"$/) do |access_name|
|
78
|
+
zoom_in_out_till_element_display("css", "add", access_name)
|
79
|
+
end
|
80
|
+
|
81
|
+
#steps to zoom out till element displays
|
82
|
+
Then(/^I zoom out page till I see element having id "(.*?)"$/) do |access_name|
|
83
|
+
zoom_in_out_till_element_display("id", "subtract", access_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
Then(/^I zoom out page till I see element having name "(.*?)"$/) do |access_name|
|
87
|
+
zoom_in_out_till_element_display("name", "subtract", access_name)
|
88
|
+
end
|
89
|
+
|
90
|
+
Then(/^I zoom out page till I see element having class "(.*?)"$/) do |access_name|
|
91
|
+
zoom_in_out_till_element_display("class", "subtract", access_name)
|
92
|
+
end
|
93
|
+
|
94
|
+
Then(/^I zoom out page till I see element having xpath "(.*?)"$/) do |access_name|
|
95
|
+
zoom_in_out_till_element_display("xpath", "subtract", access_name)
|
96
|
+
end
|
97
|
+
|
98
|
+
Then(/^I zoom out page till I see element having css "(.*?)"$/) do |access_name|
|
99
|
+
zoom_in_out_till_element_display("css", "subtract", access_name)
|
100
|
+
end
|
101
|
+
|
102
|
+
Then(/^I reset page view$/) do
|
103
|
+
zoom_in_out("numpad0")
|
104
|
+
end
|
@@ -1,13 +1,37 @@
|
|
1
|
-
require_relative 'methods/press_button_methods'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
require_relative 'methods/press_button_methods'
|
2
|
+
|
3
|
+
# click on web element
|
4
|
+
#By ID
|
5
|
+
When(/^I click on element having id "(.*?)"$/) do |access_name|
|
6
|
+
click("id",access_name)
|
7
|
+
end
|
8
|
+
|
9
|
+
#By NAME
|
10
|
+
When(/^I click on element having name "(.*?)"$/) do |access_name|
|
11
|
+
click("name",access_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
#By CLASS
|
15
|
+
When(/^I click on element having class "(.*?)"$/) do |access_name|
|
16
|
+
click("class",access_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
#By XPATH
|
20
|
+
When(/^I click on element having xpath "(.*?)"$/) do |access_name|
|
21
|
+
click("xpath",access_name)
|
22
|
+
end
|
23
|
+
|
24
|
+
#By CSS
|
25
|
+
When(/^I click on element having css "(.*?)"$/) do |access_name|
|
26
|
+
click("css",access_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
#steps to click on link
|
30
|
+
|
31
|
+
Then(/^I click on link having text "(.*?)"$/) do |access_name|
|
32
|
+
click("link",access_name)
|
33
|
+
end
|
34
|
+
|
35
|
+
Then(/^I click on link having partial text "(.*?)"$/) do |access_name|
|
36
|
+
click("partial_link_text",access_name)
|
37
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative 'methods/progress_methods'
|
2
|
+
|
3
|
+
# wait for specific period of time
|
4
|
+
Then(/^I wait for (\d+) sec$/) do |time|
|
5
|
+
wait(time)
|
6
|
+
end
|
7
|
+
|
8
|
+
# wait for specific element to display for specific period of time
|
9
|
+
#By ID
|
10
|
+
Then(/^I wait (\d+) seconds for element to display having id "(.*?)"$/) do |duration, access_name|
|
11
|
+
wait_for_element_to_display("id",access_name,duration)
|
12
|
+
end
|
13
|
+
|
14
|
+
#By NAME
|
15
|
+
Then(/^I wait (\d+) seconds for element to display having name "(.*?)"$/) do |duration, access_name|
|
16
|
+
wait_for_element_to_display("name",access_name,duration)
|
17
|
+
end
|
18
|
+
|
19
|
+
#By CLASS
|
20
|
+
Then(/^I wait (\d+) seconds for element to display having class "(.*?)"$/) do |duration, access_name|
|
21
|
+
wait_for_element_to_display("class",access_name,duration)
|
22
|
+
end
|
23
|
+
|
24
|
+
#By XPATH
|
25
|
+
Then(/^I wait (\d+) seconds for element to display having xpath "(.*?)"$/) do |duration, access_name|
|
26
|
+
wait_for_element_to_display("xpath",access_name,duration)
|
27
|
+
end
|
28
|
+
|
29
|
+
#By CSS
|
30
|
+
Then(/^I wait (\d+) seconds for element to display having css "(.*?)"$/) do |duration, access_name|
|
31
|
+
wait_for_element_to_display("css",access_name,duration)
|
32
|
+
end
|
33
|
+
|
34
|
+
# wait for specific element to enable for specific period of time
|
35
|
+
#By ID
|
36
|
+
Then(/^I wait (\d+) seconds for element to enable having id "(.*?)"$/) do |duration, access_name|
|
37
|
+
wait_for_element_to_enable("id",access_name,duration)
|
38
|
+
end
|
39
|
+
|
40
|
+
#By NAME
|
41
|
+
Then(/^I wait (\d+) seconds for element to enable having name "(.*?)"$/) do |duration, access_name|
|
42
|
+
wait_for_element_to_enable("name",access_name,duration)
|
43
|
+
end
|
44
|
+
|
45
|
+
#By CLASS
|
46
|
+
Then(/^I wait (\d+) seconds for element to enable having class "(.*?)"$/) do |duration, access_name|
|
47
|
+
wait_for_element_to_enable("class",access_name,duration)
|
48
|
+
end
|
49
|
+
|
50
|
+
#By XPATH
|
51
|
+
Then(/^I wait (\d+) seconds for element to enable having xpath "(.*?)"$/) do |duration, access_name|
|
52
|
+
wait_for_element_to_enable("xpath",access_name,duration)
|
53
|
+
end
|
54
|
+
|
55
|
+
#By CSS
|
56
|
+
Then(/^I wait (\d+) seconds for element to enable having css "(.*?)"$/) do |duration, access_name|
|
57
|
+
wait_for_element_to_enable("css",access_name,duration)
|
58
|
+
end
|