druid-ts 1.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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/ChangeLog +15 -0
  4. data/Gemfile +1 -0
  5. data/druid.gemspec +1 -0
  6. data/features/button.feature +2 -1
  7. data/features/checkbox.feature +2 -1
  8. data/features/div.feature +2 -1
  9. data/features/element.feature +2 -0
  10. data/features/file_field.feature +2 -1
  11. data/features/form.feature +2 -1
  12. data/features/hidden_field.feature +2 -1
  13. data/features/html/nested_elements.html +20 -0
  14. data/features/image.feature +2 -1
  15. data/features/javascript.feature +13 -0
  16. data/features/link.feature +1 -1
  17. data/features/list_item.feature +2 -1
  18. data/features/nested_elements.feature +12 -0
  19. data/features/ordered_list.feature +2 -1
  20. data/features/paragraph.feature +2 -1
  21. data/features/radio_button.feature +2 -1
  22. data/features/sample-app/public/jquery-1.3.2.js +4376 -0
  23. data/features/sample-app/public/jquery.html +28 -0
  24. data/features/sample-app/public/prototype-1.6.0.3.js +4320 -0
  25. data/features/sample-app/public/prototype.html +32 -0
  26. data/features/sample-app/sample_app.rb +30 -0
  27. data/features/select_list.feature +13 -1
  28. data/features/span.feature +2 -1
  29. data/features/step_definations/button_steps.rb +4 -0
  30. data/features/step_definations/checkbox_steps.rb +4 -0
  31. data/features/step_definations/div_steps.rb +4 -0
  32. data/features/step_definations/element_steps.rb +8 -0
  33. data/features/step_definations/file_field_steps.rb +4 -0
  34. data/features/step_definations/form_steps.rb +4 -0
  35. data/features/step_definations/hidden_field_steps.rb +4 -0
  36. data/features/step_definations/image_steps.rb +4 -0
  37. data/features/step_definations/javasript_steps.rb +29 -0
  38. data/features/step_definations/list_item_steps.rb +4 -0
  39. data/features/step_definations/nested_elements_steps.rb +15 -0
  40. data/features/step_definations/ordered_list_steps.rb +4 -0
  41. data/features/step_definations/paragraph_steps.rb +4 -0
  42. data/features/step_definations/radio_button_steps.rb +4 -0
  43. data/features/step_definations/select_list_steps.rb +16 -0
  44. data/features/step_definations/span_steps.rb +4 -0
  45. data/features/step_definations/table_cell_steps.rb +4 -0
  46. data/features/step_definations/table_steps.rb +4 -0
  47. data/features/step_definations/text_area_steps.rb +4 -0
  48. data/features/step_definations/text_field_steps.rb +8 -0
  49. data/features/step_definations/unordered_list_steps.rb +4 -0
  50. data/features/support/ajax_test_environment.rb +26 -0
  51. data/features/support/url_helper.rb +1 -0
  52. data/features/table.feature +2 -1
  53. data/features/table_cell.feature +2 -1
  54. data/features/text_area.feature +2 -1
  55. data/features/text_field.feature +7 -1
  56. data/features/unordered_list.feature +2 -1
  57. data/lib/druid.rb +39 -1
  58. data/lib/druid/accessors.rb +230 -82
  59. data/lib/druid/elements/element.rb +7 -1
  60. data/lib/druid/elements/ordered_list.rb +18 -3
  61. data/lib/druid/elements/select_list.rb +24 -0
  62. data/lib/druid/elements/text_area.rb +1 -1
  63. data/lib/druid/elements/text_field.rb +4 -0
  64. data/lib/druid/elements/unordered_list.rb +18 -3
  65. data/lib/druid/javascript/jquery.rb +12 -0
  66. data/lib/druid/javascript/prototype.rb +12 -0
  67. data/lib/druid/javascript_framework_facade.rb +72 -0
  68. data/lib/druid/version.rb +1 -1
  69. data/spec/druid/druid_spec.rb +18 -3
  70. data/spec/druid/elements/element_spec.rb +5 -0
  71. data/spec/druid/elements/ordered_list_spec.rb +12 -4
  72. data/spec/druid/elements/select_list_spec.rb +17 -0
  73. data/spec/druid/elements/text_area_spec.rb +1 -1
  74. data/spec/druid/elements/text_field_spec.rb +5 -0
  75. data/spec/druid/elements/unordered_list_spec.rb +12 -4
  76. data/spec/druid/javascript_framework_facade_spec.rb +59 -0
  77. 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 be able to select "Test 2" from the list
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
@@ -38,4 +38,5 @@ Feature: Span
38
38
  @locator
39
39
  Scenario: Finding a span dynamically
40
40
  When I get the text from a span while the script is executing
41
- Then the text should be "My alert"
41
+ Then I should see that the span exists
42
+ And the text should be "My alert"
@@ -46,3 +46,7 @@ end
46
46
  When(/^I click the image button using alt$/) do
47
47
  @page.button_image_alt
48
48
  end
49
+
50
+ Then(/^I should see that the button exists$/) do
51
+ expect(@page.button_id?).to eql true
52
+ end
@@ -33,3 +33,7 @@ end
33
33
  When(/^I select the first check box while the script is executing$/) do
