selenium_fury 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,9 +1,3 @@
1
- rvm use 1.9.3@selenium_fury --create
2
- # Ensure that Bundler is installed, install it if it is not.
3
- if ! command -v bundle ; then
4
- printf "The rubygem 'bundler' is not installed, installing it now.\n"
5
- gem install bundler
6
- fi
7
-
1
+ rvm use ruby-1.9.3-p362@selenium_fury --create
8
2
 
9
3
 
data/Rakefile CHANGED
@@ -6,19 +6,15 @@ require 'rspec'
6
6
  require 'rspec/core/rake_task'
7
7
  require 'cucumber'
8
8
  require 'cucumber/rake/task'
9
- require 'yard'
10
- require 'yard/rake/yardoc_task'
9
+
11
10
  require "bundler/gem_tasks"
12
11
 
13
12
  RSpec::Core::RakeTask.new(:spec)
14
13
  Cucumber::Rake::Task.new(:feature)
15
- YARD::Rake::YardocTask.new do |t|
16
- t.files = ['lib/**/*.rb']
17
- end
18
14
 
19
- task :default do
20
- system "rake spec"
21
- end
15
+ task :default => :spec
16
+
17
+
22
18
 
23
19
  #desc 'Push gem to gem server'
24
20
  # task 'release' => ['gem:build', 'gem:git:release'] do
@@ -4,8 +4,12 @@ end
4
4
  Then /^the test page object locators will be checked$/ do
5
5
  end
6
6
  When /^I run the validator with missing locators$/ do
7
- pending
7
+ class MissingElement < PageObject
8
+ element :not_a_element1, {:id => "not a element1"}
9
+ element :not_a_element2, {:id => "not a element2"}
10
+ end
11
+ expect { web_driver_validate(MissingElement) }.to raise_exception RuntimeError, "Found Missing Elements: [:not_a_element1, :not_a_element2]"
8
12
  end
9
13
  Then /^there will be missing locators found$/ do
10
- pending
14
+
11
15
  end
@@ -22,22 +22,22 @@ module SeleniumFury
22
22
  end
23
23
 
24
24
  module ClassMethods
25
- # this is a method on the class now
26
- #@method element(element_sym, element_hash, opts={})
27
- # @param element_sym [:Symbol]
28
- # @param element_hash [Hash]
29
- # @param opts [Hash]
30
- # @return [Selenium::WebDriver::Element]
25
+
31
26
  def elements
32
27
  @elements ||= []
33
28
  end
34
29
 
35
-
30
+ # this is a method on the class now
31
+ # @method element(element_sym, element_hash, opts={})
32
+ # @param element_sym [:Symbol]
33
+ # @param element_hash [Hash]
34
+ # @param opts [Hash]
35
+ # @return [Selenium::WebDriver::Element]
36
36
  def element(element_sym, element_hash, opts={})
37
37
  #@transient_elements ||= []
38
38
  # define a new method with the name of the symbol after locator that returns the value
39
39
  send :define_method, element_sym do
40
- wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
40
+ wait = Selenium::WebDriver::Wait.new(:timeout => 0.5) # seconds
41
41
  begin
42
42
  wait.until { driver.find_element element_hash }
43
43
  rescue Selenium::WebDriver::Error::TimeOutError
@@ -48,10 +48,21 @@ module SeleniumFury
48
48
  # keep a running track of all elements and transient elements
49
49
  elements << element_sym
50
50
  #@transient_elements << element_hash if opts[:transient]
51
-
52
51
  end
53
52
 
54
- # @return [PageObject]
53
+ def element_list(element_sym, element_hash, opts={})
54
+ send :define_method, element_sym do
55
+ wait = Selenium::WebDriver::Wait.new(timeout: 0.5)
56
+ begin
57
+ wait.until { !driver.find_elements(element_hash).empty? }
58
+ driver.find_elements(element_hash)
59
+ rescue Selenium::WebDriver::Error::TimeOutError
60
+ raise "Could not find any elements like #{element_sym}"
61
+ end
62
+ end
63
+ end
64
+
65
+ # @return [PageObject]
55
66
  def page(page_sym, page_class)
