druid-ts 0.0.1 → 1.1.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.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +1 -2
  6. data/ChangeLog +218 -0
  7. data/Gemfile +2 -1
  8. data/README.md +64 -7
  9. data/Rakefile +1 -1
  10. data/druid.gemspec +25 -0
  11. data/features/async.feature +18 -0
  12. data/features/button.feature +42 -1
  13. data/features/checkbox.feature +7 -1
  14. data/features/div.feature +6 -0
  15. data/features/element.feature +100 -0
  16. data/features/file_field.feature +35 -0
  17. data/features/form.feature +12 -6
  18. data/features/frames.feature +57 -0
  19. data/features/heading.feature +164 -0
  20. data/features/hidden_field.feature +6 -0
  21. data/features/html/async.html +18 -0
  22. data/features/html/frame_1.html +18 -0
  23. data/features/html/frame_2.html +16 -0
  24. data/features/html/frame_3.html +14 -0
  25. data/features/html/frames.html +12 -0
  26. data/features/html/iframes.html +12 -0
  27. data/features/html/modal.html +17 -0
  28. data/features/html/modal_1.html +38 -0
  29. data/features/html/modal_2.html +27 -0
  30. data/features/html/nested_elements.html +52 -0
  31. data/features/html/nested_frame_1.html +1 -0
  32. data/features/html/nested_frame_2.html +11 -0
  33. data/features/html/nested_frame_3.html +14 -0
  34. data/features/html/nested_frames.html +10 -0
  35. data/features/html/static_elements.html +29 -23
  36. data/features/image.feature +8 -0
  37. data/features/link.feature +5 -0
  38. data/features/list_item.feature +5 -0
  39. data/features/modal_dialog.feature +9 -0
  40. data/features/nested_elements.feature +105 -0
  41. data/features/ordered_list.feature +6 -0
  42. data/features/page_level_actions.feature +48 -0
  43. data/features/paragraph.feature +33 -0
  44. data/features/radio_button.feature +6 -0
  45. data/features/select_list.feature +6 -1
  46. data/features/span.feature +6 -1
  47. data/features/step_definations/async_steps.rb +63 -0
  48. data/features/step_definations/button_steps.rb +25 -1
  49. data/features/step_definations/checkbox_steps.rb +5 -1
  50. data/features/step_definations/div_steps.rb +6 -1
  51. data/features/step_definations/element_steps.rb +55 -1
  52. data/features/step_definations/file_field_steps.rb +27 -0
  53. data/features/step_definations/form_steps.rb +8 -0
  54. data/features/step_definations/frame_steps.rb +112 -0
  55. data/features/step_definations/heading_steps.rb +39 -0
  56. data/features/step_definations/hidden_field_steps.rb +7 -3
  57. data/features/step_definations/image_steps.rb +7 -3
  58. data/features/step_definations/link_steps.rb +8 -3
  59. data/features/step_definations/list_item_steps.rb +9 -1
  60. data/features/step_definations/modal_dialog_steps.rb +38 -0
  61. data/features/step_definations/nested_elements_steps.rb +196 -0
  62. data/features/step_definations/ordered_list_steps.rb +11 -3
  63. data/features/step_definations/page_level_actions_steps.rb +72 -0
  64. data/features/step_definations/paragraph_steps.rb +15 -0
  65. data/features/step_definations/radio_button_steps.rb +5 -1
  66. data/features/step_definations/select_list_steps.rb +10 -2
  67. data/features/step_definations/span_steps.rb +5 -1
  68. data/features/step_definations/table_cell_steps.rb +5 -1
  69. data/features/step_definations/table_steps.rb +17 -3
  70. data/features/step_definations/text_area_steps.rb +18 -2
  71. data/features/step_definations/text_field_steps.rb +9 -1
  72. data/features/step_definations/unordered_list_steps.rb +11 -3
  73. data/features/support/env.rb +0 -15
  74. data/features/support/hooks.rb +7 -0
  75. data/features/support/page.rb +98 -1
  76. data/features/support/persistent_browser.rb +15 -0
  77. data/features/support/url_helper.rb +24 -1
  78. data/features/table.feature +7 -0
  79. data/features/table_cell.feature +6 -0
  80. data/features/text_area.feature +11 -0
  81. data/features/text_field.feature +6 -1
  82. data/features/unordered_list.feature +6 -0
  83. data/lib/druid.rb +251 -3
  84. data/lib/druid/accessors.rb +446 -158
  85. data/lib/druid/assist.rb +394 -0
  86. data/lib/druid/core_ext/string.rb +5 -0
  87. data/lib/druid/element_locators.rb +405 -0
  88. data/lib/druid/elements.rb +28 -0
  89. data/lib/druid/elements/button.rb +6 -1
  90. data/lib/druid/elements/check_box.rb +26 -0
  91. data/lib/druid/elements/div.rb +3 -1
  92. data/lib/druid/elements/element.rb +170 -5
  93. data/lib/druid/elements/file_field.rb +18 -0
  94. data/lib/druid/elements/form.rb +11 -0
  95. data/lib/druid/elements/heading.rb +14 -0
  96. data/lib/druid/elements/hidden_field.rb +12 -2
  97. data/lib/druid/elements/image.rb +13 -0
  98. data/lib/druid/elements/link.rb +2 -0
  99. data/lib/druid/elements/list_item.rb +3 -1
  100. data/lib/druid/elements/option.rb +9 -0
  101. data/lib/druid/elements/ordered_list.rb +4 -5
  102. data/lib/druid/elements/paragraph.rb +9 -0
  103. data/lib/druid/elements/radio_button.rb +25 -0
  104. data/lib/druid/elements/select_list.rb +10 -1
  105. data/lib/druid/elements/span.rb +3 -1
  106. data/lib/druid/elements/table.rb +20 -1
  107. data/lib/druid/elements/table_cell.rb +7 -0
  108. data/lib/druid/elements/table_row.rb +5 -1
  109. data/lib/druid/elements/text_area.rb +15 -1
  110. data/lib/druid/elements/text_field.rb +11 -1
  111. data/lib/druid/elements/unordered_list.rb +5 -5
  112. data/lib/druid/nested_elements.rb +103 -0
  113. data/lib/druid/page_factory.rb +4 -4
  114. data/lib/druid/page_populator.rb +71 -0
  115. data/spec/druid/accessors_spec.rb +789 -0
  116. data/spec/druid/druid_spec.rb +130 -7
  117. data/spec/druid/element_locators_spec.rb +160 -0
  118. data/spec/druid/elements/button_spec.rb +31 -0
  119. data/spec/druid/elements/check_box_spec.rb +38 -0
  120. data/spec/druid/elements/div_spec.rb +19 -0
  121. data/spec/druid/elements/element_spec.rb +150 -0
  122. data/spec/druid/elements/file_field_spec.rb +27 -0
  123. data/spec/druid/elements/form_spec.rb +27 -0
  124. data/spec/druid/elements/heading_spec.rb +39 -0
  125. data/spec/druid/elements/hidden_field_spec.rb +24 -0
  126. data/spec/druid/elements/image_spec.rb +32 -0
  127. data/spec/druid/elements/link_spec.rb +26 -0
  128. data/spec/druid/elements/list_item_spec.rb +19 -0
  129. data/spec/druid/elements/option_spec.rb +10 -0
  130. data/spec/druid/elements/ordered_list_spec.rb +42 -0
  131. data/spec/druid/elements/page_factory_spec.rb +40 -0
  132. data/spec/druid/elements/paragraph_spec.rb +21 -0
  133. data/spec/druid/elements/radio_button_spec.rb +38 -0
  134. data/spec/druid/elements/select_list_spec.rb +37 -0
  135. data/spec/druid/elements/span_spec.rb +19 -0
  136. data/spec/druid/elements/table_cell_spec.rb +23 -0
  137. data/spec/druid/elements/table_row_spec.rb +41 -0
  138. data/spec/druid/elements/table_spec.rb +52 -0
  139. data/spec/druid/elements/text_area_spec.rb +31 -0
  140. data/spec/druid/elements/text_field_spec.rb +31 -0
  141. data/spec/druid/elements/unordered_list_spec.rb +42 -0
  142. data/spec/druid/nested_element_spec.rb +128 -0
  143. data/spec/druid/page_populator_spec.rb +92 -0
  144. data/spec/spec_helper.rb +2 -1
  145. metadata +147 -27
