edsl-pageobject 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/lib/edsl/page_object.rb +1 -0
- data/lib/edsl/page_object/ajax_support.rb +100 -0
- data/lib/edsl/page_object/javascript/angularjs.rb +16 -0
- data/lib/edsl/page_object/javascript/jquery.rb +16 -0
- data/lib/edsl/page_object/javascript/prototype.rb +16 -0
- data/lib/edsl/page_object/javascript/yui.rb +21 -0
- data/lib/edsl/page_object/page.rb +1 -0
- data/lib/edsl/page_object/population.rb +6 -2
- data/lib/edsl/page_object/section.rb +4 -2
- data/lib/edsl/page_object/version.rb +1 -1
- data/lib/edsl/page_object/visitation.rb +5 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44d3414e16ec1b3da3c9f0ca13363af44a345cbe3372640a4ed572e50b7337bb
|
4
|
+
data.tar.gz: ef97de15b9cba8623ba435959f6d58fc30e5e632313dc91a46b9740f96147bff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af4fde4408312d0d71321f186e026ac9f50c70b6caa3a994af48b35ecd3483b650f060a05bd25d6a5d46bbb089431edcd7ef71135b6eb06080002786959b00fd
|
7
|
+
data.tar.gz: 6541f0649773eab4b9646b95f54d468c46cc40806fe3cbdfde6e6493f1fad4c4fe1474f9b665df93d4fadba76e1b2bc990f60f3c2103893df01974137d3475d4
|
data/lib/edsl/page_object.rb
CHANGED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'edsl/page_object/javascript/jquery'
|
2
|
+
require 'edsl/page_object/javascript/prototype'
|
3
|
+
require 'edsl/page_object/javascript/yui'
|
4
|
+
require 'edsl/page_object/javascript/angularjs'
|
5
|
+
|
6
|
+
module EDSL
|
7
|
+
module PageObject
|
8
|
+
# Provide hooks into different common Javascript Frameworks.
|
9
|
+
# Currently this module only supports jQuery and Prototype but it
|
10
|
+
# has the ability for you to plug your own framework into it and
|
11
|
+
# therefore have it work with this gem. You do this by calling the
|
12
|
+
# #add_framework method. The module you provide must implement the
|
13
|
+
# necessary methods. Please look at the jQuery or Prototype
|
14
|
+
# implementations to determine the necessary methods
|
15
|
+
#
|
16
|
+
module JavascriptFrameworkFacade
|
17
|
+
|
18
|
+
class << self
|
19
|
+
#
|
20
|
+
# Set the framework to use.
|
21
|
+
#
|
22
|
+
# @param[Symbol] the framework to use. :jquery, :prototype, :yui,
|
23
|
+
# and :angularjs are supported
|
24
|
+
#
|
25
|
+
def framework=(framework)
|
26
|
+
initialize_script_builder unless @builder
|
27
|
+
raise unknown_framework(framework) unless @builder[framework]
|
28
|
+
@framework = framework
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Get the framework that will be used
|
33
|
+
#
|
34
|
+
def framework
|
35
|
+
@framework
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Add a framework and make it available to the system.
|
40
|
+
#
|
41
|
+
def add_framework(key, value)
|
42
|
+
raise invalid_framework unless value.respond_to? :pending_requests
|
43
|
+
initialize_script_builder unless @builder
|
44
|
+
@builder[key] = value
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# get the javascript to determine number of pending requests
|
49
|
+
#
|
50
|
+
def pending_requests
|
51
|
+
script_builder.pending_requests
|
52
|
+
end
|
53
|
+
|
54
|
+
def script_builder
|
55
|
+
initialize_script_builder unless @builder
|
56
|
+
@builder[@framework]
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def initialize_script_builder
|
62
|
+
@builder = {
|
63
|
+
:jquery => ::EDSL::PageObject::Javascript::JQuery,
|
64
|
+
:prototype => ::EDSL::PageObject::Javascript::Prototype,
|
65
|
+
:yui => ::EDSL::PageObject::Javascript::YUI,
|
66
|
+
:angularjs => ::EDSL::PageObject::Javascript::AngularJS
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def unknown_framework(framework)
|
71
|
+
"You specified the Javascript framework #{framework} and it is unknown to the system"
|
72
|
+
end
|
73
|
+
|
74
|
+
def invalid_framework
|
75
|
+
"The Javascript framework you provided does not implement the necessary methods"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
module AJAX
|
81
|
+
#
|
82
|
+
# Wait until there are no pending ajax requests. This requires you
|
83
|
+
# to set the javascript framework in advance.
|
84
|
+
#
|
85
|
+
# @param [Numeric] the amount of time to wait for the block to return true.
|
86
|
+
# @param [String] the message to include with the error if we exceed
|
87
|
+
# the timeout duration.
|
88
|
+
#
|
89
|
+
def wait_for_ajax(timeout = 30, message = nil)
|
90
|
+
end_time = ::Time.now + timeout
|
91
|
+
until ::Time.now > end_time
|
92
|
+
return if browser.execute_script(::EDSL::PageObject::JavascriptFrameworkFacade.pending_requests) == 0
|
93
|
+
sleep 0.5
|
94
|
+
end
|
95
|
+
message = "Timed out waiting for ajax requests to complete" unless message
|
96
|
+
raise message
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module EDSL
|
2
|
+
module PageObject
|
3
|
+
module Javascript
|
4
|
+
|
5
|
+
module AngularJS
|
6
|
+
#
|
7
|
+
# return the number of pending ajax requests
|
8
|
+
#
|
9
|
+
def self.pending_requests
|
10
|
+
'return angular.element(document.body).injector().get(\'$http\').pendingRequests.length;'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EDSL
|
2
|
+
module PageObject
|
3
|
+
module Javascript
|
4
|
+
|
5
|
+
module YUI
|
6
|
+
#
|
7
|
+
# return the number of pending ajax requests
|
8
|
+
#
|
9
|
+
def self.pending_requests
|
10
|
+
"var inProgress=0
|
11
|
+
for(var i=0; i < YAHOO.util.Connect._transaction_id; i++) {
|
12
|
+
if(YAHOO.util.Connect.isCallInProgress(i))
|
13
|
+
inProgress++;
|
14
|
+
}
|
15
|
+
return inProgress;"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -22,14 +22,14 @@ module EDSL
|
|
22
22
|
|
23
23
|
# Returns the currently defined fixture fetch function or a lambda that returns nil
|
24
24
|
def self.fixture_fetcher
|
25
|
-
@@fixture_fetcher
|
25
|
+
@@fixture_fetcher ||= lambda { |_key| nil }
|
26
26
|
end
|
27
27
|
|
28
28
|
# Fetch a value from our fixtures using a key.
|
29
29
|
#
|
30
30
|
# @param key [String, Symbol] What to fetch
|
31
31
|
def fixture_fetch(key)
|
32
|
-
ff = fixture_fetcher
|
32
|
+
ff = EDSL::PageObject::Population.fixture_fetcher
|
33
33
|
return ff.call(key) if ff.is_a?(Proc)
|
34
34
|
send(ff, key)
|
35
35
|
end
|
@@ -65,6 +65,10 @@ module EDSL
|
|
65
65
|
def populate_key
|
66
66
|
self.class.to_s.snakecase
|
67
67
|
end
|
68
|
+
|
69
|
+
def populate
|
70
|
+
populate_with(fixture_fetch(populate_key))
|
71
|
+
end
|
68
72
|
end
|
69
73
|
end
|
70
74
|
end
|
@@ -9,6 +9,8 @@ module EDSL
|
|
9
9
|
#
|
10
10
|
class Section < ElementContainer
|
11
11
|
include EDSL::PageObject::Population
|
12
|
+
include EDSL::PageObject::AJAX
|
13
|
+
|
12
14
|
# Create a new section
|
13
15
|
def initialize(element, parent)
|
14
16
|
super(element, parent)
|
@@ -35,8 +37,8 @@ module EDSL
|
|
35
37
|
|
36
38
|
def sections(name, section_class, opts)
|
37
39
|
i_sel = opts.delete(:item)
|
38
|
-
item_how = i_sel.delete(:how)
|
39
|
-
default_method = lambda { |_name, container| container.send(item_how, i_sel).map { |i| section_class.new(i, self) } }
|
40
|
+
item_how = i_sel.delete(:how) || :divs
|
41
|
+
default_method = lambda { |_name, container| container.send("#{name}_element").send(item_how, i_sel).map { |i| section_class.new(i, self) } }
|
40
42
|
element(name, { how: :div,
|
41
43
|
default_method: default_method }.merge(opts))
|
42
44
|
end
|
@@ -29,7 +29,6 @@ module EDSL
|
|
29
29
|
erb = ::ERB.new(%Q{#{lookup}})
|
30
30
|
merged_params = self.class.instance_variable_get("@merged_params")
|
31
31
|
params = merged_params ? merged_params : self.class.params
|
32
|
-
binding.pry
|
33
32
|
erb.result(binding)
|
34
33
|
end
|
35
34
|
end
|
@@ -79,6 +78,11 @@ module EDSL
|
|
79
78
|
# Support 'on' for readability of usage
|
80
79
|
alias_method :on, :on_page
|
81
80
|
|
81
|
+
def on_current_page(&block)
|
82
|
+
yield @current_page if block
|
83
|
+
@current_page
|
84
|
+
end
|
85
|
+
|
82
86
|
#
|
83
87
|
# Create a page object if and only if the current page is the same page to be created
|
84
88
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edsl-pageobject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Donavan Stanley
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,6 +157,11 @@ files:
|
|
157
157
|
- edsl-pageobject.gemspec
|
158
158
|
- examples/google_search
|
159
159
|
- lib/edsl/page_object.rb
|
160
|
+
- lib/edsl/page_object/ajax_support.rb
|
161
|
+
- lib/edsl/page_object/javascript/angularjs.rb
|
162
|
+
- lib/edsl/page_object/javascript/jquery.rb
|
163
|
+
- lib/edsl/page_object/javascript/prototype.rb
|
164
|
+
- lib/edsl/page_object/javascript/yui.rb
|
160
165
|
- lib/edsl/page_object/page.rb
|
161
166
|
- lib/edsl/page_object/population.rb
|
162
167
|
- lib/edsl/page_object/section.rb
|