56
67
  send :define_method, page_sym do
57
68
  raise "#{page_class.to_s} does not inherit from PageObject" unless page_class.superclass == PageObject
@@ -1,3 +1,3 @@
1
1
  module SeleniumFury
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -15,8 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.version = SeleniumFury::VERSION
16
16
  gem.add_dependency('selenium-webdriver')
17
17
  gem.add_dependency('nokogiri')
18
- gem.add_development_dependency('rspec')
18
+ gem.add_development_dependency('rspec','~>2.12')
19
19
  gem.add_development_dependency('cucumber')
20
- gem.add_development_dependency('yard')
21
20
  gem.add_development_dependency('redcarpet')
21
+ gem.add_development_dependency('rake')
22
22
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
  describe SeleniumFury::SeleniumWebDriver::CreateSeleniumWebDriver do
3
- it "should go to page using launch_web_driver" do
3
+ it "should go to a page using launch_web_driver" do
4
4
  launch_web_driver TEST_PAGE_URL
5
5
  driver.current_url.should include "/spec/test_page/test_page.html"
6
6
  driver.title.should == "SeleniumFury Test Page"
@@ -8,14 +8,16 @@ describe SeleniumFury::SeleniumWebDriver::CreateSeleniumWebDriver do
8
8
  end
9
9
 
10
10
  describe PageObject do
11
-
12
- it "should have a text area method on the test page" do
11
+ after(:each) do
12
+ Object.instance_eval { remove_const :TestPage } if Object.const_defined? :TestPage
13
+ end
14
+ specify "has Selenium::WebDriver::Elements defined with the element method" do
13
15
  launch_web_driver TEST_PAGE_URL
14
16
  test_page = TestPage.new(driver)
15
17
  test_page.should_not be_nil
16
18
  test_page.textarea.should be_a(Selenium::WebDriver::Element)
17
19
  end
18
- it "should have a test page" do
20
+ specify "allows a page object class can be linked to another page object class using the page method for sub pages" do
19
21
  class ComponentPage < PageObject
20
22
 
21
23
  end
@@ -23,12 +25,12 @@ describe PageObject do
23
25
  TestPage.new().component_page.should be_a(ComponentPage)
24
26
  end
25
27
 
26
- it "should have an error if a non page object class is passed to page method" do
28
+ it "should have an error if a non page object class is passed to the page method" do
27
29
  TestPage.page(:not_a_page, String)
28
30
  expect { TestPage.new().not_a_page }.to(raise_exception(RuntimeError, "String does not inherit from PageObject"))
29
31
  end
30
32
 
31
- it "should use elements on the TestPage" do
33
+ it "should call methods on Selenium::WebDriver::Elements defined in the TestPage class" do
32
34
  launch_web_driver TEST_PAGE_URL
33
35
  test_page = TestPage.new(driver)
34
36
  test_page.input_message.send_keys "this is awesome"
@@ -36,50 +38,36 @@ describe PageObject do
36
38
  driver.find_element(:id => "message").text.should == "this is awesome"
37
39
  end
38
40
 
39
- it "should use some methods man" do
41
+ specify "PageObject provides a method to return all Selenium::WebDriver::Element defined in the class" do
40
42
  launch_web_driver TEST_PAGE_URL
41
43
  test_page = TestPage.new(driver)