@@ -0,0 +1,105 @@
1
+ Feature: Nested Elements
2
+
3
+ Background:
4
+ Given I am on the nested elements page
5
+
6
+ Scenario: Finding a link within a div
7
+ When I search for a link located in a div
8
+ Then I should be able to click the nested link
9
+
10
+ Scenario: Finding a button within a div
11
+ When I search for a button located in a div
12
+ Then I should be able to click the nested button
13
+
14
+ Scenario: Finding a text field within a div
15
+ When I search for a text field located in a div
16
+ Then I should be able to type "123abc" in the nested text field
17
+
18
+ Scenario: Finding a hidden field within a div
19
+ When I search for a hidden field located in a div
20
+ Then I should be able to see that the nested hidden field contains "LeanDog"
21
+
22
+ Scenario: Finding a text area within a div
23
+ When I search for a text area located in a div
24
+ Then I should be able to type "abcdefg" in the nested text area
25
+
26
+ Scenario: Finding a select list within a div
27
+ When I search for a select list located in a div
28
+ Then I should be able to select "Test 2" in the nested select list
29
+
30
+ Scenario: Finding a checkbox within a div
31
+ When I search for a checkbox located in a div
32
+ Then I should be able to check the nested checkbox
33
+
34
+ Scenario: Finding a radio button within a div
35
+ When I search for a radio button located in a div
36
+ Then I should be able to select the nested radio button
37
+
38
+ Scenario: Finding a div within a div
39
+ When I search for a div located in a div
40
+ Then I should see the text "page-object rocks!" in the nested div
41
+
42
+ Scenario: Finding a span within a div
43
+ When I search for a span located in a div
44
+ Then I should see the text "My alert" in the nested span
45
+
46
+ Scenario: Finding a table within a div
47
+ When I search for a table located in a div
48
+ Then the data for row "1" of the nested table should be "Data1" and "Data2"
49
+
50
+ Scenario: Finding a table cell within a div
51
+ When I search the second table cell located in a table in a div
52
+ Then the nested table cell should contain "Data2"
53
+
54
+ Scenario: Finding an image within a div
55
+ When I search for an image located in a div
56
+ Then the nested image should be "106" pixels wide
57
+ And the nested image should be "106" pixels tall
58
+
59
+ Scenario: Finding a form within a div
60
+ When I search for a form located in a div
61
+ Then I should be able to submit the nested form
62
+
63
+ Scenario: Finding an ordered list within a div
64
+ When I search for an ordered list located in a div
65
+ Then the first nested list items text should be "Number One"
66
+
67
+ Scenario: Finding an unordered list within a div
68
+ When I search for an unordered list located in a div
69
+ Then the first nested list items text should be "Item One"
70
+
71
+ Scenario: Finding a list item nested in an ordered list within a div
72
+ When I search for a list item nested in a ordered list in a div
73
+ Then I should see the nested list items text should be "Number One"
74
+
75
+ Scenario: Finding a h1 within a div
76
+ When I search for a h1 located in a div
77
+ Then I should see the nested h1s text should be "h1's are cool"
78
+
79
+ Scenario: Finding a h2 within a div
80
+ When I search for a h2 located in a div
81
+ Then I should see the nested h2s text should be "h2's are cool"
82
+
83
+ Scenario: Finding a h3 within a div
84
+ When I search for a h3 located in a div
85
+ Then I should see the nested h3s text should be "h3's are cool"
86
+
87
+ Scenario: Finding a h4 within a div
88
+ When I search for a h4 located in a div
89
+ Then I should see the nested h4s text should be "h4's are cool"
90
+
91
+ Scenario: Finding a h5 within a div
92
+ When I search for a h5 located in a div
93
+ Then I should see the nested h5s text should be "h5's are cool"
94
+
95
+ Scenario: Finding a h6 within a div
96
+ When I search for a h6 located in a div
97
+ Then I should see the nested h6s text should be "h6's are cool"
98
+
99
+ Scenario: Finding a paragraph within a div
100
+ When I search for a paragraph located in a div
101
+ Then I should see the nested paragraphs text should be "This is a paragraph."
102
+
103
+ Scenario: Finding a file field within a div
104
+ When I search for a file field located in a div
105
+ Then I should be able to retrieve the nested file field
@@ -33,3 +33,9 @@ Feature: Ordered list
33
33
  | param1 | param2 |