34
34
  @page.checkbox_element(:id => "cb_id").check
35
35
  end
36
+
37
+ Then(/^I should see that the checkbox exists$/) do
38
+ expect(@page.cb_id?).to be true
39
+ end
@@ -22,3 +22,7 @@ end
22
22
  When(/^I get the text from a div while the script is executing$/) do
23
23
  @text = @page.div_element(:id => 'div_id').text
24
24
  end
25
+
26
+ Then(/^I should see that the div exists$/) do
27
+ expect(@page.div_id?).to be true
28
+ end
@@ -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
@@ -25,3 +25,7 @@ end
25
25
  Then(/^The file field should exist$/) do
26
26
  expect(@element.exist?).to be true
27
27
  end
28
+
29
+ Then(/^I should see that the file field element exists$/) do
30
+ expect(@page.file_field_id?).to be true
31
+ end
@@ -17,3 +17,7 @@ end
17
17
  When(/^I locate a form while the script is executing$/) do
18
18
  @element = @page.form_element(:id => 'form_id')
19
19
  end
20
+
21
+ Then(/^I should see that the form exists$/) do
22
+ expect(@page.form_id?).to be true
23
+ end
@@ -21,3 +21,7 @@ end
21
21
  When(/^I find a hidden field while the script is executing$/) do
22
22
  @element = @page.hidden_field_element(:id => "hidden_field_id")
23
23
  end
24
+
25
+ Then(/^I should see that the hidden field exists$/) do
26
+ expect(@page.hidden_field_id?).to be true
27
+ end
@@ -21,3 +21,7 @@ end
21
21
  When(/^I get the image element while the script is executing$/) do
22
22
  @element = @page.image_element(:id => 'image_id')
23
23
  end
24
+
25
+ Then(/^I should see that the image exists$/) do
26
+ expect(@page.image_id?).to be true
27
+ 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
@@ -18,3 +18,7 @@ end
18
18
  When(/^I search for the list item while the script is executing$/) do
19
19
  @text = @page.list_item_element(:id => 'li_id').text
20
20
  end
21
+
22
+ Then(/^I should see that the list item exists$/) do
23
+ expect(@page.li_id?).to be true
24
+ 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
@@ -39,3 +39,7 @@ end
39
39
  When(/^I search for the ordered list while the script is executing$/) do
40
40
  @list = @page.ordered_list_element(:id => 'ol_id')
41
41
  end
42
+
43
+ Then(/^I should see that the ordered list exists$/) do
44
+ expect(@page.ol_id?).to be true
45
+ end
@@ -13,3 +13,7 @@ end
13
13
  When(/^I get the text from a paragraph while the script is executing$/) do
14
14
  @text = @page.paragraph_element(:id => 'p_id').text
15
15
  end
16
+
17
+ Then(/^I should see that the paragraph exists$/) do
18
+ expect(@page.p_id?).to be true
19
+ end
@@ -25,3 +25,7 @@ end
25
25
  When(/^I select the radio button while the script is executing$/) do
26
26
  @page.radio_button_element(:id => "milk_id").select
27
27
  end
28
+
29
+ Then(/^I should see that the radio button exists$/) do
30
+ expect(@page.milk_id?).to be true
31
+ 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
@@ -17,3 +17,7 @@ end
17
17
  When(/^I get the text from a span while the script is executing$/) do
18
18
  @text = @page.span_element(:id => 'span_id').text
19
19
  end
20
+
21
+ Then(/^I should see that the span exists$/) do
22
+ expect(@page.span_id?).to be true
23
+ end
@@ -21,3 +21,7 @@ end
21
21
  When(/^I retrieve a table cell element while the script is executing$/) do
22
22
  @cell_text = @page.cell_element(:id => 'cell_id').text
23
23
  end
24
+
25
+ Then(/^I should see that the cell exists$/) do
26
+ expect(@page.cell_id?).to be true
27
+ 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
@@ -33,3 +33,7 @@ end
33
33
  When(/^I clear the text area$/) do
34
34
  @page.text_area_id_element.clear
35
35
  end
36
+
37
+ Then(/^I should see that the text area exists$/) do
38
+ expect(@page.text_area_id?).to be true
39
+ 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
@@ -17,3 +17,7 @@ end
17
17
  When(/^I search for the unordered list while the script is executing$/) do
18
18
  @list = @page.unordered_list_element(:id => 'ul_id')
19
19
  end
20
+
21
+ Then(/^I should see that the unordered list exists$/) do
22
+ expect(@page.ul_id?).to be true
23
+ 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
@@ -39,5 +39,6 @@ module UrlHelper
39
39
  def multi
40
40
  "#{files}/multi_elements.html"
41
41
  end
42
+
42
43
  end
43
44
  end
@@ -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 the data for row "1" should be "Data1" and "Data2"
50
+ Then I should see that the table exists
51
+ And the data for row "1" should be "Data1" and "Data2"
@@ -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 the cell data should be 'Data4'
42
+ Then I should see that the cell exists
43
+ And the cell data should be 'Data4'
@@ -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 be able to type "I found it" into the area element
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
@@ -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 be able to type "i found it" into the field element
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
- And I get the first item from the list
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.clear_cookies
298
+ driver.cookies.clear
261
299
  end
262
300
 
263
301
  #