selenium-cucumber 0.0.8 → 0.0.9
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.
- data/bin/generate.rb +20 -20
- data/bin/helper.rb +50 -50
- data/bin/selenium-cucumber +26 -26
- data/doc/canned_steps.md +463 -361
- data/doc/installation.md +16 -13
- data/doc/selenium-cucumber-API.md +81 -78
- data/doc/selenium-cucumber-help.md +18 -18
- 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 +33 -33
- data/lib/selenium-cucumber.rb +2 -2
- data/lib/selenium-cucumber/assertion_steps.rb +11 -4
- data/lib/selenium-cucumber/input_steps.rb +20 -24
- data/lib/selenium-cucumber/methods/assertion_methods.rb +19 -0
- data/lib/selenium-cucumber/methods/input_methods.rb +11 -4
- data/lib/selenium-cucumber/methods/navigate_methods.rb +29 -8
- data/lib/selenium-cucumber/navigation_steps.rb +11 -1
- data/lib/selenium-cucumber/version.rb +1 -1
- metadata +2 -3
- data/doc/selenium-cucumber-help.txt +0 -16
data/doc/installation.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
Installation
|
2
|
-
============
|
3
|
-
### Prerequisites
|
4
|
-
You need to have Ruby installed.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
Installation
|
2
|
+
============
|
3
|
+
### Prerequisites
|
4
|
+
You need to have Ruby installed.
|
5
|
+
Verify your installation by running ruby -v in a terminal - it should print "ruby 1.9.3" (or higher).
|
6
|
+
|
7
|
+
You need to have DevKit installed.
|
8
|
+
|
9
|
+
You can get Ruby and DevKit from [RubyInstaller.org](http://rubyinstaller.org/)
|
10
|
+
|
11
|
+
### Installation
|
12
|
+
|
13
|
+
Install `selenium-cucumber` gem by running
|
14
|
+
|
15
|
+
- `gem install selenium-cucumber`
|
16
|
+
|
@@ -1,79 +1,82 @@
|
|
1
|
-
selenium-cucumber API
|
2
|
-
=====================
|
3
|
-
|
4
|
-
If you are writing code for your custom steps you can use following methods
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
1
|
+
selenium-cucumber API
|
2
|
+
=====================
|
3
|
+
|
4
|
+
If you are writing code for your custom steps you can use the following methods :
|
5
|
+
|
6
|
+
Note : For some of the API paramtere values are fixed. Such values for paramaters are mentioned below.
|
7
|
+
|
8
|
+
Navigation API's
|
9
|
+
----------------
|
10
|
+
|
11
|
+
navigate_to(link)
|
12
|
+
|
13
|
+
navigate(direction) # direction => "back"/"forward"
|
14
|
+
|
15
|
+
close_driver()
|
16
|
+
|
17
|
+
|
18
|
+
Browser Interaction API's
|
19
|
+
-------------------------
|
20
|
+
|
21
|
+
resize_browser(width,height)
|
22
|
+
|
23
|
+
scroll_page(to) # to => "top"/"end"
|
24
|
+
|
25
|
+
scroll_to_element(by,access_value)
|
26
|
+
|
27
|
+
zoom_in_out(in_out) # in_out => "add"/"subtract"
|
28
|
+
|
29
|
+
zoom_in_out_till_element_display(by, in_out, access_value) # in_out => "add"/"subtract"
|
30
|
+
|
31
|
+
|
32
|
+
Input API's
|
33
|
+
------------
|
34
|
+
|
35
|
+
click(by,access_value)
|
36
|
+
|
37
|
+
submit(by,access_value)
|
38
|
+
|
39
|
+
enter_text(by,text,access_value)
|
40
|
+
|
41
|
+
clear_text(by,access_value)
|
42
|
+
|
43
|
+
check_checkbox(by, access_value)
|
44
|
+
|
45
|
+
uncheck_checkbox(by, access_value)
|
46
|
+
|
47
|
+
toggle_checkbox(by, access_value)
|
48
|
+
|
49
|
+
select_radio_button(by, access_value)
|
50
|
+
|
51
|
+
get_page_title()
|
52
|
+
|
53
|
+
get_element_text(by,access_value)
|
54
|
+
|
55
|
+
get_element_attribute(by,access_value,attribute)
|
56
|
+
|
57
|
+
is_element_enabled(by,access_value)
|
58
|
+
|
59
|
+
is_element_displayed(by,access_value)
|
60
|
+
|
61
|
+
|
62
|
+
Javascript Handling API
|
63
|
+
-----------------------
|
64
|
+
|
65
|
+
handle_alert(decision) # decision => "accept"/"dismiss"
|
66
|
+
|
67
|
+
get_alert_text
|
68
|
+
|
69
|
+
|
70
|
+
Progress API's
|
71
|
+
--------------
|
72
|
+
|
73
|
+
wait(time_in_sec)
|
74
|
+
|
75
|
+
wait_for_element_to_display(by,access_value,duration)
|
76
|
+
|
77
|
+
wait_for_element_to_enable(by,access_value,duration)
|
78
|
+
|
79
|
+
|
80
|
+
Screenshot API
|
81
|
+
--------------
|
79
82
|
take_screenshots
|
@@ -1,18 +1,18 @@
|
|
1
|
-
|
2
|
-
Usage: selenium-cucumber <command-name> [parameters] [options]
|
3
|
-
|
4
|
-
<command-name> can be one of
|
5
|
-
help
|
6
|
-
gen
|
7
|
-
version
|
8
|
-
|
9
|
-
Commands:
|
10
|
-
help : prints more detailed help information.
|
11
|
-
|
12
|
-
gen : creates a skeleton features dir. This is usually used once when
|
13
|
-
setting up selnium-cucumber to ensure that the features folder contains
|
14
|
-
the right step definitions and environment to run with cucumber.
|
15
|
-
|
16
|
-
version : prints the gem version
|
17
|
-
|
18
|
-
Options: -v, --verbose Turns on verbose logging
|
1
|
+
|
2
|
+
Usage: selenium-cucumber <command-name> [parameters] [options]
|
3
|
+
|
4
|
+
<command-name> can be one of
|
5
|
+
help
|
6
|
+
gen
|
7
|
+
version
|
8
|
+
|
9
|
+
Commands:
|
10
|
+
help : prints more detailed help information.
|
11
|
+
|
12
|
+
gen : creates a skeleton features dir. This is usually used once when
|
13
|
+
setting up selnium-cucumber to ensure that the features folder contains
|
14
|
+
the right step definitions and environment to run with cucumber.
|
15
|
+
|
16
|
+
version : prints the gem version
|
17
|
+
|
18
|
+
Options: -v, --verbose Turns on verbose logging
|
@@ -1,5 +1,5 @@
|
|
1
|
-
Feature: Login feature
|
2
|
-
|
3
|
-
Scenario: As a valid user I can log into my web app
|
4
|
-
When I press "Login"
|
5
|
-
Then I see "Welcome to coolest web app ever"
|
1
|
+
Feature: Login feature
|
2
|
+
|
3
|
+
Scenario: As a valid user I can log into my web app
|
4
|
+
When I press "Login"
|
5
|
+
Then I see "Welcome to coolest web app ever"
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'selenium-cucumber'
|
2
|
-
|
3
|
-
# Do Not Remove This File
|
4
|
-
# Add your custom steps here
|
1
|
+
require 'selenium-cucumber'
|
2
|
+
|
3
|
+
# Do Not Remove This File
|
4
|
+
# Add your custom steps here
|
5
5
|
# $driver is instance of webdriver use this instance to write your custom code
|
@@ -1,38 +1,38 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'selenium-webdriver'
|
3
|
-
|
4
|
-
def print_error
|
5
|
-
puts "\nInappropraite browser \"#{ENV['BROWSER']}\""
|
6
|
-
puts "\nUsage : cucumber BROWSER=browser_name"
|
7
|
-
puts "\nbrowser_name can be one of following :"
|
8
|
-
puts "1.ie\n2.chrome\n3.ff\n4.safari\n5.opera"
|
9
|
-
puts "\nNow using default browser \"Firefox\""
|
10
|
-
end
|
11
|
-
|
12
|
-
case ENV['BROWSER']
|
13
|
-
when 'ie'
|
14
|
-
browser_type = :ie
|
15
|
-
when 'ff'
|
16
|
-
browser_type = :ff
|
17
|
-
when 'chrome'
|
18
|
-
browser_type = :chrome
|
19
|
-
when 'opera'
|
20
|
-
browser_type = :opera
|
21
|
-
when 'safari'
|
22
|
-
browser_type = :safari
|
23
|
-
else
|
24
|
-
if ENV['BROWSER']
|
25
|
-
print_error
|
26
|
-
end
|
27
|
-
browser_type = :ff
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
begin
|
32
|
-
$driver = Selenium::WebDriver.for(browser_type)
|
33
|
-
$driver.manage().window().maximize()
|
34
|
-
|
35
|
-
rescue Exception => e
|
36
|
-
puts e.message
|
37
|
-
end
|
38
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'selenium-webdriver'
|
3
|
+
|
4
|
+
def print_error
|
5
|
+
puts "\nInappropraite browser \"#{ENV['BROWSER']}\""
|
6
|
+
puts "\nUsage : cucumber BROWSER=browser_name"
|
7
|
+
puts "\nbrowser_name can be one of following :"
|
8
|
+
puts "1.ie\n2.chrome\n3.ff\n4.safari\n5.opera"
|
9
|
+
puts "\nNow using default browser \"Firefox\""
|
10
|
+
end
|
11
|
+
|
12
|
+
case ENV['BROWSER']
|
13
|
+
when 'ie'
|
14
|
+
browser_type = :ie
|
15
|
+
when 'ff'
|
16
|
+
browser_type = :ff
|
17
|
+
when 'chrome'
|
18
|
+
browser_type = :chrome
|
19
|
+
when 'opera'
|
20
|
+
browser_type = :opera
|
21
|
+
when 'safari'
|
22
|
+
browser_type = :safari
|
23
|
+
else
|
24
|
+
if ENV['BROWSER']
|
25
|
+
print_error
|
26
|
+
end
|
27
|
+
browser_type = :ff
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
begin
|
32
|
+
$driver = Selenium::WebDriver.for(browser_type)
|
33
|
+
$driver.manage().window().maximize()
|
34
|
+
|
35
|
+
rescue Exception => e
|
36
|
+
puts e.message
|
37
|
+
end
|
38
|
+
|
@@ -1,34 +1,34 @@
|
|
1
|
-
#Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle
|
2
|
-
|
3
|
-
Before do
|
4
|
-
# Do something before each scenario.
|
5
|
-
end
|
6
|
-
|
7
|
-
Before do |scenario|
|
8
|
-
# The +scenario+ argument is optional, but if you use it, you can get the title,
|
9
|
-
# description, or name (title + description) of the scenario that is about to be
|
10
|
-
# executed.
|
11
|
-
end
|
12
|
-
|
13
|
-
After do |scenario|
|
14
|
-
# Do something after each scenario.
|
15
|
-
# The +scenario+ argument is optional, but
|
16
|
-
# if you use it, you can inspect status with
|
17
|
-
# the #failed?, #passed? and #exception methods.
|
18
|
-
|
19
|
-
if(scenario.failed?)
|
20
|
-
#Do something if scenario fails.
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
#Tagged hooks
|
25
|
-
|
26
|
-
Before('@Ex_tag1, @Ex_tag2') do
|
27
|
-
# This will only run before scenarios tagged
|
28
|
-
# with @cucumis OR @sativus.
|
29
|
-
end
|
30
|
-
|
31
|
-
AfterStep('@Ex_tag1, @Ex_tag2') do
|
32
|
-
# This will only run after steps within scenarios tagged
|
33
|
-
# with @cucumis AND @sativus.
|
1
|
+
#Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle
|
2
|
+
|
3
|
+
Before do
|
4
|
+
# Do something before each scenario.
|
5
|
+
end
|
6
|
+
|
7
|
+
Before do |scenario|
|
8
|
+
# The +scenario+ argument is optional, but if you use it, you can get the title,
|
9
|
+
# description, or name (title + description) of the scenario that is about to be
|
10
|
+
# executed.
|
11
|
+
end
|
12
|
+
|
13
|
+
After do |scenario|
|
14
|
+
# Do something after each scenario.
|
15
|
+
# The +scenario+ argument is optional, but
|
16
|
+
# if you use it, you can inspect status with
|
17
|
+
# the #failed?, #passed? and #exception methods.
|
18
|
+
|
19
|
+
if(scenario.failed?)
|
20
|
+
#Do something if scenario fails.
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#Tagged hooks
|
25
|
+
|
26
|
+
Before('@Ex_tag1, @Ex_tag2') do
|
27
|
+
# This will only run before scenarios tagged
|
28
|
+
# with @cucumis OR @sativus.
|
29
|
+
end
|
30
|
+
|
31
|
+
AfterStep('@Ex_tag1, @Ex_tag2') do
|
32
|
+
# This will only run after steps within scenarios tagged
|
33
|
+
# with @cucumis AND @sativus.
|
34
34
|
end
|
data/lib/selenium-cucumber.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
Dir[File.dirname(__FILE__) + '/selenium-cucumber/*.rb'].each {|file| require file }
|
1
|
+
|
2
|
+
Dir[File.dirname(__FILE__) + '/selenium-cucumber/*.rb'].each {|file| require file }
|
@@ -13,9 +13,9 @@ Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have text as "(.*?)"
|
|
13
13
|
end
|
14
14
|
|
15
15
|
#Step to check attribute value
|
16
|
-
Then(/^
|
16
|
+
Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have attribute "(.*?)" with value "(.*?)"$/) do |type, access_name, present, attrb, value|
|
17
17
|
validate_locator type
|
18
|
-
check_element_attribute(type,
|
18
|
+
check_element_attribute(type, attrb, value, access_name, present.empty?)
|
19
19
|
end
|
20
20
|
|
21
21
|
#Step to check element enabled or not
|
@@ -27,7 +27,7 @@ Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+be (enabled|disabled
|
|
27
27
|
end
|
28
28
|
|
29
29
|
#Step to check element present or not
|
30
|
-
Then(/^element having (.+) "(
|
30
|
+
Then(/^element having (.+) "(.*?)" should\s*((?:not)?)\s+be present$/) do |type, access_name, present|
|
31
31
|
validate_locator type
|
32
32
|
check_element_presence(type, access_name, present.empty?)
|
33
33
|
end
|
@@ -42,7 +42,7 @@ end
|
|
42
42
|
#steps to assert radio button checked or unchecked
|
43
43
|
Then(/^radio button having (.+) "(.*?)" should be (selected|unselected)$/) do |type, access_name, state|
|
44
44
|
validate_locator type
|
45
|
-
flag = state == "
|
45
|
+
flag = state == "selected"
|
46
46
|
is_radio_button_selected(type, access_name, flag)
|
47
47
|
end
|
48
48
|
|
@@ -66,4 +66,11 @@ end
|
|
66
66
|
|
67
67
|
Then(/^I should see alert text as "(.*?)"$/) do |actual_value|
|
68
68
|
check_alert_text(actual_value)
|
69
|
+
end
|
70
|
+
|
71
|
+
#Step tp assert dropdown list
|
72
|
+
Then(/^option "(.*?)" by (.+) from dropdown having (.+) "(.*?)" should be (selected|unselected)$/) do |option, by, type, access_name, state|
|
73
|
+
validate_locator type
|
74
|
+
flag = state == "selected"
|
75
|
+
is_option_from_dropdown_selected(type,by,option,access_name,state)
|
69
76
|
end
|
@@ -1,73 +1,69 @@
|
|
1
1
|
require_relative 'methods/input_methods'
|
2
2
|
|
3
3
|
#enter text into input field steps
|
4
|
-
|
5
4
|
Then(/^I enter "([^\"]*)" into input field having (.+) "([^\"]*)"$/) do |text, type, access_name|
|
6
5
|
validate_locator type
|
7
6
|
enter_text(type,text,access_name)
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
9
|
#clear input field steps
|
12
|
-
|
13
10
|
Then(/^I clear input field having (.+) "([^\"]*)"$/) do |type, access_name|
|
14
11
|
validate_locator type
|
15
12
|
clear_text(type, access_name)
|
16
13
|
end
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
Then(/^I select "(.*?)" option by (.+) from dropdown having (.+) "(.*?)"$/) do |option,option_by, type, access_name|
|
15
|
+
#select option by text/value from dropdown/multiselect
|
16
|
+
Then(/^I select "(.*?)" option by (.+) from\s*((?:multiselect)?)\sdropdown having (.+) "(.*?)"$/) do |option,option_by, present, type, access_name|
|
22
17
|
validate_locator type
|
23
18
|
validate_option_by option_by
|
24
19
|
select_option_from_dropdown(type, option_by,option,access_name)
|
25
20
|
end
|
26
21
|
|
22
|
+
#select option by index from dropdown/multiselect
|
23
|
+
Then(/^I select (\d+) option by index from\s*((?:multiselect)?)\sdropdown having (.+) "(.*?)"$/) do |option, present, type, access_name|
|
24
|
+
validate_locator type
|
25
|
+
select_option_from_dropdown(type, "index", (option.to_i)-1, access_name)
|
26
|
+
end
|
27
27
|
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
unselect_option_from_dropdown(type, access_name)
|
28
|
+
#step to select option from mutliselect dropdown list
|
29
|
+
Then(/^I select all options from multiselect dropdown having (.+) "(.*?)"$/) do |type, access_name|
|
30
|
+
validate_locator type
|
31
|
+
select_all_option_from_multiselect_dropdown(type, access_name)
|
33
32
|
end
|
34
33
|
|
34
|
+
#step to unselect option from mutliselect dropdown list
|
35
|
+
Then(/^I unselect all options from multiselect dropdown having (.+) "(.*?)"$/) do |type,access_name|
|
36
|
+
validate_locator type
|
37
|
+
unselect_all_option_from_multiselect_dropdown(type, access_name)
|
38
|
+
end
|
35
39
|
|
36
40
|
#check checkbox steps
|
37
|
-
|
38
|
-
Then(/^I check checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
41
|
+
Then(/^I check the checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
39
42
|
validate_locator type
|
40
43
|
check_checkbox(type, access_name)
|
41
44
|
end
|
42
45
|
|
43
46
|
#uncheck checkbox steps
|
44
|
-
|
45
|
-
Then(/^I uncheck checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
47
|
+
Then(/^I uncheck the checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
46
48
|
validate_locator type
|
47
49
|
uncheck_checkbox(type,access_name)
|
48
50
|
end
|
49
51
|
|
50
|
-
|
51
52
|
#Steps to toggle checkbox
|
52
|
-
|
53
53
|
Then(/^I toggle checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
54
54
|
validate_locator type
|
55
55
|
toggle_checkbox(type,access_name)
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
#radio button select step
|
60
|
-
|
58
|
+
#step to select radio button
|
61
59
|
Then(/^I select radio button having (.+) "(.*?)"$/) do |type,access_name|
|
62
60
|
validate_locator type
|
63
61
|
select_radio_button(type,access_name)
|
64
62
|
end
|
65
63
|
|
66
|
-
|
67
64
|
#steps to select option by text from radio button group
|
68
|
-
|
69
65
|
Then(/^I select "(.*?)" option by (.+) from radio button group having (.+) "(.*?)"$/) do |option,option_by, type, access_name|
|
70
66
|
validate_locator type
|
71
67
|
validate_option_by option_by
|
72
68
|
select_option_from_radio_button_group(type,option_by,option,access_name)
|
73
|
-
end
|
69
|
+
end
|