34
34
  | class | index |
35
35
  | name | index |
36
+
37
+ @locator
38
+ Scenario: Finding a ordered list dynamically
39
+ When I search for the ordered list while the script is executing
40
+ And I get the first item from the list
41
+ Then the list items text should be "Number One"
@@ -29,3 +29,51 @@ Feature: Page level actions
29
29
  Scenario: Using the visit_page methods with block
30
30
  Given I can goto baidu.com using visit_page with block
31
31
  Then the page should have the title "百度" using on_page with block
32
+
33
+ Scenario: Waiting for something
34
+ Given I am on the static elements page
35
+ Then I should be able to wait for a block to return true
36
+
37
+ Scenario: Handling alert popups
38
+ Given I am on the static elements page
39
+ When I handle the alert
40
+ Then I should be able to get the alert's message
41
+
42
+ Scenario: Handling confirm popups
43
+ Given I am on the static elements page
44
+ When I handle the confirm
45
+ Then I should be able to get the confirm's message
46
+
47
+ Scenario: Handling prompt popups
48
+ Given I am on the static elements page
49
+ When I handle the prompt
50
+ Then I should be able to get the message and default value
51
+
52
+ Scenario: Attach to window using title
53
+ Given I am on the static elements page
54
+ When I open a second window
55
+ Then I should be able to attach to page object using title
56
+
57
+ Scenario: Attach to window using url
58
+ Given I am on the static elements page
59
+ When I open a second window
60
+ Then I should be able to attach to page object using url
61
+
62
+ Scenario: Attach to widnow using index
63
+ Given I am on the static elements page
64
+ When I open a second window
65
+ Then I should be able to attach to page object using index
66
+
67
+ Scenario: Refreshing the page
68
+ Given I am on the static elements page
69
+ Then I should be able to refresh the page
70
+
71
+ @dev
72
+ Scenario: Going back and forward
73
+ Given I am on the static elements page
74
+ When I select the link labeled "Google Search"
75
+ Then the page should contain the text "Success"
76
+ When I press the back button
77
+ Then the page should contain the text "Static Elements Page"
78
+ When I press the forward button
79
+ Then the page should contain the text "Success"
@@ -0,0 +1,33 @@
1
+ Feature: Paragraph
2
+
3
+ Background:
4
+ Given I am on the static elements page
5
+
6
+ Scenario: Getting the text from a paragraph
7
+ When I get the text from the paragraph
8
+ Then the text should be "Static Elements Page"
9
+
10
+ Scenario Outline: Locating paragraphs on the page
11
+ When I search for the paragraph by "<search_by>"
12
+ Then the text should be "Static Elements Page"
13
+
14
+ Examples:
15
+ | search_by |
16
+ | id |
17
+ | class |
18
+ | xpath |
19
+ | index |
20
+ | name |
21
+
22
+ Scenario Outline: Locating paragraphs using multiple parameters
23
+ When I search for the paragraph by "<param1>" and "<param2>"
24
+ Then the text should be "Static Elements Page"
25
+
26
+ Examples:
27
+ | param1 | param2 |
28
+ | class | index |
29
+ | name | index |
30
+
31
+ Scenario: Finding a paragraph dynamically
32
+ When I get the text from a paragraph while the script is executing
33
+ Then the text should be "Static Elements Page"
@@ -24,6 +24,7 @@ Feature: Radio Buttons
24
24
  | name |
