selenium_fury 0.5.12 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.rvmrc +2 -7
  2. data/Gemfile +1 -1
  3. data/VERSION +1 -1
  4. data/features/custom_generator.feature +1 -1
  5. data/features/generate_page_object.feature +1 -1
  6. data/features/step_definitions/custom_generator_steps.rb +81 -125
  7. data/features/step_definitions/generate_page_object_steps.rb +3 -3
  8. data/features/step_definitions/validate_page_object_steps.rb +4 -4
  9. data/features/support/env.rb +10 -4
  10. data/features/support/hooks.rb +2 -1
  11. data/features/validate_page_object.feature +3 -3
  12. data/lib/selenium_fury.rb +3 -4
  13. data/lib/selenium_fury/common/selenium_api_chooser.rb +19 -7
  14. data/lib/selenium_fury/selenium_client/locator_finder.rb +15 -0
  15. data/lib/selenium_fury/selenium_client/page_generator.rb +1 -0
  16. data/lib/selenium_fury/selenium_client/page_validator.rb +12 -37
  17. data/lib/selenium_fury/selenium_web_driver/element_finder.rb +16 -1
  18. data/lib/selenium_fury/selenium_web_driver/page_object.rb +2 -2
  19. data/lib/selenium_fury/selenium_web_driver/page_object_components.rb +1 -1
  20. data/spec/common/selenium_api_chooser_spec.rb +11 -11
  21. data/spec/selenium_client/custom_generators_spec.rb +23 -7
  22. data/spec/selenium_client/page_generator_spec.rb +3 -3
  23. data/spec/selenium_client/page_validator_spec.rb +5 -5
  24. data/spec/selenium_client/test_page_rc_spec.rb +14 -0
  25. data/spec/selenium_web_driver/element_finder_spec.rb +1 -1
  26. data/spec/selenium_web_driver/page_generator_spec.rb +10 -10
  27. data/spec/selenium_web_driver/page_object_spec.rb +69 -40
  28. data/spec/selenium_web_driver/page_validator_spec.rb +5 -5
  29. data/spec/spec_helper.rb +13 -12
  30. data/spec/test_page/test_page.html +70 -0
  31. data/spec/test_page/test_page.rb +21 -0
  32. data/spec/test_page/test_page_custom_generator_configuration.rb +16 -0
  33. data/spec/test_page/test_page_rc.rb +25 -0
  34. metadata +194 -181
  35. data/selenium_fury.gemspec +0 -118
  36. data/spec/selenium_client/advanced_search.rb +0 -55
  37. data/spec/selenium_client/advanced_search_custom_generator_configuration.rb +0 -16
  38. data/spec/selenium_client/advanced_search_spec.rb +0 -15
  39. data/spec/selenium_web_driver/advanced_search.rb +0 -47
  40. data/spec/selenium_web_driver/inquiry_side_bar.rb +0 -7
  41. data/spec/selenium_web_driver/property_page.rb +0 -3
data/.rvmrc CHANGED
@@ -1,8 +1,4 @@
1
- rvm_install_on_use_flag=1
2
- rvm_gemset_create_on_use_flag=1
3
- rvm_project_rvmrc_default=1
4
- rvm ruby-1.8.7-p334@selenium_fury
5
-
1
+ rvm use 1.9.3@selenium_fury --create
6
2
  # Ensure that Bundler is installed, install it if it is not.
7
3
  if ! command -v bundle ; then
8
4
  printf "The rubygem 'bundler' is not installed, installing it now.\n"
@@ -10,6 +6,5 @@ if ! command -v bundle ; then
10
6
  fi
11
7
 
12
8
  # Bundle while redcing excess noise.
13
- printf "Bundling your gems this may take a few minutes on a fresh clone.\n"
14
- bundle | grep -v 'Using' | grep -v 'complete' | sed '/^$/d'
9
+ bundle | grep -vP '^Using(?!.*from source)'
15
10
 
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ group :development do
7
7
  gem 'yard'
8
8
  gem 'jeweler'
9
9
  gem 'rdiscount'
10
- gem "rspec","2.7.0"
10
+ gem "rspec"
11
11
  gem "cucumber"
12
12
  gem "bundler"
13
13
  gem "builder"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.12
1
+ 0.6.0
@@ -2,7 +2,7 @@ Feature: Custom Generator
2
2
  As an automated tester I want to create a page object with variable names that reflect business terms so the our test will reflect ubiquitous language.
3
3
 
4
4
  Scenario: Use a custom generator configuration object to specify how to name our variables from another source than the id
