selenium_fury 1.0.0 → 1.0.1
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/lib/selenium_fury.rb +0 -3
- data/lib/selenium_fury/selenium_web_driver/generic_elements/generic_element.rb +8 -1
- data/lib/selenium_fury/selenium_web_driver/generic_elements/generic_element_helpers.rb +6 -0
- data/lib/selenium_fury/selenium_web_driver/page_generator.rb +8 -3
- data/lib/selenium_fury/selenium_web_driver/page_validator.rb +30 -10
- data/lib/selenium_fury/version.rb +1 -1
- data/spec/selenium_web_driver/page_validator_spec.rb +56 -8
- metadata +4 -7
- data/lib/selenium_fury/common/selenium_api_chooser.rb +0 -42
- data/spec/common/selenium_api_chooser_spec.rb +0 -15
data/lib/selenium_fury.rb
CHANGED
@@ -23,7 +23,6 @@ require "selenium-client"
|
|
23
23
|
require 'nokogiri'
|
24
24
|
|
25
25
|
require "selenium_fury/common/page_parser"
|
26
|
-
require "selenium_fury/common/selenium_api_chooser"
|
27
26
|
require "selenium_fury/selenium_web_driver/create_selenium_web_driver"
|
28
27
|
require "selenium_fury/selenium_web_driver/element_finder"
|
29
28
|
require "selenium_fury/selenium_web_driver/page_object_components"
|
@@ -36,5 +35,3 @@ require "selenium_fury/selenium_web_driver/generic_elements/generic_element"
|
|
36
35
|
|
37
36
|
include SeleniumFury::SeleniumWebDriver::PageGenerator
|
38
37
|
include SeleniumFury::SeleniumWebDriver::PageValidator
|
39
|
-
|
40
|
-
include SeleniumFury::SeleniumApiChooser
|
@@ -9,9 +9,16 @@ module SeleniumFury
|
|
9
9
|
def initialize(locator, driver=nil, opt={})
|
10
10
|
@location = locator
|
11
11
|
@driver = driver
|
12
|
+
@tags = opt[:tags]
|
13
|
+
@validate = opt[:validate] != false # true if nil
|
12
14
|
end
|
13
15
|
|
14
|
-
attr_accessor :location, :driver
|
16
|
+
attr_accessor :location, :driver, :tags
|
17
|
+
attr_writer :validate
|
18
|
+
|
19
|
+
def validate?
|
20
|
+
@validate
|
21
|
+
end
|
15
22
|
end
|
16
23
|
|
17
24
|
class CheckboxElement < GenericElement
|
@@ -31,6 +31,12 @@ module GenericElementHelpers
|
|
31
31
|
end
|
32
32
|
|
33
33
|
module ElementWaitHelpers
|
34
|
+
def web_driver_wait(opt=10, &condition)
|
35
|
+
options={}
|
36
|
+
opt.kind_of?(Integer) ? options[:timeout] = opt : options = opt
|
37
|
+
Selenium::WebDriver::Wait.new(options).until { condition.call }
|
38
|
+
end
|
39
|
+
|
34
40
|
def wait_present(timeout)
|
35
41
|
web_driver_wait(timeout) { present? }
|
36
42
|
end
|
@@ -28,7 +28,7 @@ module SeleniumFury
|
|
28
28
|
end
|
29
29
|
result += "\n\nend"
|
30
30
|
$stdout.puts result
|
31
|
-
|
31
|
+
result
|
32
32
|
end
|
33
33
|
|
34
34
|
# @param page_object_attributes [Hash]
|
@@ -41,8 +41,7 @@ module SeleniumFury
|
|
41
41
|
end
|
42
42
|
}
|
43
43
|
print_selenium_web_driver_page_object page_object_attributes,class_name
|
44
|
-
|
45
|
-
|
44
|
+
Object.const_set(class_name, klass).new(driver)
|
46
45
|
end
|
47
46
|
|
48
47
|
# @param driver [Selenium::WebDriver::Driver]
|
@@ -56,6 +55,12 @@ module SeleniumFury
|
|
56
55
|
print_selenium_web_driver_page_object page_object_attributes
|
57
56
|
end
|
58
57
|
|
58
|
+
# @param driver [Selenium::WebDriver::Driver]
|
59
|
+
# @return [String]
|
60
|
+
def generate(driver)
|
61
|
+
web_driver_generate(driver)
|
62
|
+
end
|
63
|
+
|
59
64
|
# @param driver [Selenium::WebDriver::Driver]
|
60
65
|
# @param class_name [string]
|
61
66
|
# @return [PageObject]
|
@@ -16,34 +16,54 @@
|
|
16
16
|
module SeleniumFury
|
17
17
|
module SeleniumWebDriver
|
18
18
|
module PageValidator
|
19
|
-
def web_driver_validate(page_class)
|
19
|
+
def web_driver_validate(page_class, validate_tags={})
|
20
20
|
raise("Cannot find driver") if driver.nil?
|
21
21
|
missing_elements=[]
|
22
|
-
|
22
|
+
skipped_elements=[]
|
23
23
|
puts "class #{page_class}"
|
24
24
|
page_object=page_class.new(driver)
|
25
25
|
raise "Could not find web driver elements in #{page_class}" if page_class.elements.nil?
|
26
26
|
page_class.elements.each do |web_driver_element_name|
|
27
27
|
puts "\tValidating #{web_driver_element_name}"
|
28
28
|
begin
|
29
|
-
|
30
|
-
page_object.method(web_driver_element_name).call
|
31
|
-
else
|
32
|
-
raise unless page_object.send(web_driver_element_name).present?
|
33
|
-
end
|
29
|
+
element_obj = page_object.send(web_driver_element_name)
|
34
30
|
rescue
|
35
31
|
puts "\t\t\tCould not find #{web_driver_element_name}"
|
36
32
|
missing_elements.push(web_driver_element_name)
|
37
33
|
end
|
34
|
+
next unless element_obj.respond_to? :validate?
|
35
|
+
validate_element = case
|
36
|
+
when validate_tags[:validate_any] && validate_tags[:validate_all]
|
37
|
+
raise "Can't use both :validate_any and :validate_all tags"
|
38
|
+
when !element_obj.validate?
|
39
|
+
false # Already set to skip
|
40
|
+
when validate_tags[:validate_any] && element_obj.tags
|
41
|
+
element_obj.tags.any? { |tag| validate_tags[:validate_any].include? tag }
|
42
|
+
when validate_tags[:validate_all] && element_obj.tags
|
43
|
+
element_obj.tags.all? { |tag| validate_tags[:validate_all].include? tag }
|
44
|
+
else
|
45
|
+
true
|
46
|
+
end
|
47
|
+
if validate_element && !element_obj.present?
|
48
|
+
puts "\t\t\tCould not find #{web_driver_element_name}"
|
49
|
+
missing_elements.push(web_driver_element_name)
|
50
|
+
end
|
51
|
+
skipped_elements.push(web_driver_element_name) unless validate_element
|
38
52
|
end
|
39
53
|
if missing_elements.length > 0
|
40
54
|
puts "Missing Elements:"
|
41
|
-
missing_elements.each
|
42
|
-
|
43
|
-
|
55
|
+
missing_elements.each { |element| puts "\t#{element}" }
|
56
|
+
end
|
57
|
+
if skipped_elements.length > 0
|
58
|
+
puts "Skipped Elements:"
|
59
|
+
skipped_elements.each { |element| puts "\t#{element}" }
|
44
60
|
end
|
45
61
|
raise "Found Missing Elements: #{missing_elements.inspect}" if missing_elements.length > 0
|
46
62
|
end
|
63
|
+
|
64
|
+
def validate(page_class, validate_tags={})
|
65
|
+
web_driver_validate(page_class, validate_tags)
|
66
|
+
end
|
47
67
|
end
|
48
68
|
end
|
49
69
|
end
|
@@ -1,18 +1,66 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe SeleniumFury::SeleniumWebDriver::PageValidator do
|
3
3
|
|
4
|
-
|
4
|
+
before(:each) do
|
5
|
+
launch_web_driver TEST_PAGE_URL
|
6
|
+
end
|
7
|
+
|
8
|
+
context "with present elements" do
|
9
|
+
|
10
|
+
it "should not raise an error when validating" do
|
11
|
+
expect { validate(TestPage) }.to_not raise_error
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with missing elements" do
|
5
16
|
class MissingElement < PageObject
|
6
17
|
element :not_a_element1, {:id => "not a element1"}
|
7
18
|
element :not_a_element2, {:id => "not a element2"}
|
19
|
+
generic_element :not_a_element3, {:id => "not a element3"}
|
20
|
+
generic_element :not_a_element4, {:id => "not a element4"}
|
8
21
|
end
|
9
|
-
launch_web_driver TEST_PAGE_URL
|
10
|
-
expect { validate(MissingElement) }.to raise_exception RuntimeError, "Found Missing Elements: [:not_a_element1, :not_a_element2]"
|
11
|
-
end
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
|
23
|
+
it "should find missing elements for both old and new element types" do
|
24
|
+
expect { validate(MissingElement) }.
|
25
|
+
to raise_exception(RuntimeError, "Found Missing Elements: [:not_a_element1, :not_a_element2, :not_a_element3, :not_a_element4]")
|
26
|
+
end
|
16
27
|
end
|
17
28
|
|
18
|
-
|
29
|
+
context "with skipped elements" do
|
30
|
+
class SkippedElement < PageObject
|
31
|
+
generic_element :skip_hard_coded_element, {id: 'not_here'}, {validate: false}
|
32
|
+
generic_element :foo_element, {css: 'missing_foo_element'}, {tags: [:foo]}
|
33
|
+
generic_element :bar_element, {css: 'missing_bar_element'}, {tags: [:bar]}
|
34
|
+
generic_element :multiple_tag, {css: 'missing_mult_tag_element'}, {tags: [:foo, :bar]}
|
35
|
+
generic_element :no_tag, {css: 'missing_no_tag_element'}
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should validate everything not hard coded when no tags are passed" do
|
39
|
+
expect { validate(SkippedElement) }.
|
40
|
+
to raise_exception(RuntimeError, "Found Missing Elements: [:foo_element, :bar_element, :multiple_tag, :no_tag]")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should validate all elements where all tags defined in the Page Object are passed in with the test" do
|
44
|
+
expect { validate(SkippedElement, validate_all: [:foo]) }.
|
45
|
+
to raise_exception(RuntimeError, "Found Missing Elements: [:foo_element, :no_tag]")
|
46
|
+
expect { validate(SkippedElement, validate_all: [:bar]) }.
|
47
|
+
to raise_exception(RuntimeError, "Found Missing Elements: [:bar_element, :no_tag]")
|
48
|
+
expect { validate(SkippedElement, validate_all: [:foo, :bar]) }.
|
49
|
+
to raise_exception(RuntimeError, "Found Missing Elements: [:foo_element, :bar_element, :multiple_tag, :no_tag]")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should validate all elements where any tag defined in Page Object is passed in with the test" do
|
53
|
+
expect { validate(SkippedElement, validate_any: [:foo]) }.
|
54
|
+
to raise_exception(RuntimeError, "Found Missing Elements: [:foo_element, :multiple_tag, :no_tag]")
|
55
|
+
expect { validate(SkippedElement, validate_any: [:bar]) }.
|
56
|
+
to raise_exception(RuntimeError, "Found Missing Elements: [:bar_element, :multiple_tag, :no_tag]")
|
57
|
+
expect { validate(SkippedElement, validate_any: [:foo, :bar]) }.
|
58
|
+
to raise_exception(RuntimeError, "Found Missing Elements: [:foo_element, :bar_element, :multiple_tag, :no_tag]")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not allow multiple types of tag logic" do
|
62
|
+
expect { validate(SkippedElement, {validate_any: [:foo], validate_all: [:bar]}) }.
|
63
|
+
to raise_exception(RuntimeError, "Can't use both :validate_any and :validate_all tags")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
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: 1.0.
|
4
|
+
version: 1.0.1
|
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: 2013-05-
|
12
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: selenium-webdriver
|
@@ -130,7 +130,6 @@ files:
|
|
130
130
|
- features/validate_page_object.feature
|
131
131
|
- lib/selenium_fury.rb
|
132
132
|
- lib/selenium_fury/common/page_parser.rb
|
133
|
-
- lib/selenium_fury/common/selenium_api_chooser.rb
|
134
133
|
- lib/selenium_fury/selenium_web_driver/create_selenium_web_driver.rb
|
135
134
|
- lib/selenium_fury/selenium_web_driver/element_finder.rb
|
136
135
|
- lib/selenium_fury/selenium_web_driver/generic_elements/generic_element.rb
|
@@ -142,7 +141,6 @@ files:
|
|
142
141
|
- lib/selenium_fury/version.rb
|
143
142
|
- selenium_fury.gemspec
|
144
143
|
- spec/common/page_parser_spec.rb
|
145
|
-
- spec/common/selenium_api_chooser_spec.rb
|
146
144
|
- spec/selenium_web_driver/element_finder_spec.rb
|
147
145
|
- spec/selenium_web_driver/generic_elements_spec.rb
|
148
146
|
- spec/selenium_web_driver/page_generator_spec.rb
|
@@ -167,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
165
|
version: '0'
|
168
166
|
segments:
|
169
167
|
- 0
|
170
|
-
hash:
|
168
|
+
hash: 417938360726335985
|
171
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
170
|
none: false
|
173
171
|
requirements:
|
@@ -176,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
174
|
version: '0'
|
177
175
|
segments:
|
178
176
|
- 0
|
179
|
-
hash:
|
177
|
+
hash: 417938360726335985
|
180
178
|
requirements: []
|
181
179
|
rubyforge_project:
|
182
180
|
rubygems_version: 1.8.25
|
@@ -191,7 +189,6 @@ test_files:
|
|
191
189
|
- features/support/hooks.rb
|
192
190
|
- features/validate_page_object.feature
|
193
191
|
- spec/common/page_parser_spec.rb
|
194
|
-
- spec/common/selenium_api_chooser_spec.rb
|
195
192
|
- spec/selenium_web_driver/element_finder_spec.rb
|
196
193
|
- spec/selenium_web_driver/generic_elements_spec.rb
|
197
194
|
- spec/selenium_web_driver/page_generator_spec.rb
|
@@ -1,42 +0,0 @@
|
|
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 SeleniumApiChooser
|
18
|
-
def generate(selenium_api_object)
|
19
|
-
if selenium_api_object.class == Selenium::Client::Driver
|
20
|
-
return get_source_and_print_elements(selenium_api_object)
|
21
|
-
end
|
22
|
-
if selenium_api_object.class == Selenium::WebDriver::Driver
|
23
|
-
return web_driver_generate(selenium_api_object)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# @return [Array] validated page elements
|
28
|
-
# @param [PageObject] page_object
|
29
|
-
# @param [string] live_url
|
30
|
-
def validate(page_object, live_url = nil)
|
31
|
-
if defined?(browser)
|
32
|
-
unless browser.nil?
|
33
|
-
return check_page_file_class(page_object, *live_url)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
unless driver.nil?
|
37
|
-
return web_driver_validate(page_object)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
describe SeleniumFury::SeleniumApiChooser do
|
3
|
-
context "Finding generate/validate methods" do
|
4
|
-
it "should find the generator for selenium web_driver tests" do
|
5
|
-
launch_web_driver TEST_PAGE_URL
|
6
|
-
should_receive(:web_driver_generate)
|
7
|
-
generate(driver)
|
8
|
-
end
|
9
|
-
it "should find the validator for selenium web driver tests" do
|
10
|
-
launch_web_driver TEST_PAGE_URL
|
11
|
-
should_receive(:web_driver_validate).with(NilClass)
|
12
|
-
validate(NilClass)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|