25
25
  | xpath |
26
26
  | index |
27
+ | value |
27
28
 
28
29
  Scenario: Retrieve a radio button
29
30
  When I retrieve a radio button
@@ -40,3 +41,8 @@ Feature: Radio Buttons
40
41
  | param1 | param2 |
41
42
  | class | index |
42
43
  | name | index |
44
+
45
+ @locator
46
+ Scenario: Finding a radio button dynamically
47
+ When I select the radio button while the script is executing
48
+ Then the "Milk" radio button should be selected
@@ -37,7 +37,7 @@ Feature: Select List
37
37
  And each option should contain "Test"
38
38
 
39
39
  @multi
40
- Scenario Outline: Locating a hidden field using multiple parameters
40
+ Scenario Outline: Locating a select list using multiple parameters
41
41
  When I search for the select list bys "<param1>" and "<param2>"
42
42
  Then I should be able to select "Test 2"
43
43
  And the value for the selected item should be "option2"
@@ -46,3 +46,8 @@ Feature: Select List
46
46
  | param1 | param2 |
47
47
  | class | index |
48
48
  | name | index |
49
+
50
+ @locator
51
+ Scenario: Finding a select list dynamically
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
@@ -19,7 +19,7 @@ Feature: Span
19
19
  | xpath |
20
20
  | index |