5
- Given I am on the advanced search page for HomeAway
5
+ Given I am on the test page
6
6
  When I have a custom generator configuration class
7
7
  And I run the custom generator
8
8
  Then I will have a ruby class produced that I can use as a page object
@@ -3,6 +3,6 @@ Feature: Generator
3
3
 
4
4
 
5
5
  Scenario: The generator produces a ruby class on standard out that reflects the ids of page elements that can be used as a page object.
6
- Given I am on the advanced search page for HomeAway
6
+ Given I am on the test page
7
7
  When I run the generator
8
8
  Then I will have a ruby class produced that I can use as a page object
@@ -1,14 +1,14 @@
1
1
  When /^I have a custom generator configuration class$/ do
2
- @advanced_search_custom_generator_configuration = AdvancedSearchCustomGeneratorConfiguration.new()
3
- @advanced_search_custom_generator_configuration.should_not be_nil
2
+ @test_page_custom_generator_configuration = TestPageCustomGeneratorConfiguration.new()
3
+ @test_page_custom_generator_configuration.should_not be_nil
4
4
  end
5
5
  When /^I run the custom generator$/ do
6
6
  @found_element_ids=custom_generator(:browser => browser,
7
- :custom_configuration => @advanced_search_custom_generator_configuration)
7
+ :custom_configuration => @test_page_custom_generator_configuration)
8
8
 
9
9
  end
10
10
  When /^I specify a selector attribute$/ do
11
- @advanced_search_custom_generator_configuration.selector.should_not be_nil
11
+ @test_page_custom_generator_configuration.selector.should_not be_nil
12
12
 
13
13
  end
14
14
  When /^I create a nokogiri document for the test page$/ do
@@ -18,143 +18,99 @@ When /^I create a nokogiri document for the test page$/ do
18
18
  end
19
19
 
20
20
  Then /^I should get a nokogiri node set that I can iterate over to find a name and value for my page object locators$/ do
21
- @check_box_nokogiri_elements = @doc.css(@advanced_search_custom_generator_configuration.selector)
21
+ @check_box_nokogiri_elements = @doc.css(@test_page_custom_generator_configuration.selector)
22
22
  @check_box_nokogiri_elements.class.to_s.should == "Nokogiri::XML::NodeSet"
23
23
  @check_box_nokogiri_elements.each do |nokogiri_element|
24
24
  nokogiri_element.class.to_s.should == "Nokogiri::XML::Element"
25
25
  end
26
26
  end
27
27
  When /^I call the name method on the custom generator configuration class$/ do
28
- @advanced_search_custom_generator_configuration.nokogiri_element=@check_box_nokogiri_elements.last
29
- @advanced_search_custom_generator_configuration.nokogiri_element=@check_box_nokogiri_elements.last
30
- @locator_name = @advanced_search_custom_generator_configuration.name
28
+ @test_page_custom_generator_configuration.nokogiri_element=@check_box_nokogiri_elements.last
29
+ @test_page_custom_generator_configuration.nokogiri_element=@check_box_nokogiri_elements.last
30
+ @locator_name = @test_page_custom_generator_configuration.name
31
31
  end
32
32
  Then /^I should get the raw string to name my page object attribute$/ do
33
33
  @locator_name.should_not be_nil
34
- @locator_name.should == "downtown"
34
+ @locator_name.should == "Link 3"
35
35
  end
36
36
  When /^I call the value method on the custom generator configuration class$/ do
37
- @locator_value = @advanced_search_custom_generator_configuration.value
37
+ @locator_value = @test_page_custom_generator_configuration.value
38
38
  end
39
39
  Then /^I should get a value that I can use as a selenium locator$/ do
40
40
  @locator_value.should_not be_nil
41
- @locator_value.should == "location2.2"
41
+ @locator_value.should == "link333333"
42
42
  end
43
43
 
44
44
 
45
45
  ADVANCED_SEARCH_HTML=<<EOF
