selenium_fury 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Changelog.md +29 -0
  2. data/Gemfile +2 -1
  3. data/Gemfile.lock +31 -18
  4. data/Rakefile +2 -2
  5. data/features/custom_generator.feature +2 -1
  6. data/features/generate_page_object.feature +2 -1
  7. data/features/step_definitions/validate_page_object_steps.rb +4 -4
  8. data/features/validate_page_object.feature +2 -1
  9. data/lib/selenium_fury/common/page_parser.rb +49 -0
  10. data/lib/selenium_fury/common/selenium_api_chooser.rb +22 -0
  11. data/lib/selenium_fury/selenium_client/create_selenium_client_driver.rb +38 -0
  12. data/lib/selenium_fury/selenium_client/custom_generator.rb +65 -0
  13. data/lib/selenium_fury/selenium_client/locator_finder.rb +54 -0
  14. data/lib/selenium_fury/selenium_client/page_generator.rb +63 -0
  15. data/lib/selenium_fury/selenium_client/page_validator.rb +117 -0
  16. data/lib/selenium_fury/selenium_web_driver/create_selenium_web_driver.rb +35 -0
  17. data/lib/selenium_fury/selenium_web_driver/element_finder.rb +54 -0
  18. data/lib/selenium_fury/selenium_web_driver/page_generator.rb +47 -0
  19. data/lib/selenium_fury/selenium_web_driver/page_object.rb +26 -0
  20. data/lib/selenium_fury/selenium_web_driver/page_object_components.rb +67 -0
  21. data/lib/selenium_fury/selenium_web_driver/page_validator.rb +44 -0
  22. data/lib/selenium_fury.rb +24 -8
  23. data/selenium_fury.gemspec +46 -24
  24. data/spec/common/page_parser_spec.rb +9 -0
  25. data/spec/common/selenium_api_chooser_spec.rb +44 -0
  26. data/spec/{advanced_search.rb → selenium_client/advanced_search.rb} +1 -1
  27. data/spec/{advanced_search_custom_generator_configuration.rb → selenium_client/advanced_search_custom_generator_configuration.rb} +0 -0
  28. data/spec/{advanced_search_spec.rb → selenium_client/advanced_search_spec.rb} +0 -0
  29. data/spec/{custom_generators_spec.rb → selenium_client/custom_generators_spec.rb} +2 -1
  30. data/spec/selenium_client/locator_finder_spec.rb +20 -0
  31. data/spec/{page_generator_spec.rb → selenium_client/page_generator_spec.rb} +3 -2
  32. data/spec/selenium_client/page_validator_spec.rb +31 -0
  33. data/spec/selenium_web_driver/advanced_search.rb +47 -0
  34. data/spec/selenium_web_driver/element_finder_spec.rb +23 -0
  35. data/spec/selenium_web_driver/inquiry_side_bar.rb +7 -0
  36. data/spec/selenium_web_driver/page_generator_spec.rb +9 -0
  37. data/spec/selenium_web_driver/page_object_spec.rb +60 -0
  38. data/spec/selenium_web_driver/page_validator_spec.rb +21 -0
  39. data/spec/selenium_web_driver/property_page.rb +3 -0
  40. data/spec/spec_helper.rb +8 -4
  41. metadata +93 -59
  42. data/CHANGELOG +0 -5
  43. data/lib/selenium_fury/create_browser_driver.rb +0 -19
  44. data/lib/selenium_fury/custom_generator.rb +0 -62
  45. data/lib/selenium_fury/page_generator.rb +0 -130
  46. data/lib/selenium_fury/page_validator.rb +0 -113
  47. data/spec/page_validator_spec.rb +0 -9