21
21
  | name |
22
-
22
+ | text |
23
23
  Scenario: Retrieve a Span
24
24
  When I retrieve a span element
25
25
  Then I should know it exists
@@ -34,3 +34,8 @@ Feature: Span
34
34
  | param1 | param2 |
35
35
  | class | index |
36
36
  | name | index |
37
+
38
+ @locator
39
+ Scenario: Finding a span dynamically
40
+ When I get the text from a span while the script is executing
41
+ Then the text should be "My alert"
@@ -0,0 +1,63 @@
1
+ def success
2
+
3
+ end
4
+
5
+ Then(/^I should be able to wait until it is present$/) do
6
+ @element.when_present do
7
+ success
8
+ end
9
+ end
10
+
11
+ Then(/^I should be able to wait until it is visible$/) do
12
+ @element.when_visible do
13
+ success
14
+ end
15
+ end
16
+
17
+ Then(/^I should be able to wait until it is not visible$/) do
18
+ begin
19
+ @element.when_not_visible do
20
+ fail
21
+ end
22
+ rescue
23
+ success
24
+ end
25
+ end
26
+
27
+ Then(/^I should be able to wait until a block returns true$/) do
28
+ @element.wait_until do
29
+ @element.visible?
30
+ end
31
+ end
32
+
33
+ class AsyncPage
34
+ include Druid
35
+
36
+ button(:target, :value => 'Target')
37
+ button(:hide, :value => 'Hide Button')
38
+ button(:unhide, :value => 'Unhide Button')
39
+ end
40
+
41
+ Given(/^I am on the async elements page$/) do
42
+ @page = AsyncPage.new(@driver)
43
+ @page.navigate_to(UrlHelper.async)
44
+ end
45
+
46
+ When(/^I make the button invisible$/) do
47
+ @page.hide
48
+ sleep 2
49
+ end
50
+
51
+ Then(/^I should be able to click it when it becomes visible$/) do
52
+ @page.unhide
53
+ @page.target_element.when_visible do
54
+ @page.target
55
+ end
56
+ end
57
+
58
+ Then(/^I should be able to wait until the button becomes invisible$/) do
59
+ @page.hide
60
+ @page.target_element.when_not_visible do
61
+ expect(@page.target_element.attribute("block")).to eql "none"
62
+ end
63
+ end
@@ -16,9 +16,33 @@ Then(/^I should be able to click the button$/) do
16
16
  end
17
17
 
18
18
  When(/^I retrieve a button element$/) do
19
- @element = @page.send "button_id_button".to_sym
19
+ @element = @page.send "button_id_element".to_sym
20
20
  end
21
21
 
22
22
  When(/^I search for the button by "(.*?)" and "(.*?)"$/) do |param1, param2|
23
23
  @how = "#{param1}_#{param2}"
24
24
  end
25
+
26
+ When(/^I find a button while the script is executing$/) do
27
+ @button = @page.button_element(:id => 'button_id')
28
+ end
29
+
30
+ Then(/^I should be able to click the button element$/) do
31
+ @button.click
32
+ end
33
+
34
+ Then(/^I should be able to click the real button$/) do
35
+ @page.send "btn_#{@how}".to_sym
36
+ end
37
+
38
+ When(/^I click the button with type image$/) do
39
+ @page.button_image_id
40
+ end
41
+
42
+ When(/^I click the image button using src$/) do
43
+ @page.button_image_src
44
+ end
45
+
46
+ When(/^I click the image button using alt$/) do
47
+ @page.button_image_alt
48
+ end
@@ -23,9 +23,13 @@ Then(/^I should be able to check the check box$/) do
23
23
  end