46
- <form id=adv-search-form>
47
- <div class="fieldset">
48
- <div class="columns">
49
- <div class="column">
50
- <div class="cb-box">
51
- <input class="checkbox" type="checkbox" id="suitability0.0" name="refinements" value="Suitability:children welcome">
52
- <label for="suitability0.0">children welcome</label>
53
- </div>
54
- </div>
55
- <div class="column">
56
- <div class="cb-box">
57
- <input class="checkbox" type="checkbox" id="suitability0.1" name="refinements" value="Suitability:wheelchair accessible">
58
- <label for="suitability0.1">wheelchair accessible</label>
59
- </div>
60
- </div>
61
- <div class="column">
62
- <div class="cb-box">
63
- <input class="checkbox" type="checkbox" id="suitability1.0" name="refinements" value="Suitability:suitable for elderly or infirm">
64
- <label for="suitability1.0">suitable for elderly or infirm</label>
65
- </div>
66
- </div>
67
- <div class="column">
68
- <div class="cb-box">
69
- <input class="checkbox" type="checkbox" id="suitability1.1" name="refinements" value="Suitability:pets considered">
70
- <label for="suitability1.1">pet friendly</label>
71
- </div>
72
- </div>
73
- <div class="column">
74
- <div class="cb-box">
75
- <input class="checkbox" type="checkbox" id="suitability2.0" name="refinements" value="Suitability:non smoking only">
76
- <label for="suitability2.0">non smoking only</label>
77
- </div>
78
- </div>
79
- <div class="column">
80
- <div class="cb-box">
81
- <input class="checkbox" type="checkbox" id="suitability2.1" name="refinements" value="Suitability:long term renters welcome">
82
- <label for="suitability2.1">long term renters welcome</label>
83
- </div>
84
- </div>
85
- <div class="clear"></div>
86
- </div>
87
- </div>
88
- <div class="fieldset">
89
- <div class="columns">
90
- <div class="column">
91
- <div class="cb-box">
92
- <input class="checkbox" type="checkbox" id="location0.0" name="refinements" value="Location Type:beach">
93
- <label for="location0.0">beach</label>
94
- </div>
95
- </div>
96
- <div class="column">
97
- <div class="cb-box">
98
- <input class="checkbox" type="checkbox" id="location0.1" name="refinements" value="Location Type:lake">
99
- <label for="location0.1">lake</label>
100
- </div>
101
- </div>
102
- <div class="column">
103
- <div class="cb-box">
104
- <input class="checkbox" type="checkbox" id="location0.2" name="refinements" value="Location Type:waterfront">
105
- <label for="location0.2">waterfront</label>
106
- </div>
107
- </div>
108
- <div class="column">
109
- <div class="cb-box">
110
- <input class="checkbox" type="checkbox" id="location0.3" name="refinements" value="Location Type:mountain">
111
- <label for="location0.3">mountain</label>
112
- </div>
113
- </div>
114
- <div class="column">
115
- <div class="cb-box">
116
- <input class="checkbox" type="checkbox" id="location1.0" name="refinements" value="Location Type:near the ocean">
117
- <label for="location1.0">near the ocean</label>
118
- </div>
119
- </div>
120
- <div class="column">
121
- <div class="cb-box">
122
- <input class="checkbox" type="checkbox" id="location1.1" name="refinements" value="Location Type:resort">
123
- <label for="location1.1">resort</label>
124
- </div>
125
- </div>
126
- <div class="column">
127
- <div class="cb-box">
128
- <input class="checkbox" type="checkbox" id="location1.2" name="refinements" value="Location Type:rural">
129
- <label for="location1.2">rural</label>
130
- </div>
131
- </div>
132
- <div class="column">
133
- <div class="cb-box">
134
- <input class="checkbox" type="checkbox" id="location1.3" name="refinements" value="Location Type:town">
135
- <label for="location1.3">town</label>
136
- </div>
137
- </div>
138
- <div class="column">
139
- <div class="cb-box">
140
- <input class="checkbox" type="checkbox" id="location2.0" name="refinements" value="Location Type:village">
141
- <label for="location2.0">village</label>
142
- </div>
143
- </div>
144
- <div class="column">
145
- <div class="cb-box">
146
- <input class="checkbox" type="checkbox" id="location2.1" name="refinements" value="Location Type:river">
147
- <label for="location2.1">river</label>
148
- </div>
149
- </div>
150
- <div class="column">
151
- <div class="cb-box">
152
- <input class="checkbox" type="checkbox" id="location2.2" name="refinements" value="Location Type:downtown">
153
- <label for="location2.2">downtown</label>
154
- </div>
155
- </div>
156
- <div class="clear"></div>
157
- </div>
158
- </div>
159
- <form>
46
+ <!doctype html>
47
+ <html lang="en">
48
+ <head>
49
+ <meta charset="utf-8">
50
+ <title>SeleniumFury Test Page</title>
51
+ <script type="text/javascript">
52
+ function displayMessage() {
53
+ document.getElementById('message').innerHTML = document.form.msgtext.value
54
+ }
55
+ </script>
56
+ </head>
57
+ <body>
58
+
59
+ <div id="message"></div>
60
+
61
+ <form id="form" name="form">
62
+ <label for="textarea">Textarea</label>
63
+ <textarea id="textarea">This is a textarea field.
64
+ </textarea>
65
+ <br/>
66
+ <label for="select">Select</label>
67
+ <select id="select">
68
+ <option value="volvo">Volvo</option>
69
+ <option value="saab">Saab</option>
70
+ <option value="mercedes">Mercedes</option>
71
+ <option value="audi">Audi</option>
72
+ </select>
73
+ <br/>
74
+ <label for="input_button">Button</label>
75
+ <input id="input_button" type="button" value="Click me"/>
76
+ <br/>
77
+ <label for="input_checkbox">Checkbox</label>
78
+ <input id="input_checkbox" type="checkbox"/>
79
+ <br/>
80
+ <label for="input_file">File</label>
81
+ <input id="input_file" type="file"/>
82
+ <br/>
83
+ <input id="input_hidden" type="hidden"/>
84
+ <br/>
85
+ <label for="input_image">Image</label>
86
+ <input id="input_image" type="image" alt="input image"/>
87
+ <br/>
88
+ <label for="input_password">Password</label>
89
+ <input id="input_password" type="password"/>
90
+ <br/>
91
+ <label for="input_radio">Radio</label>
92
+ <input id="input_radio" type="radio"/>
93
+ <br/>
94
+ <label for="input_reset">Reset</label>
95
+ <input id="input_reset" type="reset"/>
96
+ <br/>
97
+ <label for="input_submit">Submit</label>
98
+ <input id="input_submit" type="submit"/>
99
+ <br/>
100
+ <label for="input_text">Text</label>
101
+ <input id="input_text" type="text"/>
102
+ <br/>
103
+ <fieldset>
104
+ <legend>Input test:</legend>
105
+ <label for="input_message">Message Text:</label>
106
+ <input id="input_message" name="msgtext" type="text" />
107
+ <br/>
108
+ <input id="input_msg_button" type="button" value="Click me" onClick="displayMessage()"/>
109
+ </fieldset>
110
+ </form>
111
+ <a id="link111111" href="http://news.ycombinator.com/">Link 1</a>
112
+ <a id="link222222" href="http://yahoo.com">Link 2</a>
113
+ <a id="link333333" href="http://google.com">Link 3</a>
114
+ </body>
115
+ </html>
160
116
  EOF