data/Changelog.md ADDED
@@ -0,0 +1,29 @@
1
+ ###v0.5.2
2
+ ####Enhancements
3
+
4
+ * Adding the custom generator and cucumber features to the project.
5
+ * Tests now execute against HomeAway.
6
+
7
+ [full changelog](https://github.com/scottcsims/SeleniumFury/compare/v0.5.1...v0.5.2)
8
+
9
+ ###v0.5.1
10
+ ####Enhancements
11
+
12
+ * Adding ability to name attributes in order of id, name, title.
13
+
14
+ [full changelog](https://github.com/scottcsims/SeleniumFury/compare/v0.5...v0.5.1)
15
+
16
+ ###v0.5.
17
+ ####Enhancements
18
+
19
+ * Adding project files and connecting to a public facing site.
20
+
21
+ v0.2.
22
+ ####Enhancements
23
+
24
+ * Adding Validator Code
25
+
26
+ v0.1.
27
+ ####Enhancements
28
+
29
+ * Adding Generator Code
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gem "selenium-client", :require => "selenium/client"
3
+ gem "selenium-webdriver"
4
4
  gem "nokogiri"
5
5
 
6
6
  group :development do
@@ -12,6 +12,7 @@ group :development do
12
12
  gem "bundler"
13
13
  gem "builder"
14
14
  gem "rake"
15
+ gem "faker"
15
16
  end
16
17
 
17
18
 
data/Gemfile.lock CHANGED
@@ -2,35 +2,47 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  builder (3.0.0)
5
- cucumber (1.0.2)
5
+ childprocess (0.2.2)
6
+ ffi (~> 1.0.6)
7
+ cucumber (1.1.0)
6
8
  builder (>= 2.1.2)
7
9
  diff-lcs (>= 1.1.2)
8
- gherkin (~> 2.4.5)
10
+ gherkin (~> 2.5.0)
9
11
  json (>= 1.4.6)
10
- term-ansicolor (>= 1.0.5)
11
- diff-lcs (1.1.2)
12
- gherkin (2.4.5)
12
+ term-ansicolor (>= 1.0.6)
13
+ diff-lcs (1.1.3)
14
+ faker (1.0.1)
15
+ i18n (~> 0.4)
16
+ ffi (1.0.9)
17
+ gherkin (2.5.4)
13
18
  json (>= 1.4.6)
14
19
  git (1.2.5)
20
+ i18n (0.6.0)
15
21
  jeweler (1.6.4)
16
22
  bundler (~> 1.0)
17
23
  git (>= 1.2.5)
18
24
  rake
19
- json (1.5.3)
25
+ json (1.6.1)
26
+ json_pure (1.6.1)
20
27
  nokogiri (1.5.0)
21
- rake (0.9.2)
28
+ rake (0.9.2.2)
22
29
  rdiscount (1.6.8)
23
- rspec (2.6.0)
24
- rspec-core (~> 2.6.0)
25
- rspec-expectations (~> 2.6.0)
26
- rspec-mocks (~> 2.6.0)
27
- rspec-core (2.6.4)
28
- rspec-expectations (2.6.0)
30
+ rspec (2.7.0)
31
+ rspec-core (~> 2.7.0)
32
+ rspec-expectations (~> 2.7.0)
33
+ rspec-mocks (~> 2.7.0)
34
+ rspec-core (2.7.1)
35
+ rspec-expectations (2.7.0)
29
36
  diff-lcs (~> 1.1.2)
30
- rspec-mocks (2.6.0)
31
- selenium-client (1.2.18)
32
- term-ansicolor (1.0.6)
33
- yard (0.7.2)
37
+ rspec-mocks (2.7.0)
38
+ rubyzip (0.9.4)
39
+ selenium-webdriver (2.9.1)
40
+ childprocess (>= 0.2.1)
41
+ ffi (= 1.0.9)
42
+ json_pure
43
+ rubyzip
44
+ term-ansicolor (1.0.7)
45
+ yard (0.7.3)
34
46
 
35
47
  PLATFORMS
36
48
  ruby
@@ -39,10 +51,11 @@ DEPENDENCIES
39
51
  builder
40
52
  bundler
41
53
  cucumber
54
+ faker
42
55
  jeweler
43
56
  nokogiri
44
57
  rake
45
58
  rdiscount
46
59
  rspec
47
- selenium-client
60
+ selenium-webdriver
48
61
  yard
data/Rakefile CHANGED
@@ -23,9 +23,9 @@ Jeweler::Tasks.new do |gem|
23
23
  all of the selenium locators you are using in your page file and return a list of the locators that it could not find.
24
24
  If there are missing locators you can then rerun the generator to generate new selenium locators for your page. http://www.scottcsims.com}
25
25
  gem.email = "ssims98@gmail.com"
26
- gem.authors = ["Scott Sims"]
26
+ gem.authors = ["Scott Sims","Tim Tischler"]
27
27
  gem.homepage = "https://github.com/scottcsims/SeleniumFury"
28
- gem.version = '0.5.5'
28
+ gem.version = '0.5.6'
29
29
  gem.add_dependency 'nokogiri'
30
30
  end
31
31
 
@@ -1,4 +1,5 @@
1
- Feature: 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.
1
+ Feature: Custom Generator
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.
2
3
 
3
4
  Scenario: Use a custom generator configuration object to specify how to name our variables from another source than the id
4
5
  Given I am on the advanced search page for HomeAway
@@ -1,4 +1,5 @@
1
- Feature: As an automated tester I want to use a tool to find html elements on a web page so that I can reuse locators in in the page object pattern.
1
+ Feature: Generator
2
+ As an automated tester I want to use a tool to find html elements on a web page so that I can reuse locators in in the page object pattern.
2
3
 
3
4
 
4
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.
@@ -1,9 +1,8 @@
1
1
  When /^I run the validator$/ do
2
- check_page_file_class(AdvancedSearch, "/searchForm")
2
+ validate(AdvancedSearch, "/searchForm")
3
3
  end
4
4
  Then /^the advanced search page object locators will be checked$/ do
5
- found_missing_locators.should have(0).elements
6
- found_missing_locators.should_not be_nil
5
+ @found_missing_locators.should have(0).elements
7
6
  end
8
7
  When /^I run the validator with missing locators$/ do
9
8
  class AdvancedSearchBroken < AdvancedSearch
@@ -20,5 +19,6 @@ When /^I run the validator with missing locators$/ do
20
19
  end
21
20
  end
22
21
  Then /^there will be missing locators found$/ do
23
- found_missing_locators["missing_locator_attribute"].should == "missing_locator"
22
+ @found_missing_locators.should have(1).elements
23
+ @found_missing_locators["missing_locator_attribute"].should == "missing_locator"
24
24
  end
@@ -1,4 +1,5 @@
1
- Feature: As an automated tester I want a tool to check if my page object locators are correct so that I can update invalid locators.
1
+ Feature: Validator
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.
2
3
 
3
4
  Scenario: Use reflection to open a page object and validate that the locators are valid
4
5
  Given I am on the advanced search page for HomeAway
@@ -0,0 +1,49 @@
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
+ # */
16
+ module SeleniumFury
17
+ class PageParser
18
+ def initialize (html_source)
19
+ @html_source = html_source
20
+ @nokogiri_selectors= ["select",
21
+ "textarea",
22
+ "form",
23
+ "input",
24
+ "input[type='button']",
25
+ "input[type='file']",
26
+ "input[type='checkbox']",
27
+ "input[type='password']",
28
+ "input[type='radio']",
29
+ "input[type='reset']",
30
+ "input[type='image']",
31
+ "input[type='submit']",
32
+ "input[type='text']"]
33
+
34
+ end
35
+
36
+ attr_reader :browser, :nokogiri_selectors,:html_source
37
+
38
+ def nokogiri_elements
39
+ nokogiri_elements=[]
40
+ doc = Nokogiri::HTML(html_source)
41
+ nokogiri_selectors.each do |selector|
42
+ doc.css(selector).each do |nokogiri_element|
43
+ nokogiri_elements.push(nokogiri_element)
44
+ end
45
+ end
46
+ return nokogiri_elements
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,22 @@
1
+ module SeleniumFury
2
+ module SeleniumApiChooser
3
+ def generate(selenium_api_object)
4
+ if selenium_api_object.class == Selenium::Client::Driver
5
+ return SeleniumFury::SeleniumClient::PageGenerator.get_source_and_print_elements(selenium_api_object)
6
+ end
7
+ if selenium_api_object.class == Selenium::WebDriver::Driver
8
+ return SeleniumFury::SeleniumWebDriver::PageGenerator.web_driver_generate(selenium_api_object)
9
+ end
10
+ end
11
+
12
+ def validate(page_object, *live_url)
13
+ unless browser.nil?
14
+ return check_page_file_class(page_object,*live_url)
15
+ end
16
+ unless driver.nil?
17
+ return SeleniumFury::SeleniumWebDriver::PageValidator.web_driver_validate(page_object)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,38 @@
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
+ # */
16
+ module SeleniumFury
17
+ module SeleniumClient
18
+ module CreateSeleniumClientDriver
19
+ # @return [Selenium::Client::Driver]
20
+ def browser
21
+ return @browser
22
+ end
23
+
24
+ # @param url [string]
25
+ # @return [Selenium::Client::Driver]
26
+ def create_selenium_driver(url)
27
+
28
+ @browser = Selenium::Client::Driver.new(
29
+ :host => ENV['HOST'] || "localhost",
30
+ :port => 4444,
31
+ :browser => ENV['SELENIUM_RC_BROWSER'] || "*firefox",
32
+ :url => url,
33
+ :timeout_in_second => 60)
34
+ end
35
+ alias_method :create_selenium_client_driver, :create_selenium_driver
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,65 @@
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
+ # */
16
+ module SeleniumFury
17
+ module SeleniumClient
18
+ module CustomGenerator
19
+ # Use a custom configuration object to define a location strategy for a locators name and value
20
+ # @param [Hash] options the options to use with a custom generator.
21
+ # @option opts [CustomConfiguration] :custom_configuration a class that explains how to parse the page
22
+ # @option opts [String] :browser the selenium driver
23
+ # @option opts [String] :html html from the page under test
24
+ def custom_generator(options)
25
+ custom_configuration = options[:custom_configuration]
26
+ browser = options[:browser]
27
+ if !browser.nil?
28
+ html = browser.get_html_source
29
+ else
30
+ html = options[:html]
31
+ end
32
+ doc = Nokogiri::HTML(html)
33
+ html_menu_elements ={}
34
+ doc.css(custom_configuration.selector).each do |nokogiri_element|
35
+ custom_configuration.nokogiri_element = nokogiri_element
36
+ puts "Html element is #{nokogiri_element}" if $DEBUG
37
+ generated_name = clean_attribute_name(custom_configuration.name)
38
+ puts "generated name is #{generated_name}" if $DEBUG
39
+ generated_value = custom_configuration.value
40
+ puts "generated value is #{generated_value}" if $DEBUG
41
+ puts "@#{generated_name} = \"#{generated_value}\"" if $DEBUG
42
+ html_menu_elements[generated_name]= generated_value
43
+ end
44
+ return print_selenium_client_page_object(html_menu_elements)
45
+ end
46
+
47
+ # Parse the html attribute to a ruby variable
48
+ # @return [String]
49
+ # @param attribute_name [String] the html id,name, or title of an element
50
+ def clean_attribute_name(attribute_name)
51
+ attribute_name.gsub!('input-', '')
52
+ attribute_name.gsub!('select-', '')
53
+ attribute_name.gsub!(/([A-Z]+)/, '_\1')
54
+ attribute_name.gsub!('\\', '')
55
+ attribute_name.gsub!(' ', '_')
56
+ attribute_name.gsub!('.', '_')
57
+ attribute_name.gsub!('-', '_')
58
+ attribute_name.gsub!('__', '_')
59
+ attribute_name.gsub!(/^_/, '')
60
+ attribute_name = attribute_name.to_s.downcase
61
+ return attribute_name
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,54 @@
1
+ module SeleniumFury
2
+ module SeleniumClient
3
+ class LocatorFinder
4
+ def initialize (nokogiri_elements)
5
+ @nokogiri_elements=nokogiri_elements
6
+ @valid_locators=["id", "name", "title"]
7
+ end
8
+
9
+ attr_reader :nokogiri_elements, :valid_locators
10
+
11
+ def find_locators
12
+ locators=[]
13
+ nokogiri_elements.each do |nokogiri_element|
14
+ valid_locators.each do |valid_locator|
15
+ if nokogiri_element.get_attribute(valid_locator) != nil
16
+ locators.push(nokogiri_element.get_attribute(valid_locator))
17
+ break
18
+ end
19
+ end
20
+ end
21
+ return locators
22
+ end
23
+
24
+ def page_object_attributes
25
+ locators=find_locators
26
+ object_attributes ={}
27
+ locators.each do |locator|
28
+ name=attribute_name(locator)
29
+ object_attributes[name] = locator
30
+ end
31
+ return object_attributes
32
+ end
33
+
34
+ def attribute_name name
35
+ if !name.nil?
36
+ find_and_replace_patterns = [[/([A-Z]+)/, '_\1'],
37
+ ['input-', ''],
38
+ ['select-', ''],
39
+ ['\\', ''],
40
+ [' ', '_'],
41
+ ['.', '_'],
42
+ ['-', '_'],
43
+ ['__', '_']
44
+ ]
45
+ find_and_replace_patterns.each do |pattern|
46
+ name=name.gsub(pattern[0], pattern[1])
47
+ end
48
+ name=name.to_s.downcase
49
+ end
50
+ return name
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,63 @@
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
+ # */
16
+ module SeleniumFury
17
+ module SeleniumClient
18
+ module PageGenerator
19
+
20
+ # @return [String]
21
+ # @param html_elements [Hash]
22
+ def print_selenium_client_page_object(html_elements)
23
+ result = ""
24
+ result += "found (#{html_elements.length} elements)\n"
25
+ result += "class YourPageFile\n"
26
+ result += "\tdef initialize *browser\n\t\t@browser = *browser\n"
27
+ html_elements.keys.sort.each do |key|
28
+ result += "\t\t@#{key} = \"#{html_elements[key]}\"\n"
29
+ end
30
+ result += "\tend\n"
31
+ count=1
32
+ html_elements.keys.sort.each do |key|
33
+ if count == 1
34
+ result += "\tattr_accessor :browser, "
35
+ end
36
+ if count % 5 == 0
37
+ result += "\n\t"
38
+ end
39
+ if count != html_elements.length
40
+ result += ":#{key}, "
41
+ else
42
+ result += ":#{key}"
43
+ end
44
+ count = count + 1
45
+ end
46
+ result += "\n\nend"
47
+ $stdout.puts result
48
+ return result
49
+ end
50
+
51
+
52
+ # @param browser [Selenium::Client::Driver]
53
+ def get_source_and_print_elements(browser)
54
+ html =browser.get_html_source
55
+ nokogiri_elements = SeleniumFury::PageParser.new(html).nokogiri_elements
56
+ raise "The generator did not find nokogiri elements" unless nokogiri_elements
57
+ page_object_attributes = SeleniumFury::SeleniumClient::LocatorFinder.new(nokogiri_elements).page_object_attributes
58
+ raise "The generator did not find page object attributes" if page_object_attributes.empty?
59
+ print_selenium_client_page_object page_object_attributes
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,117 @@
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
+ # */
16
+ module SeleniumFury
17
+ module SeleniumClient
18
+ module PageValidator
19
+ @found_missing_locators
20
+ attr_accessor :found_missing_locators
21
+ # @param page_file_class [Class] The page object class you want to test
22
+ # @param live_url [String] the url of the page your testing
23
+ def check_page_file_class(page_file_class, *live_url)
24
+ raise "cannot access the selenium client driver" if browser.nil?
25
+ missing_locators={}
26
+ puts "Validating the #{page_file_class} class"
27
+ #all initialize methods of page files should have *browser specified as the argument. This is an optional argument
28
+ test_page = page_file_class.new(browser)
29
+ raise "The test class is nil" if test_page.nil?
30
+ #skip the open if we don't need to open the url again
31
+ unless live_url.empty?
32
+ puts "Opening #{browser.browser_url}/#{live_url}" #if $DEBUG
33
+ browser.open live_url
34
+ end
35
+
36
+ #check for class methods and execute.
37
+ verify_class_variables(test_page, missing_locators) if test_page.public_methods(all=false).length > 0
38
+
39
+ #check for instance methods and execute.
40
+ verify_instance_variables(test_page, missing_locators) if test_page.instance_variables.length > 0
41
+ @found_missing_locators=missing_locators
42
+ return print_missing_locators(missing_locators)
43
+ end
44
+
45
+
46
+ # @param missing_locators [Hash] locator name and values
47
+ def print_missing_locators missing_locators
48
+ puts "Missing locators are " if missing_locators != {}
49
+ missing_locators.each_pair do |locator_name, locator_value|
50
+ puts " #{locator_name} => #{locator_value}"
51
+ end
52
+ raise "found missing locators" unless missing_locators.empty?
53
+ end
54
+
55
+ def attribute_name_filter locator_name
56
+ #Add names of attributes to filter
57
+ skip_words=["browser"]
58
+
59
+ skip_words=skip_words+@known_missing_locators if !@known_missing_locators.nil?
60
+
61
+ return skip_words.include?(locator_name)
62
+ end
63
+
64
+ # @param test_page [Object] an instantiated page object
65
+ # @param missing_locators [Hash]
66
+ def verify_instance_variables(test_page, missing_locators)
67
+ #test_page.print_properties browser
68
+ test_page.instance_variables.each do |locator_name|
69
+ #prepare the locator values
70
+ locator_name.slice!(0)
71
+ if attribute_name_filter(locator_name)
72
+ puts "Skipping validation for #{locator_name}"
73
+ next
74
+ end
75
+ next if (test_page.method(locator_name).call.class.to_s != "String")
76
+ puts " Validating the #{locator_name} page element locator" #chomp the @ sign off of the method name.
77
+ locator_value = test_page.method(locator_name) # Create the reference to the get method of the instance variable
78
+ begin
79
+ browser.wait_for_element(locator_value.call, {:timeout_in_seconds => "5"})
80
+ rescue
81
+ puts " ----------------------------------- Could not find '#{locator_name}'"
82
+ end
83
+ missing_locators[locator_name]= locator_value.call if !browser.element?(locator_value.call) # Use the value of the instance variable
84
+ end
85
+ end
86
+
87
+ # @param test_page [Object] an instantiated page object
88
+ # @param missing_locators [Hash]
89
+ def verify_class_variables(test_page, missing_locators)
90
+ test_page.public_methods(all=false).each do |locator_name|
91
+ #Only operate with the set methods not the get methods
92
+ next if (!locator_name.include?("="))
93
+
94
+ locator_name.slice!(locator_name.length-1)
95
+
96
+ if attribute_name_filter(locator_name)
97
+ puts "Skipping validation for #{locator_name}"
98
+ next
99
+ end
100
+ next if (test_page.method(locator_name).call.class.to_s != "String")
101
+ puts " Validating the #{locator_name} page element locator" #chomp the @ sign off of the method name.
102
+ locator_value = test_page.method(locator_name) # Create the reference to the get method of the instance variable
103
+ #Now validate the page
104
+ begin
105
+ browser.wait_for_element(locator_value.call, {:timeout_in_seconds => "5"})
106
+ rescue
107
+ puts " ----------------------------------- Could not find #{locator_name}"
108
+ end
109
+ missing_locators[locator_name]= locator_value.call if !browser.element?(locator_value.call) # Use the value of the instance variable
110
+
111
+ end
112
+ end
113
+
114
+
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,35 @@
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
+ # */
16
+
17
+ module SeleniumFury
18
+ module SeleniumWebDriver
19
+ module CreateSeleniumWebDriver
20
+
21
+ #@return [Selenium::WebDriver::Driver]
22
+ def driver
23
+ return @driver
24
+ end
25
+
26
+ # @param url [string]
27
+ # @return [Selenium::WebDriver::Driver]
28
+ def launch_web_driver url
29
+ @driver = Selenium::WebDriver.for :firefox
30
+ @driver.navigate.to url
31
+ end
32
+
33
+ end
34
+ end
35
+ end