42
- test_page.click_check_box
43
- driver.find_element(:id => "input_checkbox").selected?.should be_true
44
- end
45
- end
46
- # OK, so here's some great info about the "magic" behind ruby.
47
- # When ruby spins up, an Object class is created, and everything runs "inside" it
48
- # When you do code like this: TestPage.new() an instance of TestPage is added as a constant
49
- # to the instance of this "global" Object class
50
- # Therefore, since rspec is running "inside" this Object Class, an instance of TestPage is
51
- # instantiated and shared from test to test, BUT when you do get_page_object, an instance
52
- # of the page object must be created and added as a constant, but if it already exists,
53
- # you're gonna have bad time. Therefore, for testing sake, we must check for this,
54
- # and handle it appropriately.
55
- #
56
- # It should also be noted that get_page_object only adds page elements to the class
57
- # and currently doesn't look for a pre-defined page object in the project
58
-
59
- describe "PageObjectElements" do
60
- before(:each) do
61
- Object.instance_eval { remove_const :TestPage } if Object.const_defined? :TestPage
62
- end
63
- after(:each) do
64
- Object.instance_eval { remove_const :TestPage }
65
- end
66
- it "should have elements" do
67
- launch_web_driver TEST_PAGE_URL
68
- test_page = get_page_object(driver, 'TestPage')
69
44
  test_page.class.elements.should_not be_nil
70
45
  test_page.class.elements.should have(15).elements
71
46
  test_page.method(test_page.class.elements[0]).call.class.should == Selenium::WebDriver::Element
72
47
  end
73
- it "should return a web_driver element when an attribute is accessed" do
74
- launch_web_driver TEST_PAGE_URL
75
- test_page = get_page_object(driver, 'TestPage')
76
- test_page.textarea.class.should == Selenium::WebDriver::Element
77
- end
78
48
 
79
49
  it "should raise an exception when the element can't be found'" do
80
50
  launch_web_driver TEST_PAGE_URL
81
- test_page = get_page_object(driver, 'TestPage')
51
+ test_page = TestPage.new(driver)
82
52
  TestPage.element :not_a_element, {:id => "not a element"}
83
53
  expect { test_page.not_a_element }.to raise_exception RuntimeError, "Could not find element not_a_element"
84
54
  end
85
- end
55
+
56
+ describe "#element_list" do
57
+ context 'when there are elements found' do
58
+ it "should return an array of Selenium::WebDriver::Elements" do
59
+ launch_web_driver TEST_PAGE_URL
60
+ test_page = TestPage.new(driver)
61
+ test_page.listings.should be_an Array
62
+ end
63
+ end
64
+ context 'when there are not elements found' do
65
+ it "should i dunno" do
66
+ launch_web_driver TEST_PAGE_URL
67
+ test_page = TestPage.new(driver)
68
+ TestPage.element_list :cats, { id: 'meow' }
69
+ expect { test_page.cats }.to raise_error RuntimeError
70
+ end
71
+ end
72
+ end
73
+ end
@@ -7,7 +7,7 @@ describe SeleniumFury::SeleniumWebDriver::PageValidator do
7
7
  element :not_a_element2, {:id => "not a element2"}
8
8
  end
9
9
  launch_web_driver TEST_PAGE_URL
10
- expect { web_driver_validate(MissingElement) }.to raise_exception RuntimeError, "Found Missing Elements: [:not_a_element1, :not_a_element2]"
10
+ expect { validate(MissingElement) }.to raise_exception RuntimeError, "Found Missing Elements: [:not_a_element1, :not_a_element2]"
11
11
  end
12
12
 
13
13
  it "should validate elements" do
@@ -13,6 +13,11 @@
13
13
 
14
14
  <div id="message"></div>
15
15
 
16
+ <ul id="element_list">
17
+ <li class="listing">Herpa</li>
18
+ <li class="listing">Derpa</li>
19
+ </ul>
20
+
16
21
  <form id="form" name="form">
17
22
  <label for="textarea">Textarea</label>
18
23
  <textarea id="textarea">This is a textarea field.
@@ -15,6 +15,8 @@ class TestPage < PageObject
15
15
  element :select, {:id => "select"}
16
16
  element :textarea, {:id => "textarea"}
