selenium-cucumber 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/generate.rb ADDED
@@ -0,0 +1,20 @@
1
+
2
+ def selenium_cucumber_scaffold
3
+ if File.exists?(@features_dir)
4
+ puts "A features directory already exists. Stopping..."
5
+ exit 1
6
+ end
7
+ msg("Question") do
8
+ puts "I'm about to create a subdirectory called features."
9
+ puts "features will contain all your project tests."
10
+ puts "Please hit return to confirm that's what you want."
11
+ end
12
+ exit 2 unless STDIN.gets.chomp == ''
13
+
14
+ FileUtils.cp_r(@source_dir, @features_dir)
15
+
16
+ msg("Info") do
17
+ puts "features subdirectory created. \n"
18
+ end
19
+
20
+ end
data/bin/helper.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'tempfile'
2
+ require 'json'
3
+ require "rubygems"
4
+
5
+ def msg(title, &block)
6
+ puts "\n" + "-"*10 + title + "-"*10
7
+ block.call
8
+ puts "-"*10 + "-------" + "-"*10 + "\n"
9
+ end
10
+
11
+ def print_usage
12
+ puts <<EOF
13
+
14
+ Usage: selenium-cucumber <command-name> [parameters] [options]
15
+
16
+ <command-name> can be one of
17
+ help
18
+ prints more detailed help information.
19
+ gen
20
+ generate a features folder structure.
21
+ version
22
+ prints the gem version
23
+
24
+ <options> can be
25
+ -v, --verbose Turns on verbose logging
26
+ EOF
27
+ end
28
+
29
+ def print_help
30
+ puts <<EOF
31
+
32
+ Usage: selenium-cucumber <command-name> [parameters] [options]
33
+
34
+ <command-name> can be one of
35
+ help
36
+ gen
37
+ version
38
+
39
+ Commands:
40
+ help : prints more detailed help information.
41
+
42
+ gen : creates a skeleton features dir. This is usually used once when
43
+ setting up selnium-cucumber to ensure that the features folder contains
44
+ the right step definitions and environment to run with cucumber.
45
+
46
+ version : prints the gem version
47
+
48
+ <Options>
49
+ -v, --verbose Turns on verbose logging
50
+ EOF
51
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'helper.rb'
4
+ require_relative 'generate.rb'
5
+ require 'selenium-cucumber/version'
6
+
7
+ @features_dir = File.join(FileUtils.pwd, "features")
8
+ @support_dir = File.join(@features_dir, "support")
9
+ @source_dir = File.join(File.dirname(__FILE__), '..', 'features-skeleton')
10
+
11
+ if (ARGV.length == 0)
12
+ print_usage
13
+ end
14
+
15
+ cmd = ARGV.shift
16
+
17
+ if cmd == 'help'
18
+ print_help
19
+ elsif cmd == 'gen'
20
+ selenium_cucumber_scaffold
21
+ elsif cmd == 'version'
22
+ puts Selenium::Cucumber::VERSION
23
+ end
@@ -0,0 +1,76 @@
1
+ Canned Steps
2
+ ============
3
+ selenium-cucumber comes with the following set of predefined steps.
4
+ You can add your own steps or change the ones you see here.
5
+
6
+ Assertion Steps
7
+ ---------------
8
+ To assert that page title can be found use following step.
9
+
10
+ Then(/^I see page title as "(.*?)"$/)
11
+
12
+ To assert that value of element can be found use any of the following steps.
13
+
14
+ Then /^I should see element value as "([^\"]*)" where element id is "([^\"]*)"$/
15
+ Then /^I should see element value as "([^\"]*)" where element name is "([^\"]*)"$/
16
+ Then /^I should see element value as "([^\"]*)" where element xpath is "([^\"]*)"$/
17
+
18
+
19
+ To assert that value of element cannot be found use any of the following steps.
20
+
21
+ Then /^I should not see element value as "([^\"]*)" where element id is "([^\"]*)"$/
22
+ Then /^I should not see element value as "([^\"]*)" where element name is "([^\"]*)"$/
23
+ Then /^I should not see element value as "([^\"]*)" where element xpath is "([^\"]*)"$/
24
+
25
+
26
+ To assert that element is enabled use any of the following steps.
27
+
28
+ Then /^element with id "([^\"]*)" should enable$/
29
+ Then /^element with name "([^\"]*)" should enable$/
30
+ Then /^element with xpath "([^\"]*)" should enable$/
31
+
32
+ To assert that element is disabled use any of the following steps.
33
+
34
+ Then /^element with id "([^\"]*)" should disable$/
35
+ Then /^element with name "([^\"]*)" should disable$/
36
+ Then /^element with xpath "([^\"]*)" should disable$/
37
+
38
+ Input Steps
39
+ -----------
40
+ To enter text into input field use following steps
41
+
42
+ Then /^I enter "([^\"]*)" into input field with id "([^\"]*)"$/
43
+ Then /^I enter "([^\"]*)" into input field with name "([^\"]*)"$/
44
+ Then /^I enter "([^\"]*)" into input field with xpath "([^\"]*)"$/
45
+
46
+ To clear input field use following steps
47
+
48
+ Then /^I clear input field with id "([^\"]*)"$/
49
+ Then /^I clear input field with name "([^\"]*)"$/
50
+ Then /^I clear input field with xpath "([^\"]*)"$/
51
+
52
+ Navigation Steps
53
+ ----------------
54
+
55
+ Then(/^I navigate to "([^\"]*)"$/)
56
+ Then(/^I close browser$/)
57
+
58
+ Click Steps
59
+ -----------
60
+
61
+ Then(/^I click on element with id "(.*?)"$/)
62
+ Then(/^I click on element with name "(.*?)"$/)
63
+ Then(/^I click on element with xpath "(.*?)"$/)
64
+
65
+ Progress Steps
66
+ --------------
67
+
68
+ Then(/^I wait for (\d+) sec$/)
69
+ Then(/^I wait "(.*?)" second for element having id "(.*?)"$/)
70
+ Then(/^I wait "(.*?)" second for element having name "(.*?)"$/)
71
+ Then(/^I wait "(.*?)" second for element having xpath "(.*?)"$/)
72
+
73
+ Screenshot Steps
74
+ ----------------
75
+
76
+ Then(/^I take screenshot$/)
@@ -0,0 +1,13 @@
1
+ Installation
2
+ ============
3
+ ### Prerequisites
4
+ You need to have Ruby installed. Verify your installation by running ruby -v in a terminal - it should print "ruby 1.8.7" (or higher).
5
+
6
+ If you are on Windows you can get Ruby from [RubyInstaller.org](http://rubyinstaller.org/)
7
+
8
+ ### Installation
9
+
10
+ Install `selenium-cucumber` by running
11
+
12
+ - `gem install selenium-cucumber`
13
+ - You might have to run `sudo gem install selenium-cucumber` if you do not have the right permissions.
@@ -0,0 +1,16 @@
1
+ Usage: selenium-cucumber <command-name> [parameters] [options]
2
+ <command-name> can be one of
3
+ help
4
+ gen
5
+ version
6
+
7
+ Commands:
8
+ help : prints more detailed help information.
9
+
10
+ gen : creates a skeleton features dir. This is usually used once when
11
+ setting up selnium-cucumber to ensure that the features folder contains
12
+ the right step definitions and environment to run with cucumber.
13
+
14
+ version : prints the gem version
15
+
16
+ Options: -v, --verbose Turns on verbose logging
@@ -0,0 +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"
@@ -0,0 +1,4 @@
1
+ require 'selenium-cucumber'
2
+
3
+ # Do Not Remove This File
4
+ # Add your custom steps here
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'selenium-webdriver'
3
+
4
+ $BASE_URL = ENV["URL"] || "ff"
5
+
6
+ case ENV['BROWSER']
7
+ when 'ie'
8
+ browser_type = :ie
9
+ when 'ff'
10
+ browser_type = :ff
11
+ when 'chrome'
12
+ browser_type = :chrome
13
+ when 'opera'
14
+ browser_type = :opera
15
+ else
16
+ browser_type = :ff
17
+ end
18
+
19
+ browser = Selenium::WebDriver.for(browser_type)
20
+ #puts browser_type.to_s
21
+ Before do
22
+ $driver = browser
23
+ $driver.manage().window().maximize()
24
+ # $driver.get $BASE_URL
25
+ end
26
+
27
+ at_exit() do
28
+ $driver.close
29
+ end
@@ -0,0 +1,58 @@
1
+ require_relative 'methods/assertion_methods'
2
+
3
+ #Page title checking
4
+ Then(/^I see page title as "(.*?)"$/) do |title|
5
+ check_title(title)
6
+ end
7
+
8
+ #Element Value checking - Positive Case
9
+ Then /^I should see element value as "([^\"]*)" where element id is "([^\"]*)"$/ do |element_value, element_id|
10
+ check_element_value("id",element_value,element_id,true)
11
+ end
12
+
13
+ Then /^I should see element value as "([^\"]*)" where element name is "([^\"]*)"$/ do |element_value, element_name|
14
+ check_element_value("name",element_value,element_name,true)
15
+ end
16
+
17
+ Then /^I should see element value as "([^\"]*)" where element xpath is "([^\"]*)"$/ do |element_value, element_xpath|
18
+ check_element_value("xpath",element_value,element_xpath,true)
19
+ end
20
+
21
+ #Element Value checking - Negative Case
22
+ Then /^I should not see element value as "([^\"]*)" where element id is "([^\"]*)"$/ do |element_value, element_id|
23
+ check_element_value("id",element_value,element_id,false)
24
+ end
25
+
26
+ Then /^I should not see element value as "([^\"]*)" where element name is "([^\"]*)"$/ do |element_value, element_name|
27
+ check_element_value("name",element_value,element_name,false)
28
+ end
29
+
30
+ Then /^I should not see element value as "([^\"]*)" where element xpath is "([^\"]*)"$/ do |element_value, element_xpath|
31
+ check_element_value("xpath",element_value,element_xpath,false)
32
+ end
33
+
34
+ #Element enabled checking - Positive Case
35
+ Then /^element with id "([^\"]*)" should enable$/ do |element_id|
36
+ check_element_enable("id", element_id, true)
37
+ end
38
+
39
+ Then /^element with name "([^\"]*)" should enable$/ do |element_name|
40
+ check_element_enable("name", element_name, true)
41
+ end
42
+
43
+ Then /^element with xpath "([^\"]*)" should enable$/ do |element_xpath|
44
+ check_element_enable("xpath", element_xpath, true)
45
+ end
46
+
47
+ #Element disabled checking - Positive Case
48
+ Then /^element with id "([^\"]*)" should disable$/ do |element_id|
49
+ check_element_enable("id", element_id, false)
50
+ end
51
+
52
+ Then /^element with name "([^\"]*)" should disable$/ do |element_name|
53
+ check_element_enable("name", element_name, false)
54
+ end
55
+
56
+ Then /^element with xpath "([^\"]*)" should disable$/ do |element_xpath|
57
+ check_element_enable("xpath", element_xpath, false)
58
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'methods/enter_text_methods'
2
+
3
+ #input field
4
+ Then /^I enter "([^\"]*)" into input field with id "([^\"]*)"$/ do |text, id|
5
+ enter_text("id",text,id)
6
+ end
7
+
8
+ Then /^I enter "([^\"]*)" into input field with name "([^\"]*)"$/ do |text, name|
9
+ enter_text("name",text,name)
10
+ end
11
+
12
+ Then /^I enter "([^\"]*)" into input field with xpath "([^\"]*)"$/ do |text, xpath|
13
+ enter_text("xpath",text,xpath)
14
+ end
15
+
16
+ Then /^I clear input field with id "([^\"]*)"$/ do |id|
17
+ clear_text("id",id)
18
+ end
19
+
20
+ Then /^I clear input field with name "([^\"]*)"$/ do |name|
21
+ clear_text("name",name)
22
+ end
23
+
24
+ Then /^I clear input field with xpath "([^\"]*)"$/ do |xpath|
25
+ clear_text("xpath",xpath)
26
+ end
27
+
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require "selenium-webdriver"
3
+
4
+ #Page title checking
5
+ def check_title(title)
6
+ if($driver.title!=title)
7
+ raise "Page Title Not Matched"
8
+ end
9
+ end
10
+
11
+ #Element Value checking
12
+ def check_element_value(access_type, actual_value, access_name, test_case)
13
+ if test_case
14
+ if($driver.find_element(:"#{access_type}" => "#{access_name}").attribute("value")!=actual_value)
15
+ raise "Value Not Matched"
16
+ end
17
+ else
18
+ if($driver.find_element(:"#{access_type}" => "#{access_name}").attribute("value")==actual_value)
19
+ raise "Value Matched"
20
+ end
21
+ end
22
+ end
23
+
24
+ #Element enabled checking
25
+ def check_element_enable(access_type, access_name, test_case)
26
+ if test_case
27
+ if(!$driver.find_element(:"#{access_type}" => "#{access_name}").enabled?)
28
+ raise "Element not enabled"
29
+ end
30
+ else
31
+ if($driver.find_element(:"#{access_type}" => "#{access_name}").enabled?)
32
+ raise "Element enabled"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require "selenium-webdriver"
3
+
4
+
5
+ def enter_text(access_type,text,access_name)
6
+ element = $driver.find_element(:"#{access_type}" => "#{access_name}").send_keys text
7
+ end
8
+
9
+ def clear_text(access_type,access_name)
10
+ element = $driver.find_element(:"#{access_type}" => "#{access_name}").clear
11
+ end
12
+
13
+
14
+
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require "selenium-webdriver"
3
+
4
+
5
+ def navigate_to(link)
6
+ $driver.get link
7
+ end
8
+
9
+ def close_driver
10
+ $driver.quit
11
+ end
@@ -0,0 +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
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require "selenium-webdriver"
3
+
4
+ def wait_for_element(access_type,access_id)
5
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
6
+ element = wait.until { $driver.find_element(:"#{access_type}" => "#{access_id}") }
7
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'methods/navigate_methods'
2
+
3
+ Then(/^I navigate to "([^\"]*)"$/)do |link|
4
+ navigate_to(link)
5
+ end
6
+
7
+ Then(/^I close browser$/) do
8
+ close_driver
9
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'methods/press_button_methods'
2
+
3
+ When(/^I click on element with id "(.*?)"$/) do |element_id|
4
+ click("id",element_id)
5
+ end
6
+
7
+ When(/^I click on element with name "(.*?)"$/) do |element_name|
8
+ click("name",element_name)
9
+ end
10
+
11
+ When(/^I click on element with xpath "(.*?)"$/) do |element_xpath|
12
+ click("xpath",element_xpath)
13
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'methods/progress_methods'
2
+
3
+ Then(/^I wait for (\d+) sec$/) do |time|
4
+ sleep time.to_i
5
+ end
6
+
7
+ Then(/^I wait "(.*?)" second for element having id "(.*?)"$/) do |duration, id|
8
+ wait_for_element("id",id,duration)
9
+ end
10
+
11
+ Then(/^I wait "(.*?)" second for element having name "(.*?)"$/) do |duration, name|
12
+ wait_for_element("name",name,duration)
13
+ end
14
+
15
+ Then(/^I wait "(.*?)" second for element having xpath "(.*?)"$/) do |duration, xpath|
16
+ wait_for_element("xpath",xpath,duration)
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require "selenium-webdriver"
3
+
4
+
5
+ Then(/^I take screenshot$/) do
6
+ curTime = Time.now.strftime('%Y%m%d%H%M%S%L')
7
+ $driver.save_screenshot('./screenshot'+curTime+'.png')
8
+ end
@@ -0,0 +1,5 @@
1
+ module Selenium
2
+ module Cucumber
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+
2
+ require 'selenium-cucumber/assertion_steps'
3
+ require 'selenium-cucumber/enter_text_steps'
4
+ require 'selenium-cucumber/navigation_steps'
5
+ require 'selenium-cucumber/press_button_steps'
6
+ require 'selenium-cucumber/progress_step'
7
+ require 'selenium-cucumber/screenshot_step'
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium-cucumber
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sameer Sawant
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cucumber
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: selenium-webdriver
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A BDD approch to write automated test script for testing web application.
47
+ email: sameersawant1992@gmail.com
48
+ executables:
49
+ - selenium-cucumber
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/selenium-cucumber.rb
54
+ - lib/selenium-cucumber/assertion_steps.rb
55
+ - lib/selenium-cucumber/enter_text_steps.rb
56
+ - lib/selenium-cucumber/navigation_steps.rb
57
+ - lib/selenium-cucumber/press_button_steps.rb
58
+ - lib/selenium-cucumber/progress_step.rb
59
+ - lib/selenium-cucumber/screenshot_step.rb
60
+ - lib/selenium-cucumber/version.rb
61
+ - lib/selenium-cucumber/methods/assertion_methods.rb
62
+ - lib/selenium-cucumber/methods/enter_text_methods.rb
63
+ - lib/selenium-cucumber/methods/navigate_methods.rb
64
+ - lib/selenium-cucumber/methods/press_button_methods.rb
65
+ - lib/selenium-cucumber/methods/progress_methods.rb
66
+ - bin/generate.rb
67
+ - bin/helper.rb
68
+ - features-skeleton/my_first.feature
69
+ - features-skeleton/step_definitions/custom_steps.rb
70
+ - features-skeleton/support/env.rb
71
+ - doc/canned_steps.md
72
+ - doc/installation.md
73
+ - doc/selenium-cucumber-help.txt
74
+ - bin/selenium-cucumber
75
+ homepage: http://sameersawant1992.wordpress.com/
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.28
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: SELENIUM WEBDRIVER 2.0 WITH RUBY & CUCUMBER
99
+ test_files: []