@@ -1,8 +1,8 @@
1
- Given /^I am on the advanced search page for HomeAway$/ do
2
- create_selenium_driver("http://www.homeaway.com")
1
+ Given /^I am on the test page$/ do
2
+ create_selenium_driver TEST_PAGE_URL
3
3
  browser.start_new_browser_session
4
4
  puts "Testing #{browser.browser_url} on #{browser.browser_string} "
5
- browser.open "/searchForm"
5
+ browser.open TEST_PAGE_URL
6
6
  end
7
7
 
8
8
  When /^I run the generator$/ do
@@ -1,11 +1,11 @@
1
1
  When /^I run the validator$/ do
2
- validate(AdvancedSearch, "/searchForm")
2
+ validate(TestPageRc, TEST_PAGE_URL)
3
3
  end
4
- Then /^the advanced search page object locators will be checked$/ do
4
+ Then /^the test page object locators will be checked$/ do
5
5
  @found_missing_locators.should have(0).elements
6
6
  end
7
7
  When /^I run the validator with missing locators$/ do
8
- class AdvancedSearchBroken < AdvancedSearch
8
+ class TestPageRcBroken < TestPageRc
9
9
  def initialize *browser
10
10
  super
11
11
  @missing_locator_attribute="missing_locator"
@@ -14,7 +14,7 @@ When /^I run the validator with missing locators$/ do
14
14
  attr_reader :missing_locator_attribute
15
15
  end
16
16
  begin
17
- check_page_file_class(AdvancedSearchBroken, "/searchForm")
17
+ check_page_file_class(TestPageRcBroken,TEST_PAGE_URL)
18
18
  rescue Exception=>e
19
19
  end
20
20
  end
@@ -1,7 +1,13 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
- $:.unshift(File.dirname(__FILE__))
3
2
  require 'rubygems'
4
- require 'bundler/setup'
3
+ require 'bundler'
4
+
5
5
  require 'selenium_fury'