17
17
 
18
+ element_list :listings, { css: 'li.listing' }
19
+
18
20
  def click_check_box
19
21
  input_checkbox.click
20
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium_fury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
@@ -48,17 +48,17 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: '2.12'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '2.12'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: cucumber
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -76,7 +76,7 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: yard
79
+ name: redcarpet
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -92,7 +92,7 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
95
- name: redcarpet
95
+ name: rake
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -122,9 +122,7 @@ files:
122
122
  - LICENSE
123
123
  - README.md
124
124
  - Rakefile
125
- - features/custom_generator.feature
126
125
  - features/generate_page_object.feature
127
- - features/step_definitions/custom_generator_steps.rb
128
126
  - features/step_definitions/generate_page_object_steps.rb
129
127
  - features/step_definitions/validate_page_object_steps.rb
130
128
  - features/support/env.rb
@@ -163,22 +161,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
161
  - - ! '>='
164
162
  - !ruby/object:Gem::Version
165
163
  version: '0'
164
+ segments:
165
+ - 0
166
+ hash: 2135389141801828284
166
167
  required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  none: false
168
169
  requirements:
169
170
  - - ! '>='
170
171
  - !ruby/object:Gem::Version
171
172
  version: '0'
173
+ segments:
174
+ - 0
175
+ hash: 2135389141801828284
172
176
  requirements: []
173
177
  rubyforge_project:
174
- rubygems_version: 1.8.24
178
+ rubygems_version: 1.8.25
175
179
  signing_key:
176
180
  specification_version: 3
177
181
  summary: Generate Selenium Page Objects
178
182
  test_files:
179
- - features/custom_generator.feature
180
183
  - features/generate_page_object.feature
181
- - features/step_definitions/custom_generator_steps.rb
182
184
  - features/step_definitions/generate_page_object_steps.rb
183
185
  - features/step_definitions/validate_page_object_steps.rb
184
186
  - features/support/env.rb
@@ -194,4 +196,3 @@ test_files:
194
196
  - spec/test_page/test_page.html
195
197
  - spec/test_page/test_page.rb
196
198
  - spec/test_page/test_page_custom_generator_configuration.rb