24
24
 
25
25
  When(/^I retrieve a check box element$/) do
26
- @element = @page.cb_id_checkbox
26
+ @element = @page.cb_id_element
27
27
  end
28
28
 
29
29
  When(/^I search for the check box by "(.*?)" and "(.*?)"$/) do |param1, param2|
30
30
  @how = "#{param1}_#{param2}"
31
31
  end
32
+
33
+ When(/^I select the first check box while the script is executing$/) do
34
+ @page.checkbox_element(:id => "cb_id").check
35
+ end
@@ -11,9 +11,14 @@ When(/^I locate the div by "(.*?)"$/) do |how|
11
11
  end
12
12
 
13
13
  When(/^I retrieve the div element$/) do
14
- @element = @page.div_id_div
14
+ @element = @page.div_id_element
15
15
  end
16
16
 
17
17
  When(/^I search for the div by "(.*?)" and "(.*?)"$/) do |param1, param2|
18
18
  @text = @page.send "div_#{param1}_#{param2}".to_sym
19
19
  end
20
+
21
+
22
+ When(/^I get the text from a div while the script is executing$/) do
23
+ @text = @page.div_element(:id => 'div_id').text
24
+ end
@@ -11,7 +11,7 @@ Then(/^I should know its' tag name is "(.*?)"$/) do |tagname|
11
11
  end
12
12
 
13
13
  Then(/^I should know the attribute "(.*?)" is false$/) do |attr_name|
14
- @attr = @element.attribute_value(attr_name)
14
+ @attr = @element.attribute(attr_name)
15
15
  # expect(@attr.is_a? NilClass).to be true
16
16
  expect(@attr).to be_nil
17
17
  end
@@ -27,3 +27,57 @@ end
27
27
  Then(/^I should know its' text includes "(.*?)"$/) do |text|
28
28
  expect(@element.text).to include text
29
29
  end
30
+
31
+ Then(/^I should know it is not visible$/) do
32
+ expect(@element).not_to be_visible
33
+ end
34
+
35
+ When(/^I clear the text field$/) do
36
+ @page.text_field_id_element.clear
37
+ end
38
+
39
+ When(/^I retrieve a heading element$/) do
40
+ @element = @page.h1_id_element
41
+ end
42
+
43
+ When(/^I click an enabled button$/) do
44
+ @element = @page.button_id_element
45
+ end
46
+
47
+ Then(/^it should know it is enabled$/) do
48
+ expect(@element.enabled?).to be true
49
+ end
50
+
51
+ When(/^I check a disabled button$/) do
52
+ @element = @page.disabled_button_element
53
+ end
54
+
55
+ Then(/^it should know it is not enabled$/) do
56
+ expect(@element.enabled?).not_to be true
57
+ end
58
+
59
+ When(/^I set the focus to the test text_field using the onfocus event$/) do
60
+ @page.text_field_element(:id => 'onfocus_text_field').fire_event('onfocus')
61
+ end
62
+
63
+ Then(/^I should see the onfocus text "([^"]*)"$/) do |text|
64
+ expect(@page.div_element(:id => 'onfocus_test').text).to eql text
65
+ end
66
+
67
+ When(/^I set the focus on the test text_field$/) do
68
+ @page.text_field_element(:id => 'text_field_id').click
69
+ # Focuses element. Note that Firefox queues focus events until the window actually has focus.
70
+ @page.text_field_element(:id => 'onfocus_text_field').focus
71
+ end
72
+
73
+ When(/^I find the child link element$/) do
74
+ @element = @page.child_element
75
+ end
76
+
77
+ When(/^ask for the parent element$/) do
78
+ @parent = @element.parent
79
+ end
80
+
81
+ Then(/^I should have a div parent$/) do
82
+ expect(@parent).to be_instance_of Druid::Elements::Div
83
+ end