site_prism 1.1.1 → 1.2
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/README.md +95 -3
- data/lib/site_prism/element_container.rb +23 -13
- data/lib/site_prism/version.rb +1 -1
- metadata +21 -9
data/README.md
CHANGED
@@ -917,20 +917,112 @@ end
|
|
917
917
|
@results_page.wait_for_search_results(10) #=> waits for 10 seconds instead of the default capybara timeout
|
918
918
|
```
|
919
919
|
|
920
|
+
## IFrames
|
921
|
+
|
922
|
+
SitePrism allows you to interact with iframes. An iframe is declared as
|
923
|
+
a `SitePrism::Page` class, and then referenced by the page or section it
|
924
|
+
is embeded into. Like a section, it is possible to test for the
|
925
|
+
existence of the iframe, wait for it to exist as well as interact with
|
926
|
+
the page it contains.
|
927
|
+
|
928
|
+
### Creating an iframe
|
929
|
+
|
930
|
+
An iframe is declared in the same way as a Page:
|
931
|
+
|
932
|
+
```ruby
|
933
|
+
class MyIframe < SitePrism::Page
|
934
|
+
element :some_text_field, "input.username"
|
935
|
+
end
|
936
|
+
```
|
937
|
+
|
938
|
+
To expose the iframe, reference it from another page or class using the `iframe`
|
939
|
+
method. The `iframe` method takes 3 arguments; the name by which you
|
940
|
+
would like to reference the iframe, the page class that represents the
|
941
|
+
iframe, and an ID by which you can locate the iframe. For example:
|
942
|
+
|
943
|
+
```ruby
|
944
|
+
class PageContainingIframe < SitePrism::Page
|
945
|
+
iframe :my_iframe, MyIframe, "#my_iframe_id"
|
946
|
+
end
|
947
|
+
```
|
948
|
+
|
949
|
+
NB: An iframe can only be referenced by its ID. This is a limitation
|
950
|
+
imposed by Capybara. The third argument to the `iframe` method must
|
951
|
+
contain a selector that will locate the iframe node, and the portion of
|
952
|
+
the selector that locates the iframe node must use the iframe node's ID.
|
953
|
+
|
954
|
+
### Testing for an iframe's existence
|
955
|
+
|
956
|
+
Like an element or section, it is possible to test for an iframe's
|
957
|
+
existence using the auto-generated `has_<iframe_name>?` method. Using
|
958
|
+
the above example, here's how it's done:
|
959
|
+
|
960
|
+
```ruby
|
961
|
+
@page = PageContainingIframe.new
|
962
|
+
# ...
|
963
|
+
@page.has_my_iframe? #=> true
|
964
|
+
@page.should have_my_iframe
|
965
|
+
```
|
966
|
+
|
967
|
+
### Waiting for an iframe
|
968
|
+
|
969
|
+
Like an element or section, it is possible to wait for an iframe to
|
970
|
+
exist by using the `wait_for_<iframe_name>` method. For example:
|
971
|
+
|
972
|
+
```ruby
|
973
|
+
@page = PageContainingIframe.new
|
974
|
+
# ...
|
975
|
+
@page.wait_for_my_iframe
|
976
|
+
```
|
977
|
+
|
978
|
+
### Interacting with an iframe's contents:
|
979
|
+
|
980
|
+
Since an iframe contains a fully fledged SitePrism::Page, you are able
|
981
|
+
to interact with the elements and sections defined within it. Due to
|
982
|
+
capybara internals it is necessary to pass a block to the iframe instead
|
983
|
+
of simply calling methods on it; the block argument is the
|
984
|
+
SitePrism::Page that represents the iframe's contents. For example:
|
985
|
+
|
986
|
+
```ruby
|
987
|
+
# SitePrism::Page representing the iframe
|
988
|
+
class Login < SitePrism::Page
|
989
|
+
element :username "input.username"
|
990
|
+
element :password "input.password"
|
991
|
+
end
|
992
|
+
|
993
|
+
# SitePrism::Page representing the page that contains the iframe
|
994
|
+
class Home < SitePrism::Page
|
995
|
+
set_url "http://www.example.com"
|
996
|
+
|
997
|
+
iframe, :login_area, Login, "#login_and_registration"
|
998
|
+
end
|
999
|
+
|
1000
|
+
# cucumber step that performs login
|
1001
|
+
When /^I log in$/ do
|
1002
|
+
@home = Home.new
|
1003
|
+
@home.load
|
1004
|
+
|
1005
|
+
@home.login_area do |frame|
|
1006
|
+
#`frame` is an instance of the `Login` class
|
1007
|
+
frame.username.set "admin"
|
1008
|
+
frame.password.set "p4ssword"
|
1009
|
+
end
|
1010
|
+
end
|
1011
|
+
```
|
920
1012
|
|
921
1013
|
# Epilogue
|
922
1014
|
|
923
1015
|
So, we've seen how to use SitePrism to put together page objects made up
|
924
|
-
of pages, elements and
|
1016
|
+
of pages, elements, sections and iframes. But how to organise this stuff? There
|
925
1017
|
are a few ways of saving yourself having to create instances of pages
|
926
1018
|
all over the place. Here's an example of this common problem:
|
927
1019
|
|
928
1020
|
```ruby
|
929
|
-
@home = Home.new
|
1021
|
+
@home = Home.new # <-- noise
|
930
1022
|
@home.load
|
931
1023
|
@home.search_field.set "Sausages"
|
932
1024
|
@home.search_field.search_button.click
|
933
|
-
@results_page = SearchResults.new
|
1025
|
+
@results_page = SearchResults.new # <-- noise
|
934
1026
|
@results_page.should have_search_result_items
|
935
1027
|
```
|
936
1028
|
|
@@ -2,9 +2,7 @@ module SitePrism::ElementContainer
|
|
2
2
|
|
3
3
|
def element element_name, element_locator = nil
|
4
4
|
if element_locator.nil?
|
5
|
-
|
6
|
-
raise SitePrism::NoLocatorForElement.new("#{self.class.name} => :#{element_name} needs a locator")
|
7
|
-
end
|
5
|
+
create_no_locator element_name
|
8
6
|
else
|
9
7
|
add_element_name element_name.to_s
|
10
8
|
define_method element_name.to_s do
|
@@ -17,9 +15,7 @@ module SitePrism::ElementContainer
|
|
17
15
|
|
18
16
|
def elements collection_name, collection_locator = nil
|
19
17
|
if collection_locator.nil?
|
20
|
-
|
21
|
-
raise SitePrism::NoLocatorForElement.new("#{self.class.name} => :#{element_name} needs a locator")
|
22
|
-
end
|
18
|
+
create_no_locator collection_name
|
23
19
|
else
|
24
20
|
add_element_name collection_name
|
25
21
|
define_method collection_name.to_s do
|
@@ -51,6 +47,17 @@ module SitePrism::ElementContainer
|
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
50
|
+
def iframe iframe_name, iframe_page_class, iframe_id
|
51
|
+
add_element_name iframe_name
|
52
|
+
create_existence_checker iframe_name, iframe_id
|
53
|
+
create_waiter iframe_name, iframe_id
|
54
|
+
define_method iframe_name do |&block|
|
55
|
+
within_frame iframe_id.split("#").last do
|
56
|
+
block.call iframe_page_class.new
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
54
61
|
def add_element_name element_name
|
55
62
|
@element_names ||= []
|
56
63
|
@element_names << element_name
|
@@ -65,9 +72,7 @@ module SitePrism::ElementContainer
|
|
65
72
|
def create_existence_checker element_name, element_locator
|
66
73
|
method_name = "has_#{element_name.to_s}?"
|
67
74
|
if element_locator.nil?
|
68
|
-
|
69
|
-
raise SitePrism::NoLocatorForElement.new("#{self.class.name} => :#{element_name} needs a locator")
|
70
|
-
end
|
75
|
+
create_no_locator element_name, method_name
|
71
76
|
else
|
72
77
|
define_method method_name do
|
73
78
|
Capybara.using_wait_time 0 do
|
@@ -80,11 +85,9 @@ module SitePrism::ElementContainer
|
|
80
85
|
def create_waiter element_name, element_locator
|
81
86
|
method_name = "wait_for_#{element_name.to_s}"
|
82
87
|
if element_locator.nil?
|
83
|
-
|
84
|
-
raise SitePrism::NoLocatorForElement.new("#{self.class.name} => :#{element_name} needs a locator")
|
85
|
-
end
|
88
|
+
create_no_locator element_name, method_name
|
86
89
|
else
|
87
|
-
define_method method_name do |*args|
|
90
|
+
define_method method_name do |*args| #used to use block args, but they don't work under ruby 1.8 :(
|
88
91
|
timeout = args.shift || Capybara.default_wait_time
|
89
92
|
Capybara.using_wait_time timeout do
|
90
93
|
element_waiter element_locator
|
@@ -92,5 +95,12 @@ module SitePrism::ElementContainer
|
|
92
95
|
end
|
93
96
|
end
|
94
97
|
end
|
98
|
+
|
99
|
+
def create_no_locator element_name, method_name = nil
|
100
|
+
no_locator_method_name = method_name.nil? ? element_name : method_name
|
101
|
+
define_method no_locator_method_name do
|
102
|
+
raise SitePrism::NoLocatorForElement.new("#{self.class.name} => :#{element_name} needs a locator")
|
103
|
+
end
|
104
|
+
end
|
95
105
|
end
|
96
106
|
|
data/lib/site_prism/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_prism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 2
|
8
|
+
version: "1.2"
|
6
9
|
platform: ruby
|
7
10
|
authors:
|
8
11
|
- Nat Ritmeyer
|
@@ -10,16 +13,20 @@ autorequire:
|
|
10
13
|
bindir: bin
|
11
14
|
cert_chain: []
|
12
15
|
|
13
|
-
date: 2012-
|
16
|
+
date: 2012-07-02 00:00:00 +01:00
|
17
|
+
default_executable:
|
14
18
|
dependencies:
|
15
19
|
- !ruby/object:Gem::Dependency
|
16
20
|
name: capybara
|
17
21
|
prerelease: false
|
18
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
23
|
requirements:
|
21
24
|
- - ">="
|
22
25
|
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 1
|
28
|
+
- 1
|
29
|
+
- 1
|
23
30
|
version: 1.1.1
|
24
31
|
type: :runtime
|
25
32
|
version_requirements: *id001
|
@@ -27,10 +34,13 @@ dependencies:
|
|
27
34
|
name: rspec
|
28
35
|
prerelease: false
|
29
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
-
none: false
|
31
37
|
requirements:
|
32
38
|
- - ">="
|
33
39
|
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 2
|
42
|
+
- 0
|
43
|
+
- 0
|
34
44
|
version: 2.0.0
|
35
45
|
type: :runtime
|
36
46
|
version_requirements: *id002
|
@@ -53,6 +63,7 @@ files:
|
|
53
63
|
- lib/site_prism.rb
|
54
64
|
- LICENSE
|
55
65
|
- README.md
|
66
|
+
has_rdoc: true
|
56
67
|
homepage: http://github.com/natritmeyer/site_prism
|
57
68
|
licenses: []
|
58
69
|
|
@@ -62,24 +73,25 @@ rdoc_options: []
|
|
62
73
|
require_paths:
|
63
74
|
- lib
|
64
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
76
|
requirements:
|
67
77
|
- - ">="
|
68
78
|
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
69
81
|
version: "0"
|
70
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
83
|
requirements:
|
73
84
|
- - ">="
|
74
85
|
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
75
88
|
version: "0"
|
76
89
|
requirements: []
|
77
90
|
|
78
91
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 1.3.6
|
80
93
|
signing_key:
|
81
94
|
specification_version: 3
|
82
95
|
summary: A Page Object Model DSL for Capybara
|
83
96
|
test_files: []
|
84
97
|
|
85
|
-
has_rdoc:
|