197
- has_rdoc:
@@ -1,21 +0,0 @@
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.
3
-
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 test page
6
- When I have a custom generator configuration class
7
- And I run the custom generator
8
- Then I will have a ruby class produced that I can use as a page object
9
-
10
-
11
- Scenario: I can specify a locator that I can pass to nokogiri to get a nokogiri node set that contains data that I want to use as an attribute name and locator value
12
- Given I have a custom generator configuration class
13
- When I specify a selector attribute
14
- And I create a nokogiri document for the test page
15
- Then I should get a nokogiri node set that I can iterate over to find a name and value for my page object locators
16
- When I call the name method on the custom generator configuration class
17
- Then I should get the raw string to name my page object attribute
18
- When I call the value method on the custom generator configuration class
19
- Then I should get a value that I can use as a selenium locator
20
-
21
-
@@ -1,114 +0,0 @@
1
- When /^I have a custom generator configuration class$/ do
2
- @test_page_custom_generator_configuration = TestPageCustomGeneratorConfiguration.new()
3
- @test_page_custom_generator_configuration.should_not be_nil
4
- end
5
- When /^I run the custom generator$/ do
6
- pending
7
- end
8
- When /^I specify a selector attribute$/ do
9
- @test_page_custom_generator_configuration.selector.should_not be_nil
10
-
11
- end
12
- When /^I create a nokogiri document for the test page$/ do
13
- @doc = Nokogiri::HTML(ADVANCED_SEARCH_HTML)
14
- @doc.should_not be_nil
15
- @doc.class.to_s.should == "Nokogiri::HTML::Document"
16
- end
17
-
18
- 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
19
- @check_box_nokogiri_elements = @doc.css(@test_page_custom_generator_configuration.selector)
20
- @check_box_nokogiri_elements.class.to_s.should == "Nokogiri::XML::NodeSet"
21
- @check_box_nokogiri_elements.each do |nokogiri_element|
22
- nokogiri_element.class.to_s.should == "Nokogiri::XML::Element"
23
- end
24
- end
25
- When /^I call the name method on the custom generator configuration class$/ do
26
- @test_page_custom_generator_configuration.nokogiri_element=@check_box_nokogiri_elements.last
27
- @test_page_custom_generator_configuration.nokogiri_element=@check_box_nokogiri_elements.last
28
- @locator_name = @test_page_custom_generator_configuration.name
29
- end
30
- Then /^I should get the raw string to name my page object attribute$/ do
31
- @locator_name.should_not be_nil
32
- @locator_name.should == "Link 3"
33
- end
34
- When /^I call the value method on the custom generator configuration class$/ do
35
- @locator_value = @test_page_custom_generator_configuration.value
36
- end
37
- Then /^I should get a value that I can use as a selenium locator$/ do
38
- @locator_value.should_not be_nil
39
- @locator_value.should == "link333333"
40
- end
41
-
42
-
43
- ADVANCED_SEARCH_HTML=<<EOF
44
- <!doctype html>
45
- <html lang="en">
46
- <head>
47
- <meta charset="utf-8">
48
- <title>SeleniumFury Test Page</title>
49
- <script type="text/javascript">
50
- function displayMessage() {
51
- document.getElementById('message').innerHTML = document.form.msgtext.value
52
- }
53
- </script>
54
- </head>
55
- <body>
56
-
57
- <div id="message"></div>
58
-
59
- <form id="form" name="form">
60
- <label for="textarea">Textarea</label>
61
- <textarea id="textarea">This is a textarea field.
62
- </textarea>
63
- <br/>
64
- <label for="select">Select</label>
65
- <select id="select">
66
- <option value="volvo">Volvo</option>
67
- <option value="saab">Saab</option>
68
- <option value="mercedes">Mercedes</option>
69
- <option value="audi">Audi</option>
70
- </select>
71
- <br/>
72
- <label for="input_button">Button</label>
73
- <input id="input_button" type="button" value="Click me"/>
74
- <br/>
75
- <label for="input_checkbox">Checkbox</label>
76
- <input id="input_checkbox" type="checkbox"/>
77
- <br/>
78
- <label for="input_file">File</label>
79
- <input id="input_file" type="file"/>
80
- <br/>
81
- <input id="input_hidden" type="hidden"/>
82
- <br/>
83
- <label for="input_image">Image</label>
84
- <input id="input_image" type="image" alt="input image"/>
85
- <br/>
86
- <label for="input_password">Password</label>
87
- <input id="input_password" type="password"/>
88
- <br/>
89
- <label for="input_radio">Radio</label>
90
- <input id="input_radio" type="radio"/>
91
- <br/>
92
- <label for="input_reset">Reset</label>
93
- <input id="input_reset" type="reset"/>
94
- <br/>
95
- <label for="input_submit">Submit</label>
96
- <input id="input_submit" type="submit"/>
97
- <br/>
98
- <label for="input_text">Text</label>
99
- <input id="input_text" type="text"/>
100
- <br/>
101
- <fieldset>
102
- <legend>Input test:</legend>
103
- <label for="input_message">Message Text:</label>
104
- <input id="input_message" name="msgtext" type="text" />
105
- <br/>
106
- <input id="input_msg_button" type="button" value="Click me" onClick="displayMessage()"/>
107
- </fieldset>
108
- </form>
109
- <a id="link111111" href="http://news.ycombinator.com/">Link 1</a>
110
- <a id="link222222" href="http://yahoo.com">Link 2</a>
111
- <a id="link333333" href="http://google.com">Link 3</a>
112
- </body>
113
- </html>
114
- EOF