druid-ts 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +14 -0
- data/features/element.feature +1 -0
- data/features/html/static_elements.html +3 -0
- data/features/ordered_list.feature +5 -0
- data/features/step_definations/element_steps.rb +4 -0
- data/features/step_definations/ordered_list_steps.rb +4 -0
- data/features/step_definations/table_steps.rb +4 -0
- data/features/step_definations/unordered_list_steps.rb +4 -0
- data/features/table.feature +9 -0
- data/features/unordered_list.feature +5 -0
- data/lib/druid.rb +4 -2
- data/lib/druid/accessors.rb +46 -9
- data/lib/druid/assist.rb +21 -0
- data/lib/druid/elements/element.rb +9 -0
- data/lib/druid/elements/table_row.rb +1 -1
- data/lib/druid/page_factory.rb +16 -5
- data/lib/druid/version.rb +1 -1
- data/spec/druid/accessors_spec.rb +9 -3
- data/spec/druid/druid_spec.rb +97 -13
- data/spec/druid/elements/table_row_spec.rb +1 -0
- data/spec/druid/page_factory_spec.rb +90 -9
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69f2f0968bdcb0f4b0bf3bc82c40747118a2b2c8
|
4
|
+
data.tar.gz: d7e98d748da74a8936534b3a4b3a3b628130ff80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2b3000474fb1dc3ec20bc53e8bf452e49f90ef3d7cece31bd309136bb6e6dff6c7319bdecdbfb98598b7baa5a0fd83f56b4d46882ec8200bdf90a925fd8a17b
|
7
|
+
data.tar.gz: 84203743b392fd02051531e63209dc6581d83e6830995d091b9f8ef7a35cdcfe6bd8e25aec3c95b4a8cf5f7c65d994aff373d622f7d0631a4573e2a9d1e4fc2a
|
data/ChangeLog
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
+
=== 2017-01-13
|
2
|
+
* Enhancement
|
3
|
+
* Added callback to initialize_accessors method during initialization
|
4
|
+
* Added html method to Element
|
5
|
+
* Added generated method to return text for a table
|
6
|
+
* Added generated method to return text for an unordered list
|
7
|
+
* Added generated method to return text for an ordered list
|
8
|
+
=== 2017-01-09
|
9
|
+
* Enhancement
|
10
|
+
* Added params class instance variable to hold hash values that can be used in the page
|
11
|
+
* Added ability to insert ERB into page_url string and have it access params
|
12
|
+
* Fixes
|
13
|
+
* Fixed issue when passing symbol to page_url and calling multiple times
|
1
14
|
=== 2017-01-03
|
2
15
|
* Enhancement
|
3
16
|
* Added selected_values method to SelectList to get values of all selected elements
|
17
|
+
* Added ability to pass classname as string to visit_page, on_page, and if_page methods
|
4
18
|
=== Version v1.1.5/ 2016-12-31
|
5
19
|
* Enhancement
|
6
20
|
* Added method to get the id of an Element
|
data/features/element.feature
CHANGED
@@ -20,6 +20,7 @@ Feature: Elements
|
|
20
20
|
Then I should know it exists
|
21
21
|
And I should know it is visible
|
22
22
|
And I should know its' text is "Google Search"
|
23
|
+
And I should know the html is "<a href="success.html" id="link_id" name="link_name" class="link_class" title="link_title">Google Search</a>"
|
23
24
|
And I should know it is equal to itself
|
24
25
|
And I should know its' tag name is "a"
|
25
26
|
And I should know the attribute "readonly" is false
|
@@ -40,3 +40,8 @@ Feature: Ordered list
|
|
40
40
|
Then I should see that the ordered list exists
|
41
41
|
When I get the first item from the list
|
42
42
|
Then the list items text should be "Number One"
|
43
|
+
|
44
|
+
Scenario: Getting the text for an ordered list
|
45
|
+
Then the text for the ordered list should contain "Number One"
|
46
|
+
And the text for the ordered list should contain "Number Two"
|
47
|
+
And the text for the ordered list should contain "Number Three"
|
@@ -75,3 +75,7 @@ end
|
|
75
75
|
When(/^I retrieve a table with thead element$/) do
|
76
76
|
@element = @page.table_with_thead_id_element
|
77
77
|
end
|
78
|
+
|
79
|
+
Then(/^I should see the text includes "([^"]*)" when I retrieve it by "([^"]*)"$/) do |text, how|
|
80
|
+
expect(@page.send("table_#{how}")).to include text
|
81
|
+
end
|
data/features/table.feature
CHANGED
@@ -45,6 +45,11 @@ Feature: Table
|
|
45
45
|
Scenario: Retrieve data from a table with an incorrect column header
|
46
46
|
When I retrieve a table element
|
47
47
|
Then the data for row "Data3" and column "Data20" should be nil
|
48
|
+
|
49
|
+
Scenario: Retrieve data from a table that does not have a cell which corresponds to a column header
|
50
|
+
When I retrieve a table with thead element
|
51
|
+
Then the data for row "Data5" and column "Col2" should be nil
|
52
|
+
|
48
53
|
@name
|
49
54
|
Scenario Outline: Locating table cells on the Page
|
50
55
|
When I retrieve a table element by "<locate_by>"
|
@@ -92,3 +97,7 @@ Feature: Table
|
|
92
97
|
Scenario: Retrieve data from the first row of a table with a thead using a column header
|
93
98
|
When I retrieve a table with thead element
|
94
99
|
Then the data for column "Col1" and row "1" should be "Col1"
|
100
|
+
|
101
|
+
Scenario: Getting the text from a table
|
102
|
+
Then I should see the text includes "Data1" when I retrieve it by "id"
|
103
|
+
And I should see the text includes "Data2" when I retrieve it by "id"
|
@@ -41,3 +41,8 @@ Feature: Unordered list
|
|
41
41
|
Then I should see that the unordered list exists
|
42
42
|
When I get the first item from the list
|
43
43
|
Then the list items text should be "Item One"
|
44
|
+
|
45
|
+
Scenario: Getting the text from an unordered list
|
46
|
+
Then the text for the unordered list should contain "Item One"
|
47
|
+
And the text for the unordered list should contain "Item Two"
|
48
|
+
And the text for the unordered list should contain "Item Three"
|
data/lib/druid.rb
CHANGED
@@ -43,13 +43,15 @@ module Druid
|
|
43
43
|
# @return [Watir::Browser] the drvier passed to the constructor
|
44
44
|
attr_reader :driver
|
45
45
|
#
|
46
|
-
# Construct a new druid.
|
47
|
-
#
|
46
|
+
# Construct a new druid. Prior to browser initialization it will call
|
47
|
+
# a method named initialize_accessors if it exists. Upon initialization of
|
48
|
+
# the page it will call a method named initialize_page if it exists
|
48
49
|
#
|
49
50
|
# @param [Watir::Browser] the driver to use
|
50
51
|
# @param [bool] open the page if page_url is set
|
51
52
|
#
|
52
53
|
def initialize(driver, visit=false)
|
54
|
+
initialize_accessors if respond_to?(:initialize_accessors)
|
53
55
|
if driver.is_a? Watir::Browser
|
54
56
|
@driver ||= driver
|
55
57
|
goto if visit && respond_to?(:goto)
|
data/lib/druid/accessors.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'druid/elements'
|
2
|
+
require 'erb'
|
2
3
|
|
3
4
|
module Druid
|
4
5
|
#
|
@@ -7,6 +8,25 @@ module Druid
|
|
7
8
|
# set of methods that provide access to the elements on the web pages.
|
8
9
|
#
|
9
10
|
module Accessors
|
11
|
+
|
12
|
+
#
|
13
|
+
# Set some values that can be used withing the class. This is
|
14
|
+
# typically used to provided values that help build dynamic urls in
|
15
|
+
# the page_url method
|
16
|
+
#
|
17
|
+
# @param [Hash] the value to set the params
|
18
|
+
#
|
19
|
+
def params=(the_params)
|
20
|
+
@params = the_params
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Return the params that exist on this page class
|
25
|
+
#
|
26
|
+
def params
|
27
|
+
@params ||= {}
|
28
|
+
end
|
29
|
+
|
10
30
|
#
|
11
31
|
# Specify the url for the page. A call to this method will generate a
|
12
32
|
# 'goto' method to take you to the page.
|
@@ -16,8 +36,11 @@ module Druid
|
|
16
36
|
#
|
17
37
|
def page_url(url)
|
18
38
|
define_method("goto") do
|
19
|
-
|
20
|
-
|
39
|
+
lookup = url.kind_of?(Symbol) ? self.send(url) : url
|
40
|
+
erb = ERB.new(%Q{#{lookup}})
|
41
|
+
merged_params = self.class.instance_variable_get("@merged_params")
|
42
|
+
params = merged_params ? merged_params : self.class.params
|
43
|
+
driver.goto erb.result(binding)
|
21
44
|
end
|
22
45
|
end
|
23
46
|
alias_method :direct_url, :page_url
|
@@ -408,12 +431,13 @@ module Druid
|
|
408
431
|
end
|
409
432
|
|
410
433
|
#
|
411
|
-
# adds
|
434
|
+
# adds three methods - one to retrieve the text for the table, one
|
435
|
+
# to retrieve the table element, and another to
|
412
436
|
# check the table's existence.
|
413
437
|
#
|
414
438
|
# @example
|
415
439
|
# table(:cart, :id => 'shopping_cart')
|
416
|
-
# # will generate a 'cart_element' and 'cart?' method
|
440
|
+
# # will generate a 'cart', 'cart_element' and 'cart?' method
|
417
441
|
#
|
418
442
|
# @param the name used for the generated methods
|
419
443
|
# @param identifier how we find a table. You can use a multiple parameters
|
@@ -426,6 +450,10 @@ module Druid
|
|
426
450
|
# @param optional block to be invoked when element method is called
|
427
451
|
#
|
428
452
|
def table(name, identifier={:index => 0}, &block)
|
453
|
+
define_method(name) do
|
454
|
+
return table_text_for identifier.clone unless block_given?
|
455
|
+
self.send("#{name}_element").text
|
456
|
+
end
|
429
457
|
define_method("#{name}_element") do
|
430
458
|
return call_block(&block) if block_given?
|
431
459
|
table_for(identifier.clone)
|
@@ -657,12 +685,13 @@ module Druid
|
|
657
685
|
alias_method :li, :list_item
|
658
686
|
|
659
687
|
#
|
660
|
-
# adds
|
688
|
+
# adds three methods - one to return the text within the ordered
|
689
|
+
# list, one to retrieve the ordered list element, and another to
|
661
690
|
# test it's existence.
|
662
691
|
#
|
663
692
|
# @example
|
664
693
|
# ordered_list(:top_five, :id => 'top')
|
665
|
-
# # will generate 'top_five_element' and 'top_five?' methods
|
694
|
+
# # will generate 'top_five' 'top_five_element' and 'top_five?' methods
|
666
695
|
#
|
667
696
|
# @param [Symbol] the name used for the generated methods
|
668
697
|
# @param [Hash] identifier how we find an ordered list. You can use a multiple parameters
|
@@ -675,6 +704,10 @@ module Druid
|
|
675
704
|
# @param optional block to be invoked when element method is called
|
676
705
|
#
|
677
706
|
def ordered_list(name, identifier={:index => 0}, &block)
|
707
|
+
define_method(name) do
|
708
|
+
return ordered_list_text_for identifier.clone unless block_given?
|
709
|
+
self.send("#{name}_element").text
|
710
|
+
end
|
678
711
|
define_method("#{name}_element") do
|
679
712
|
return call_block(&block) if block_given?
|
680
713
|
ordered_list_for(identifier.clone)
|
@@ -731,12 +764,12 @@ module Druid
|
|
731
764
|
alias_method :textarea, :text_area
|
732
765
|
|
733
766
|
#
|
734
|
-
# adds
|
735
|
-
# check it's existence.
|
767
|
+
# adds three methods - one to return the text of unordered list, another one
|
768
|
+
# retrieve the unordered list element, and another to check it's existence.
|
736
769
|
#
|
737
770
|
# @example
|
738
771
|
# unordered_list(:menu, :id => 'main_menu')
|
739
|
-
# # will generate 'menu_element' and 'menu?' methods
|
772
|
+
# # will generate 'menu' 'menu_element' and 'menu?' methods
|
740
773
|
#
|
741
774
|
# @param [Symbol] the name used for the generated methods
|
742
775
|
# @param [Hash] identifier how we find an unordered list. You can use a multiple parameters
|
@@ -748,6 +781,10 @@ module Druid
|
|
748
781
|
# * :name
|
749
782
|
# @param optional block to be invoked when element method is called
|
750
783
|
def unordered_list(name, identifier={:index => 0}, &block)
|
784
|
+
define_method(name) do
|
785
|
+
return unordered_list_text_for identifier.clone unless block_given?
|
786
|
+
self.send("#{name}_element").text
|
787
|
+
end
|
751
788
|
define_method("#{name}_element") do
|
752
789
|
return call_block(&block) if block_given?
|
753
790
|
unordered_list_for(identifier.clone)
|
data/lib/druid/assist.rb
CHANGED
@@ -129,6 +129,13 @@ module Druid
|
|
129
129
|
find_elements("divs(identifier)", Elements::Div, identifier, 'div')
|
130
130
|
end
|
131
131
|
|
132
|
+
#
|
133
|
+
# method to return the text for a table
|
134
|
+
#
|
135
|
+
def table_text_for(identifier)
|
136
|
+
process_call("table(identifier).text", Elements::Table, identifier, nil, 'table')
|
137
|
+
end
|
138
|
+
|
132
139
|
def table_for identifier
|
133
140
|
find_element("table(identifier)", Elements::Table, identifier, 'table')
|
134
141
|
end
|
@@ -222,6 +229,13 @@ module Druid
|
|
222
229
|
find_elements("lis(identifier)", Elements::ListItem, identifier, 'li')
|
223
230
|
end
|
224
231
|
|
232
|
+
#
|
233
|
+
# method to retrieve the text from an ordered list
|
234
|
+
#
|
235
|
+
def ordered_list_text_for(identifier)
|
236
|
+
process_call("ol(identifier).text", Elements::OrderedList, identifier, nil, 'ol')
|
237
|
+
end
|
238
|
+
|
225
239
|
def ordered_list_for identifier
|
226
240
|
find_element("ol(identifier)", Elements::OrderedList, identifier, 'ol')
|
227
241
|
end
|
@@ -250,6 +264,13 @@ module Druid
|
|
250
264
|
find_elements("textareas(identifier)", Elements::TextArea, identifier)
|
251
265
|
end
|
252
266
|
|
267
|
+
#
|
268
|
+
# method to retrieve the text from an unordered list
|
269
|
+
#
|
270
|
+
def unordered_list_text_for(identifier)
|
271
|
+
process_call("ul(identifier).text", Elements::UnOrderedList, identifier, nil, 'ul')
|
272
|
+
end
|
273
|
+
|
253
274
|
def unordered_list_for identifier
|
254
275
|
find_element("ul(identifier)", Elements::UnOrderedList, identifier, 'ul')
|
255
276
|
end
|
data/lib/druid/page_factory.rb
CHANGED
@@ -34,11 +34,14 @@ module Druid
|
|
34
34
|
# Create and navigate to a page object. The navigation will only work if the
|
35
35
|
# 'page_url' method was call on the page object.
|
36
36
|
#
|
37
|
-
# @param [
|
37
|
+
# @param [PageObject, String] a class that has included the Druid module or a string containing the name of the class
|
38
38
|
# @param an optional block to be called
|
39
39
|
# @return [PageObject] the newly created page object
|
40
40
|
#
|
41
|
-
def visit_page(page_class, &block)
|
41
|
+
def visit_page(page_class, params={:using_params => {}}, &block)
|
42
|
+
page_class = class_from_string(page_class) if page_class.is_a? String
|
43
|
+
merged = page_class.params.merge(params[:using_params])
|
44
|
+
page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
|
42
45
|
on_page page_class, true, &block
|
43
46
|
end
|
44
47
|
|
@@ -47,12 +50,13 @@ module Druid
|
|
47
50
|
#
|
48
51
|
# Create a page object.
|
49
52
|
#
|
50
|
-
# @param [
|
53
|
+
# @param [PageObject, String] a class that has included the Druid module or a string containing the name of the class
|
51
54
|
# @param [Bool] should the page be visited? default is false.
|
52
55
|
# @param an optional block to be called
|
53
56
|
# @return [PageObject] the newly created page object
|
54
57
|
#
|
55
58
|
def on_page(page_class, visit=false, &block)
|
59
|
+
page_class = class_from_string(page_class) if page_class.is_a? String
|
56
60
|
@current_page = page_class.new(@driver, visit)
|
57
61
|
block.call @current_page if block
|
58
62
|
@current_page
|
@@ -73,12 +77,13 @@ module Druid
|
|
73
77
|
# page.save
|
74
78
|
# end
|
75
79
|
# if_page EditProduct do |page|
|
76
|
-
# page.update
|
80
|
+
# page.update
|
77
81
|
# end
|
78
|
-
# @param [PageObject] a class that has included the Druid module
|
82
|
+
# @param [PageObject, String] a class that has included the Druid module or a string containing the name of the class
|
79
83
|
# @param [block] an optional block to be called
|
80
84
|
# @return [PageObject] the newly created page object
|
81
85
|
def if_page(page_class, &block)
|
86
|
+
page_class = class_from_string(page_class) if page_class.is_a? String
|
82
87
|
return @current_page unless @current_page.class == page_class
|
83
88
|
on_page(page_class, false, &block)
|
84
89
|
end
|
@@ -136,6 +141,12 @@ module Druid
|
|
136
141
|
|
137
142
|
private
|
138
143
|
|
144
|
+
def class_from_string(str)
|
145
|
+
str.split('::').inject(Object) do |mod, class_name|
|
146
|
+
mod.const_get(class_name)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
139
150
|
def path_for(how)
|
140
151
|
path = Druid::PageFactory.page_object_routes[how[:using]]
|
141
152
|
fail("PageFactory route :#{how[:using].to_s} not found") unless path
|
data/lib/druid/version.rb
CHANGED
@@ -149,12 +149,18 @@ describe Druid::Accessors do
|
|
149
149
|
class SymbolPageUrl
|
150
150
|
include Druid
|
151
151
|
page_url :custom_url
|
152
|
-
|
153
|
-
|
152
|
+
|
153
|
+
attr_reader :custom_url
|
154
|
+
|
155
|
+
def initialize(d, v, url)
|
156
|
+
@custom_url = url
|
157
|
+
super(d, v)
|
154
158
|
end
|
155
159
|
end
|
156
160
|
expect(driver).to receive(:goto).with("custom")
|
157
|
-
SymbolPageUrl.new(driver, true)
|
161
|
+
SymbolPageUrl.new(driver, true, 'custom')
|
162
|
+
expect(driver).to receive(:goto).with('different')
|
163
|
+
SymbolPageUrl.new(driver, true, 'different')
|
158
164
|
end
|
159
165
|
|
160
166
|
it "should not navigate to a page when not requested" do
|
data/spec/druid/druid_spec.rb
CHANGED
@@ -8,6 +8,68 @@ describe Druid do
|
|
8
8
|
let(:driver) { mock_driver }
|
9
9
|
let(:druid) { TestDruid.new(driver) }
|
10
10
|
|
11
|
+
context "setting values on the Druid module" do
|
12
|
+
it "should set the javascript framework" do
|
13
|
+
expect(Druid::JavascriptFrameworkFacade).to receive(:framework=)
|
14
|
+
Druid.javascript_framework = :foo
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should add the javascript framework" do
|
18
|
+
expect(Druid::JavascriptFrameworkFacade).to receive(:add_framework)
|
19
|
+
Druid.add_framework(:foo, :bar)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set a default page wait value" do
|
23
|
+
Druid.default_page_wait = 20
|
24
|
+
wait = Druid.instance_variable_get("@page_wait")
|
25
|
+
expect(wait).to eql 20
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should provide the default page wait value" do
|
29
|
+
Druid.instance_variable_set("@page_wait", 10)
|
30
|
+
expect(Druid.default_page_wait).to eql 10
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should default the page wait value to 30" do
|
34
|
+
Druid.instance_variable_set("@page_wait", nil)
|
35
|
+
expect(Druid.default_page_wait).to eql 30
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set the default element wait value" do
|
39
|
+
Druid.default_element_wait = 20
|
40
|
+
wait = Druid.instance_variable_get("@element_wait")
|
41
|
+
expect(wait).to eql 20
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should provide the default element wait value" do
|
45
|
+
Druid.instance_variable_set("@element_wait", 10)
|
46
|
+
expect(Druid.default_element_wait).to eql 10
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should default the element wait to 5" do
|
50
|
+
Druid.instance_variable_set("@element_wait", nil)
|
51
|
+
expect(Druid.default_element_wait).to eql 5
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "setting values on the Druid class instance" do
|
56
|
+
it "should set the params value" do
|
57
|
+
TestDruid.params = {:some => :value}
|
58
|
+
params = TestDruid.instance_variable_get("@params")
|
59
|
+
expect(params[:some]).to eql :value
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should provide the params value" do
|
63
|
+
TestDruid.instance_variable_set("@params", {:value => :updated})
|
64
|
+
expect(TestDruid.params[:value]).to eql :updated
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should default the params to an empty hash" do
|
68
|
+
TestDruid.instance_variable_set("@params", nil)
|
69
|
+
expect(TestDruid.params).to eql Hash.new
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
11
73
|
context "when created with a watir-webdriver browser" do
|
12
74
|
it "should include the Druid module" do
|
13
75
|
expect(druid).to be_kind_of Druid
|
@@ -127,15 +189,47 @@ describe Druid do
|
|
127
189
|
it "should call intialize_page if it exists" do
|
128
190
|
class CallbackPage
|
129
191
|
include Druid
|
130
|
-
attr_reader :
|
192
|
+
attr_reader :initialize_page_called
|
131
193
|
|
132
194
|
def initialize_page
|
133
|
-
@
|
195
|
+
@initialize_page_called = true
|
134
196
|
end
|
135
197
|
end
|
136
198
|
|
137
199
|
page = CallbackPage.new(driver)
|
138
|
-
expect(page.
|
200
|
+
expect(page.initialize_page_called).to be true
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should call initialize_accessors if it exists" do
|
204
|
+
class CallbackPage
|
205
|
+
include Druid
|
206
|
+
attr_reader :initialize_accessors_called
|
207
|
+
|
208
|
+
def initialize_accessors
|
209
|
+
@initialize_accessors_called = true
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
@page = CallbackPage.new(driver)
|
214
|
+
expect(@page.initialize_accessors_called).to be true
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should call initialize_accessors before initialize_page if both exist" do
|
218
|
+
class CallbackPage
|
219
|
+
include Druid
|
220
|
+
attr_reader :initialize_page, :initialize_accessors
|
221
|
+
|
222
|
+
def initialize_page
|
223
|
+
@initialize_page = Time.now
|
224
|
+
end
|
225
|
+
|
226
|
+
def initialize_accessors
|
227
|
+
@initialize_accessors = Time.now
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
@page = CallbackPage.new(driver)
|
232
|
+
expect(@page.initialize_accessors.usec).to be < @page.initialize_page.usec
|
139
233
|
end
|
140
234
|
|
141
235
|
it "should convert a modal popup to a window" do
|
@@ -166,16 +260,6 @@ describe Druid do
|
|
166
260
|
druid.wait_for_ajax
|
167
261
|
end
|
168
262
|
|
169
|
-
it "should set the javascript framework" do
|
170
|
-
expect(Druid::JavascriptFrameworkFacade).to receive(:framework=)
|
171
|
-
Druid.javascript_framework = :foo
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should add the javascript framework" do
|
175
|
-
expect(Druid::JavascriptFrameworkFacade).to receive(:add_framework)
|
176
|
-
Druid.add_framework(:foo, :bar)
|
177
|
-
end
|
178
|
-
|
179
263
|
it "should execute javascript on the browser" do
|
180
264
|
expect(driver).to receive(:execute_script).and_return("abc")
|
181
265
|
expect(druid.execute_script("333")).to eql "abc"
|
@@ -15,6 +15,7 @@ describe Druid::Elements::TableRow do
|
|
15
15
|
let(:table_row) { Druid::Elements::TableRow.new(element) }
|
16
16
|
|
17
17
|
it "should return a table cell when indexed" do
|
18
|
+
allow(table_row).to receive(:columns).and_return(2)
|
18
19
|
expect(element).to receive(:[]).with(1)
|
19
20
|
expect(table_row[1]).to be_instance_of Druid::Elements::TableCell
|
20
21
|
end
|
@@ -19,6 +19,13 @@ class YetAnotherPage
|
|
19
19
|
include Druid
|
20
20
|
end
|
21
21
|
|
22
|
+
module ContainingModule
|
23
|
+
class PageInsideModule
|
24
|
+
include Druid
|
25
|
+
page_url "http://google.co.uk"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
22
29
|
class TestWorld
|
23
30
|
include Druid::PageFactory
|
24
31
|
|
@@ -26,7 +33,6 @@ class TestWorld
|
|
26
33
|
attr_accessor :current_page
|
27
34
|
end
|
28
35
|
|
29
|
-
|
30
36
|
describe Druid::PageFactory do
|
31
37
|
|
32
38
|
let(:world) { TestWorld.new }
|
@@ -40,6 +46,12 @@ describe Druid::PageFactory do
|
|
40
46
|
world.on_page FactoryTestDruid do |page|
|
41
47
|
expect(page).to be_instance_of FactoryTestDruid
|
42
48
|
end
|
49
|
+
world.on_page "FactoryTestDruid" do |page|
|
50
|
+
expect(page).to be_instance_of FactoryTestDruid
|
51
|
+
end
|
52
|
+
world.on_page "ContainingModule::PageInsideModule" do |page|
|
53
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
54
|
+
end
|
43
55
|
end
|
44
56
|
|
45
57
|
it "should create a new page object and execute a block using 'on'" do
|
@@ -47,20 +59,65 @@ describe Druid::PageFactory do
|
|
47
59
|
world.on FactoryTestDruid do |page|
|
48
60
|
expect(page).to be_instance_of FactoryTestDruid
|
49
61
|
end
|
62
|
+
world.on "FactoryTestDruid" do |page|
|
63
|
+
expect(page).to be_instance_of FactoryTestDruid
|
64
|
+
end
|
65
|
+
world.on "ContainingModule::PageInsideModule" do |page|
|
66
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
67
|
+
end
|
50
68
|
end
|
51
69
|
|
52
70
|
it "should create and visit a new page" do
|
53
|
-
expect(driver).to receive(:goto)
|
71
|
+
expect(driver).to receive(:goto).exactly(3).times
|
54
72
|
world.visit_page FactoryTestDruid do |page|
|
55
73
|
expect(page).to be_instance_of FactoryTestDruid
|
56
74
|
end
|
75
|
+
world.visit_page "FactoryTestDruid" do |page|
|
76
|
+
expect(page).to be_instance_of FactoryTestDruid
|
77
|
+
end
|
78
|
+
world.visit_page "ContainingModule::PageInsideModule" do |page|
|
79
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
80
|
+
end
|
57
81
|
end
|
58
82
|
|
59
|
-
it "should
|
83
|
+
it "should merge params with the class level params if provided when visiting" do
|
60
84
|
expect(driver).to receive(:goto)
|
85
|
+
FactoryTestDruid.params = {:initial => :value}
|
86
|
+
world.visit_page(FactoryTestDruid, :using_params => {:new_value => :merged})
|
87
|
+
merged = FactoryTestDruid.instance_variable_get("@merged_params")
|
88
|
+
expect(merged[:initial]).to eql :value
|
89
|
+
expect(merged[:new_value]).to eql :merged
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should use the params in the url when they are provided" do
|
93
|
+
class PageUsingParams
|
94
|
+
include Druid
|
95
|
+
page_url "http://google.com/<%=params[:value]%>"
|
96
|
+
end
|
97
|
+
expect(driver).to receive(:goto).with("http://google.com/Druid")
|
98
|
+
world.visit_page(PageUsingParams, :using_params => {:value => 'Druid'})
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should use the params as well as interpolated values" do
|
102
|
+
class PageUsingParamsAndInterpolated
|
103
|
+
include Druid
|
104
|
+
page_url "http://google.com/#{1+2}/<%=params[:value]%>"
|
105
|
+
end
|
106
|
+
expect(driver).to receive(:goto).with("http://google.com/3/Druid")
|
107
|
+
world.visit_page(PageUsingParamsAndInterpolated, :using_params => {:value => 'Druid'})
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should create and visit a new page using 'visit'" do
|
111
|
+
expect(driver).to receive(:goto).exactly(3).times
|
61
112
|
world.visit FactoryTestDruid do |page|
|
62
113
|
expect(page).to be_instance_of FactoryTestDruid
|
63
114
|
end
|
115
|
+
world.visit "FactoryTestDruid" do |page|
|
116
|
+
expect(page).to be_instance_of FactoryTestDruid
|
117
|
+
end
|
118
|
+
world.visit "ContainingModule::PageInsideModule" do |page|
|
119
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
120
|
+
end
|
64
121
|
end
|
65
122
|
|
66
123
|
it "should create and visit a new page when url is defined as 'direct_url'" do
|
@@ -82,20 +139,44 @@ describe Druid::PageFactory do
|
|
82
139
|
world.if_page(FactoryTestDruid) do |page|
|
83
140
|
fail
|
84
141
|
end
|
142
|
+
world.if_page("FactoryTestDruid") do |page|
|
143
|
+
fail
|
144
|
+
end
|
145
|
+
world.if_page("ContainingModule::PageInsideModule") do |page|
|
146
|
+
fail
|
147
|
+
end
|
85
148
|
end
|
86
149
|
|
87
150
|
it "should return the @current_page if asking for another page" do
|
88
151
|
expected = TestPageWithDirectUrl.new(driver)
|
89
152
|
world.instance_variable_set "@current_page", expected
|
90
153
|
expect(world.if_page(FactoryTestDruid)).to be expected
|
154
|
+
expect(world.if_page("FactoryTestDruid")).to be expected
|
155
|
+
expect(world.if_page("ContainingModule::PageInsideModule")).to be expected
|
91
156
|
end
|
92
157
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
158
|
+
it "should execute the block when we ask if it is the correct page" do
|
159
|
+
world.instance_variable_set "@current_page", FactoryTestDruid.new(driver)
|
160
|
+
done = false
|
161
|
+
world.if_page(FactoryTestDruid) do |page|
|
162
|
+
expect(page).to be_instance_of FactoryTestDruid
|
163
|
+
done = true
|
164
|
+
end
|
165
|
+
expect(done).to be true
|
166
|
+
done = false
|
167
|
+
world.if_page("FactoryTestDruid") do |page|
|
168
|
+
expect(page).to be_instance_of FactoryTestDruid
|
169
|
+
done = true
|
170
|
+
end
|
171
|
+
expect(done).to be true
|
172
|
+
done = false
|
173
|
+
world.instance_variable_set "@current_page", ContainingModule::PageInsideModule.new(driver)
|
174
|
+
world.if_page("ContainingModule::PageInsideModule") do |page|
|
175
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
176
|
+
done = true
|
177
|
+
end
|
178
|
+
expect(done).to be true
|
179
|
+
end
|
99
180
|
|
100
181
|
it "should raise an error when you do not provide a default route" do
|
101
182
|
expect { Druid::PageFactory.routes = {:another => []} }.to raise_error 'You must provide a :default route for PageFactory routes'
|
data/spec/spec_helper.rb
CHANGED