6
- require 'rspec'
7
- require 'spec_helper'
6
+
7
+
8
+ require_relative "../../spec/test_page/test_page_rc"
9
+ require_relative "../../spec/test_page/test_page_custom_generator_configuration"
10
+
11
+ TEST_PAGE_URL="file://"+ File.expand_path(File.dirname(__FILE__) + "/../../spec/test_page/test_page.html")
12
+ include SeleniumFury::SeleniumWebDriver::CreateSeleniumWebDriver
13
+ include SeleniumFury::SeleniumClient::CreateSeleniumClientDriver
@@ -1,3 +1,4 @@
1
1
  After do
2
- browser.close_current_browser_session if defined?(browser) && !browser.nil?
2
+ browser.close_current_browser_session unless(browser.nil? || browser.session_id.nil?)
3
+ driver.quit unless driver.nil?
3
4
  end
@@ -2,11 +2,11 @@ Feature: Validator
2
2
  As an automated tester I want a tool to check if my page object locators are correct so that I can update invalid locators.
3
3
 
4
4
  Scenario: Use reflection to open a page object and validate that the locators are valid
5
- Given I am on the advanced search page for HomeAway
5
+ Given I am on the test page
6
6
  When I run the validator
7
- Then the advanced search page object locators will be checked
7
+ Then the test page object locators will be checked
8
8
 
9
9
  Scenario: The validator will fail and return a list of missing locators
10
- Given I am on the advanced search page for HomeAway
10
+ Given I am on the test page
11
11
  When I run the validator with missing locators
12
12
  Then there will be missing locators found
data/lib/selenium_fury.rb CHANGED
@@ -13,13 +13,12 @@
13
13
  # * See the License for the specific language governing permissions and
14
14
  # * limitations under the License.
15
15
  # */
16
- $:.unshift(File.dirname(__FILE__))
17
16
 
18
17
  require 'rubygems'
19
18
  require 'bundler'
20
- Bundler.setup
21
- require "selenium/webdriver"
22
- require "selenium/client"
19
+
20
+ require "selenium-webdriver"
21
+ require "selenium-client"
23
22
  require 'nokogiri'
24
23
 
25
24
  require "selenium_fury/selenium_client/page_generator"
@@ -1,3 +1,18 @@
1
+ #/* Copyright (c) 2010 HomeAway, Inc.
2
+ # * All rights reserved. http://www.homeaway.com
3
+ # *
4
+ # * Licensed under the Apache License, Version 2.0 (the "License");
5
+ # * you may not use this file except in compliance with the License.
6
+ # * You may obtain a copy of the License at
7
+ # *
8
+ # * http://www.apache.org/licenses/LICENSE-2.0
9
+ # *
10
+ # * Unless required by applicable law or agreed to in writing, software
11
+ # * distributed under the License is distributed on an "AS IS" BASIS,
12
+ # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # * See the License for the specific language governing permissions and
14
+ # * limitations under the License.
15
+ # */
1
16
  module SeleniumFury
2
17
  module SeleniumApiChooser
3
18
  def generate(selenium_api_object)
@@ -9,13 +24,10 @@ module SeleniumFury
9
24
  end
10
25
  end
11
26
 
12
- def validate(page_object, *live_url)
13
- if defined?(browser)
14
- unless browser.nil?
15
- return check_page_file_class(page_object, *live_url)
16
- end
17
- end
18
- unless driver.nil?
27
+ def validate(page_object, live_url = nil)
28
+ if browser
29
+ return check_page_file_class(page_object, live_url)
30
+ else
19
31
  return web_driver_validate(page_object)
20
32
  end
21
33
  end
@@ -1,3 +1,18 @@
1
+ #/* Copyright (c) 2010 HomeAway, Inc.
2
+ # * All rights reserved. http://www.homeaway.com
3
+ # *
4
+ # * Licensed under the Apache License, Version 2.0 (the "License");
5
+ # * you may not use this file except in compliance with the License.
6
+ # * You may obtain a copy of the License at
7
+ # *
8
+ # * http://www.apache.org/licenses/LICENSE-2.0
9
+ # *
10
+ # * Unless required by applicable law or agreed to in writing, software
11
+ # * distributed under the License is distributed on an "AS IS" BASIS,
12
+ # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # * See the License for the specific language governing permissions and
14
+ # * limitations under the License.
15
+ # */
1
16
  module SeleniumFury
2
17
  module SeleniumClient
3
18
  class LocatorFinder
@@ -44,6 +44,7 @@ module SeleniumFury
44
44
  count = count + 1
45
45
  end
46
46
  result += "\n\nend"
47
+ result += "\n"
47
48
  $stdout.puts result
48
49
  return result
49
50
  end