druid-ts 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/ChangeLog +15 -0
- data/Gemfile +1 -0
- data/druid.gemspec +1 -0
- data/features/button.feature +2 -1
- data/features/checkbox.feature +2 -1
- data/features/div.feature +2 -1
- data/features/element.feature +2 -0
- data/features/file_field.feature +2 -1
- data/features/form.feature +2 -1
- data/features/hidden_field.feature +2 -1
- data/features/html/nested_elements.html +20 -0
- data/features/image.feature +2 -1
- data/features/javascript.feature +13 -0
- data/features/link.feature +1 -1
- data/features/list_item.feature +2 -1
- data/features/nested_elements.feature +12 -0
- data/features/ordered_list.feature +2 -1
- data/features/paragraph.feature +2 -1
- data/features/radio_button.feature +2 -1
- data/features/sample-app/public/jquery-1.3.2.js +4376 -0
- data/features/sample-app/public/jquery.html +28 -0
- data/features/sample-app/public/prototype-1.6.0.3.js +4320 -0
- data/features/sample-app/public/prototype.html +32 -0
- data/features/sample-app/sample_app.rb +30 -0
- data/features/select_list.feature +13 -1
- data/features/span.feature +2 -1
- data/features/step_definations/button_steps.rb +4 -0
- data/features/step_definations/checkbox_steps.rb +4 -0
- data/features/step_definations/div_steps.rb +4 -0
- data/features/step_definations/element_steps.rb +8 -0
- data/features/step_definations/file_field_steps.rb +4 -0
- data/features/step_definations/form_steps.rb +4 -0
- data/features/step_definations/hidden_field_steps.rb +4 -0
- data/features/step_definations/image_steps.rb +4 -0
- data/features/step_definations/javasript_steps.rb +29 -0
- data/features/step_definations/list_item_steps.rb +4 -0
- data/features/step_definations/nested_elements_steps.rb +15 -0
- data/features/step_definations/ordered_list_steps.rb +4 -0
- data/features/step_definations/paragraph_steps.rb +4 -0
- data/features/step_definations/radio_button_steps.rb +4 -0
- data/features/step_definations/select_list_steps.rb +16 -0
- data/features/step_definations/span_steps.rb +4 -0
- data/features/step_definations/table_cell_steps.rb +4 -0
- data/features/step_definations/table_steps.rb +4 -0
- data/features/step_definations/text_area_steps.rb +4 -0
- data/features/step_definations/text_field_steps.rb +8 -0
- data/features/step_definations/unordered_list_steps.rb +4 -0
- data/features/support/ajax_test_environment.rb +26 -0
- data/features/support/url_helper.rb +1 -0
- data/features/table.feature +2 -1
- data/features/table_cell.feature +2 -1
- data/features/text_area.feature +2 -1
- data/features/text_field.feature +7 -1
- data/features/unordered_list.feature +2 -1
- data/lib/druid.rb +39 -1
- data/lib/druid/accessors.rb +230 -82
- data/lib/druid/elements/element.rb +7 -1
- data/lib/druid/elements/ordered_list.rb +18 -3
- data/lib/druid/elements/select_list.rb +24 -0
- data/lib/druid/elements/text_area.rb +1 -1
- data/lib/druid/elements/text_field.rb +4 -0
- data/lib/druid/elements/unordered_list.rb +18 -3
- data/lib/druid/javascript/jquery.rb +12 -0
- data/lib/druid/javascript/prototype.rb +12 -0
- data/lib/druid/javascript_framework_facade.rb +72 -0
- data/lib/druid/version.rb +1 -1
- data/spec/druid/druid_spec.rb +18 -3
- data/spec/druid/elements/element_spec.rb +5 -0
- data/spec/druid/elements/ordered_list_spec.rb +12 -4
- data/spec/druid/elements/select_list_spec.rb +17 -0
- data/spec/druid/elements/text_area_spec.rb +1 -1
- data/spec/druid/elements/text_field_spec.rb +5 -0
- data/spec/druid/elements/unordered_list_spec.rb +12 -4
- data/spec/druid/javascript_framework_facade_spec.rb +59 -0
- metadata +36 -1
@@ -0,0 +1,32 @@
|
|
1
|
+
<htmL>
|
2
|
+
<head>
|
3
|
+
<title>Prototype - Sample App</title>
|
4
|
+
<script type="application/x-javascript" src="/prototype-1.6.0.3.js"></script>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<div id="ajax-demo">
|
8
|
+
<h2>AJAX Calculator</h2>
|
9
|
+
<form id="calculator-form" action="#" method="post" onSubmit="return false;">
|
10
|
+
<input id="calculator-expression" name="calculator-expression"/>
|
11
|
+
<input type="submit" id="calculator-button" value="Compute" />
|
12
|
+
<br/><br/>
|
13
|
+
<div>Result: <input id="calculator-result" disabled /></div>
|
14
|
+
</form>
|
15
|
+
|
16
|
+
<script type="text/javascript" language="javascript">
|
17
|
+
Event.observe(window, 'load', function() {
|
18
|
+
Event.observe('calculator-button', 'click', function (event) {
|
19
|
+
new Ajax.Request('/compute', {
|
20
|
+
method: 'post',
|
21
|
+
parameters: $('calculator-form').serialize(true),
|
22
|
+
onSuccess: function(transport) {
|
23
|
+
$('calculator-result').value = transport.responseText;
|
24
|
+
},
|
25
|
+
});
|
26
|
+
return false;
|
27
|
+
});
|
28
|
+
});
|
29
|
+
</script>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
</body>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rack'
|
3
|
+
require 'webrick'
|
4
|
+
|
5
|
+
class SampleApp
|
6
|
+
|
7
|
+
def self.start(host, port)
|
8
|
+
Rack::Handler::WEBrick.run(new, :Host => host, :Port => port)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@public = Rack::File.new(File.expand_path("../public", __FILE__))
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
req = Rack::Request.new(env)
|
17
|
+
|
18
|
+
case req.path
|
19
|
+
when "/"
|
20
|
+
[200, {}, ["Sample Application"]]
|
21
|
+
when "/compute"
|
22
|
+
sleep 5
|
23
|
+
resp = eval(req.params['calculator-expression']).to_s
|
24
|
+
[200, {}, [resp]]
|
25
|
+
else
|
26
|
+
@public.call(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -50,4 +50,16 @@ Feature: Select List
|
|
50
50
|
@locator
|
51
51
|
Scenario: Finding a select list dynamically
|
52
52
|
When I find a select list while the script is executing
|
53
|
-
Then I should
|
53
|
+
Then I should see that the select list exists
|
54
|
+
And I should be able to select "Test 2" from the list
|
55
|
+
|
56
|
+
Scenario: Getting the selected option
|
57
|
+
When I select "Test 2" from the select list
|
58
|
+
Then the selected option should be "Test 2"
|
59
|
+
|
60
|
+
Scenario: Determining if a select list includes some options
|
61
|
+
Then the select list should include "Test 2"
|
62
|
+
|
63
|
+
Scenario: It should know if an option is selected
|
64
|
+
When I select "Test 2" from the select list
|
65
|
+
Then the select list should know that "Test 2" is selected
|
data/features/span.feature
CHANGED
@@ -81,3 +81,11 @@ end
|
|
81
81
|
Then(/^I should have a div parent$/) do
|
82
82
|
expect(@parent).to be_instance_of Druid::Elements::Div
|
83
83
|
end
|
84
|
+
|
85
|
+
Then(/^it should know that it is not disabled$/) do
|
86
|
+
expect(@element).not_to be_disabled
|
87
|
+
end
|
88
|
+
|
89
|
+
Then(/^it should know that it is disabled$/) do
|
90
|
+
expect(@element).to be_disabled
|
91
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class JavascriptPage
|
2
|
+
include Druid
|
3
|
+
|
4
|
+
text_field(:expression, :id => 'calculator-expression')
|
5
|
+
text_field(:results, :id => 'calculator-result')
|
6
|
+
button(:compute, :value => 'Compute')
|
7
|
+
end
|
8
|
+
|
9
|
+
Given(/^I am on jQuery example page$/) do
|
10
|
+
Druid.javascript_framework = :jquery
|
11
|
+
@page = JavascriptPage.new(@driver)
|
12
|
+
@page.navigate_to "http://localhost:4567/jquery.html"
|
13
|
+
end
|
14
|
+
|
15
|
+
Given(/^I am on the Prototype example page$/) do
|
16
|
+
Druid.javascript_framework = :prototype
|
17
|
+
@page = JavascriptPage.new(@driver)
|
18
|
+
@page.navigate_to "http://localhost:4567/prototype.html"
|
19
|
+
end
|
20
|
+
|
21
|
+
When(/^I ask to compute "([^"]*)"$/) do |expression|
|
22
|
+
@page.expression = expression
|
23
|
+
@page.compute
|
24
|
+
end
|
25
|
+
|
26
|
+
Then(/^I should be able to wait for the answer "([^"]*)"$/) do |answer|
|
27
|
+
@page.wait_for_ajax
|
28
|
+
expect(@page.results).to eql answer
|
29
|
+
end
|
@@ -27,6 +27,8 @@ class NestedElementsPage
|
|
27
27
|
h6(:nested_h6) { |page| page.outer_div_element.h6_element }
|
28
28
|
paragraph(:nested_paragraph) { |page| page.outer_div_element.paragraph_element }
|
29
29
|
file_field(:nested_file_field) { |page| page.outer_div_element.file_field_element }
|
30
|
+
unordered_list(:outer_list, :id => 'outer')
|
31
|
+
ordered_list(:ordered_outer, :id => 'ol-outer')
|
30
32
|
end
|
31
33
|
Given(/^I am on the nested elements page$/) do
|
32
34
|
@page = NestedElementsPage.new(@driver)
|
@@ -194,3 +196,16 @@ end
|
|
194
196
|
Then(/^I should be able to retrieve the nested file field$/) do
|
195
197
|
expect(@ff.exist?).to be true
|
196
198
|
end
|
199
|
+
|
200
|
+
When(/^I get the outter unordered list$/) do
|
201
|
+
@list = @page.outer_list_element
|
202
|
+
end
|
203
|
+
|
204
|
+
When(/^I get the outter ordered list$/) do
|
205
|
+
@list = @page.ordered_outer_element
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
Then(/^I should see "([^"]*)" for list item (\d+)$/) do |text, item_num|
|
210
|
+
expect(@list[item_num.to_i - 1].text).to eql text
|
211
|
+
end
|
@@ -48,3 +48,19 @@ end
|
|
48
48
|
Then(/^I should be able to select "(.*?)" from the list$/) do |value|
|
49
49
|
@select_list.select value
|
50
50
|
end
|
51
|
+
|
52
|
+
Then(/^I should see that the select list exists$/) do
|
53
|
+
expect(@page.select_list_id?).to be true
|
54
|
+
end
|
55
|
+
|
56
|
+
Then(/^the selected option should be "([^"]*)"$/) do |text|
|
57
|
+
expect(@page.select_list_element(:id => 'sel_list_id').selected_options[0]).to eql text
|
58
|
+
end
|
59
|
+
|
60
|
+
Then(/^the select list should include "([^"]*)"$/) do |text|
|
61
|
+
expect(@page.select_list_id_element).to include text
|
62
|
+
end
|
63
|
+
|
64
|
+
Then(/^the select list should know that "([^"]*)" is selected$/) do |text|
|
65
|
+
expect(@page.select_list_id_element.selected?(text)).to be true
|
66
|
+
end
|
@@ -50,3 +50,7 @@ Then(/^the data for the last row should be "([^"]*)" and "([^"]*)"$/) do |col1,
|
|
50
50
|
expect(@element.last_row[0].text).to eql col1
|
51
51
|
expect(@element.last_row[1].text).to eql col2
|
52
52
|
end
|
53
|
+
|
54
|
+
Then(/^I should see that the table exists$/) do
|
55
|
+
expect(@page.table_id?).to be true
|
56
|
+
end
|
@@ -29,3 +29,11 @@ end
|
|
29
29
|
Then(/^I should be able to type "(.*?)" into the field element$/) do |value|
|
30
30
|
@text_field.value = value
|
31
31
|
end
|
32
|
+
|
33
|
+
Then(/^I should see that the text field exists$/) do
|
34
|
+
expect(@page.text_field_id?).to be true
|
35
|
+
end
|
36
|
+
|
37
|
+
When(/^I append "([^"]*)" to the text field$/) do |text|
|
38
|
+
@page.text_field_id_element.append text
|
39
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "../sample-app/sample_app"
|
2
|
+
|
3
|
+
class AjaxTestEnvironment
|
4
|
+
def run
|
5
|
+
Thread.abort_on_exception = true
|
6
|
+
@example_app = Thread.new { SampleApp.start("127.0.0.1", 4567) }
|
7
|
+
|
8
|
+
poller = Selenium::WebDriver::SocketPoller.new("127.0.0.1", 4567, 60)
|
9
|
+
unless poller.connected?
|
10
|
+
raise "timed out waiting for SampleApp to launch"
|
11
|
+
end
|
12
|
+
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def stop
|
17
|
+
@example_app.kill
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
@server = AjaxTestEnvironment.new
|
22
|
+
@server.run
|
23
|
+
|
24
|
+
at_exit do
|
25
|
+
@server.stop
|
26
|
+
end
|
data/features/table.feature
CHANGED
@@ -47,4 +47,5 @@ Feature: Table
|
|
47
47
|
@locator
|
48
48
|
Scenario: Finding a table dynamically
|
49
49
|
When I retrieve a table element while the script is executing
|
50
|
-
Then
|
50
|
+
Then I should see that the table exists
|
51
|
+
And the data for row "1" should be "Data1" and "Data2"
|
data/features/table_cell.feature
CHANGED
@@ -39,4 +39,5 @@ Feature: Table Cell
|
|
39
39
|
@locator
|
40
40
|
Scenario: Finding a table cell dynamically
|
41
41
|
When I retrieve a table cell element while the script is executing
|
42
|
-
Then
|
42
|
+
Then I should see that the cell exists
|
43
|
+
And the cell data should be 'Data4'
|
data/features/text_area.feature
CHANGED
@@ -34,7 +34,8 @@ Feature: Text Area
|
|
34
34
|
@locator
|
35
35
|
Scenario: Finding a text area dynamically
|
36
36
|
When I find a text area while the script is executing
|
37
|
-
Then I should
|
37
|
+
Then I should see that the text area exists
|
38
|
+
And I should be able to type "I found it" into the area element
|
38
39
|
|
39
40
|
Scenario: Clearing the text area
|
40
41
|
When I type "abcdefghijklmnop" into the text area
|
data/features/text_field.feature
CHANGED
@@ -44,4 +44,10 @@ Feature: Text Fields
|
|
44
44
|
@locator
|
45
45
|
Scenario: Finding a text field dynamically
|
46
46
|
When I find a text field while the script is executing
|
47
|
-
Then I should
|
47
|
+
Then I should see that the text field exists
|
48
|
+
And I should be able to type "i found it" into the field element
|
49
|
+
|
50
|
+
Scenario: Appending text to a text field
|
51
|
+
When I type "abcd" into the text field
|
52
|
+
And I append "efg" to the text field
|
53
|
+
Then the text field should contain "abcdefg"
|
@@ -38,5 +38,6 @@ Feature: Unordered list
|
|
38
38
|
@locator
|
39
39
|
Scenario: Finding a unordered list dynamically
|
40
40
|
When I search for the unordered list while the script is executing
|
41
|
-
|
41
|
+
Then I should see that the unordered list exists
|
42
|
+
When I get the first item from the list
|
42
43
|
Then the list items text should be "Item One"
|
data/lib/druid.rb
CHANGED
@@ -4,6 +4,7 @@ require 'druid/page_factory'
|
|
4
4
|
require 'druid/core_ext/string'
|
5
5
|
require 'druid/element_locators'
|
6
6
|
require 'druid/page_populator'
|
7
|
+
require 'druid/javascript_framework_facade'
|
7
8
|
|
8
9
|
# require 'watir-webdriver/extensions/alerts'
|
9
10
|
#
|
@@ -72,6 +73,27 @@ module Druid
|
|
72
73
|
driver.goto url
|
73
74
|
end
|
74
75
|
|
76
|
+
#
|
77
|
+
# Set the javascript framework to use when determining number of
|
78
|
+
# ajax requests. Valid frameworks are :jquery, :prototype, and :Dojo
|
79
|
+
#
|
80
|
+
def self.javascript_framework=(framework)
|
81
|
+
Druid::JavascriptFrameworkFacade.framework = framework
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# Add a new javascript framework to druid. The module passed
|
86
|
+
# in must adhere to the same prototype as the JQuery and Prototype
|
87
|
+
# modules.
|
88
|
+
#
|
89
|
+
# @param [Symbol] the name used to reference the framework in
|
90
|
+
# subsequent calls
|
91
|
+
# @param [Module] a module that has the necessary methods to perform
|
92
|
+
# the required actions.
|
93
|
+
#
|
94
|
+
def self.add_framework(key, framework)
|
95
|
+
Druid::JavascriptFrameworkFacade.add_framework(key, framework)
|
96
|
+
end
|
75
97
|
#
|
76
98
|
# get the current page url
|
77
99
|
#
|
@@ -136,6 +158,22 @@ module Druid
|
|
136
158
|
driver.wait_until(timeout, message, &block)
|
137
159
|
end
|
138
160
|
|
161
|
+
#
|
162
|
+
# wait until there are no pending ajax requests. This requires you to set the javascript framework in advance.
|
163
|
+
#
|
164
|
+
# @param [Numeric] the amount of time to wait for the block to return true.
|
165
|
+
# @param [String] the message to include with the error if we exceed the timeout duration
|
166
|
+
#
|
167
|
+
def wait_for_ajax(timeout = 30, message = nil)
|
168
|
+
end_time = ::Time.now + timeout
|
169
|
+
until ::Time.now > end_time
|
170
|
+
return if driver.execute_script(Druid::JavascriptFrameworkFacade.pending_requests) == 0
|
171
|
+
sleep 1
|
172
|
+
end
|
173
|
+
message = "Timed out waiting for ajax requests to complete" unless message
|
174
|
+
raise message
|
175
|
+
end
|
176
|
+
|
139
177
|
#
|
140
178
|
# Override the normal alert popup so it does not occurr.
|
141
179
|
#
|
@@ -257,7 +295,7 @@ module Druid
|
|
257
295
|
# Clear the cookies from the browser
|
258
296
|
#
|
259
297
|
def clear_cookies
|
260
|
-
driver.
|
298
|
+
driver.cookies.clear
|
261
299
|
end
|
262
300
|
|
263
301
|
#
|