selenium_fury 1.0.1 → 1.0.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/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +1 -1
- data/lib/selenium/webdriver/common/timeouts.rb +19 -0
- data/lib/selenium_fury.rb +2 -0
- data/lib/selenium_fury/selenium_web_driver/create_selenium_web_driver.rb +3 -4
- data/lib/selenium_fury/selenium_web_driver/generic_elements/generic_element.rb +20 -2
- data/lib/selenium_fury/selenium_web_driver/generic_elements/generic_element_helpers.rb +64 -22
- data/lib/selenium_fury/selenium_web_driver/page_object_components.rb +7 -0
- data/lib/selenium_fury/version.rb +1 -1
- data/spec/selenium/webdriver/common/timeouts_spec.rb +11 -0
- data/spec/selenium_web_driver/generic_elements_spec.rb +189 -28
- data/spec/selenium_web_driver/page_object_spec.rb +1 -1
- data/spec/test_page/test_page.rb +2 -0
- metadata +9 -5
- data/.rvmrc +0 -3
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
selenium-fury
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/Gemfile
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
class Timeouts
|
4
|
+
|
5
|
+
def initialize(bridge)
|
6
|
+
@bridge = bridge
|
7
|
+
end
|
8
|
+
|
9
|
+
def implicit_wait
|
10
|
+
@implicit_wait || 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def implicit_wait=(seconds)
|
14
|
+
@bridge.setImplicitWaitTimeout Integer(seconds * 1000)
|
15
|
+
@implicit_wait = seconds || 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/selenium_fury.rb
CHANGED
@@ -25,11 +25,10 @@ module SeleniumFury
|
|
25
25
|
|
26
26
|
# @param url [string]
|
27
27
|
# @return [Selenium::WebDriver::Driver]
|
28
|
-
def launch_web_driver url
|
28
|
+
def launch_web_driver url=nil
|
29
29
|
@driver = Selenium::WebDriver.for :chrome
|
30
|
-
@driver.navigate.to url
|
30
|
+
@driver.navigate.to url unless url.nil?
|
31
31
|
end
|
32
|
-
|
33
32
|
end
|
34
33
|
end
|
35
|
-
end
|
34
|
+
end
|
@@ -10,15 +10,29 @@ module SeleniumFury
|
|
10
10
|
@location = locator
|
11
11
|
@driver = driver
|
12
12
|
@tags = opt[:tags]
|
13
|
-
|
13
|
+
# Should validate if opt[:validate] is nil, should not validate if doing dynamic matchin
|
14
|
+
@validate = opt[:validate] != false && !locator.values.first.match(/\^([^=].*?)\$/)
|
15
|
+
# This is different from implicit_wait. This explicitly waits for this element, not for entire driver session.
|
16
|
+
@wait = 10 || opt[:wait]
|
14
17
|
end
|
15
18
|
|
16
|
-
attr_accessor :location, :driver, :tags
|
19
|
+
attr_accessor :location, :driver, :tags, :wait, :implicit_wait
|
17
20
|
attr_writer :validate
|
18
21
|
|
19
22
|
def validate?
|
20
23
|
@validate
|
21
24
|
end
|
25
|
+
|
26
|
+
def update_locator(variables)
|
27
|
+
locator_value = @location.values.first
|
28
|
+
variables.each { |key, value|
|
29
|
+
locator_value.scan(/\^([^=]\w*)\$/).flatten.each { |match|
|
30
|
+
locator_value.gsub!("^#{match}$", value.to_s) if match == key.to_s
|
31
|
+
}
|
32
|
+
}
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
22
36
|
end
|
23
37
|
|
24
38
|
class CheckboxElement < GenericElement
|
@@ -54,6 +68,10 @@ module SeleniumFury
|
|
54
68
|
class TextInputElement < GenericElement
|
55
69
|
include TextElementHelpers
|
56
70
|
end
|
71
|
+
|
72
|
+
class SelectableElement < GenericElement
|
73
|
+
include SelectableElementHelpers
|
74
|
+
end
|
57
75
|
end
|
58
76
|
end
|
59
77
|
end
|
@@ -5,9 +5,15 @@ module GenericElementHelpers
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def present?
|
8
|
-
|
8
|
+
# Set implicit wait to zero so it doesn't wait that time each method call
|
9
|
+
implicit_wait = driver.manage.timeouts.implicit_wait
|
10
|
+
driver.manage.timeouts.implicit_wait = 0
|
11
|
+
present = list.size > 0
|
12
|
+
driver.manage.timeouts.implicit_wait = implicit_wait
|
13
|
+
present
|
9
14
|
end
|
10
15
|
|
16
|
+
# Raises error if not already present
|
11
17
|
def visible?
|
12
18
|
el.displayed?
|
13
19
|
end
|
@@ -20,6 +26,10 @@ module GenericElementHelpers
|
|
20
26
|
el.attribute('value')
|
21
27
|
end
|
22
28
|
|
29
|
+
def move_to
|
30
|
+
@driver.action.move_to(el).perform
|
31
|
+
end
|
32
|
+
|
23
33
|
# Use any methods from WebDriverElement not present
|
24
34
|
def method_missing method_sym, *args
|
25
35
|
if el.respond_to?(method_sym)
|
@@ -31,26 +41,37 @@ module GenericElementHelpers
|
|
31
41
|
end
|
32
42
|
|
33
43
|
module ElementWaitHelpers
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
Selenium::WebDriver::Wait.new(
|
44
|
+
def wait_for(opts={}, &condition)
|
45
|
+
opts[:timeout] ||= @wait
|
46
|
+
opts[:message] ||= ''
|
47
|
+
Selenium::WebDriver::Wait.new(opts).until { condition.call }
|
48
|
+
end
|
49
|
+
|
50
|
+
def wait_present(timeout=@wait)
|
51
|
+
wait_for(timeout: timeout) { present? }
|
52
|
+
end
|
53
|
+
|
54
|
+
def wait_not_present(timeout=@wait)
|
55
|
+
wait_for(timeout: timeout) { !present? }
|
38
56
|
end
|
39
57
|
|
40
|
-
def
|
41
|
-
|
58
|
+
def wait_visible(timeout=@wait)
|
59
|
+
wait_present(timeout)
|
60
|
+
wait_visible!(timeout)
|
42
61
|
end
|
43
62
|
|
44
|
-
|
45
|
-
|
63
|
+
# Raises error if not present
|
64
|
+
def wait_visible!(timeout=@wait)
|
65
|
+
wait_for(timeout: timeout) { visible? }
|
46
66
|
end
|
47
67
|
|
48
|
-
def
|
49
|
-
|
68
|
+
def wait_not_visible(timeout=@wait)
|
69
|
+
wait_for(timeout: timeout) { !present? || !visible? }
|
50
70
|
end
|
51
71
|
|
52
|
-
|
53
|
-
|
72
|
+
# Raises error if not present
|
73
|
+
def wait_not_visible!(timeout=@wait)
|
74
|
+
wait_for(timeout: timeout) { !visible? }
|
54
75
|
end
|
55
76
|
end
|
56
77
|
|
@@ -60,7 +81,6 @@ module CheckboxElementHelpers
|
|
60
81
|
end
|
61
82
|
end
|
62
83
|
|
63
|
-
|
64
84
|
module DropDownHelpers
|
65
85
|
def selected_option
|
66
86
|
Selenium::WebDriver::Support::Select.new(el).first_selected_option.text
|
@@ -76,30 +96,52 @@ end
|
|
76
96
|
|
77
97
|
module ImageElementHelpers
|
78
98
|
def text
|
79
|
-
attribute('alt')
|
99
|
+
el.attribute('alt')
|
80
100
|
end
|
81
101
|
|
82
102
|
def source
|
83
|
-
attribute('src')
|
103
|
+
el.attribute('src')
|
84
104
|
end
|
85
105
|
end
|
86
106
|
|
87
107
|
module LinkElementHelpers
|
88
108
|
def link
|
89
|
-
attribute('href')
|
109
|
+
el.attribute('href')
|
90
110
|
end
|
91
111
|
end
|
92
112
|
|
93
|
-
|
94
113
|
module SelectableElementHelpers
|
95
|
-
def select
|
96
|
-
raise "Locator at #{location} can not be interacted with" unless visible?
|
97
|
-
el.click
|
98
|
-
end
|
99
114
|
|
100
115
|
def selected?
|
101
116
|
el.selected?
|
102
117
|
end
|
118
|
+
|
119
|
+
# Raises error if not selectable
|
120
|
+
def select!
|
121
|
+
raise "Locator at #{location} is not visible" unless visible?
|
122
|
+
begin
|
123
|
+
el.click
|
124
|
+
rescue
|
125
|
+
raise "Locator at #{location} can not be interacted with" unless visible?
|
126
|
+
end
|
127
|
+
check_errors
|
128
|
+
end
|
129
|
+
|
130
|
+
def select
|
131
|
+
wait_visible
|
132
|
+
begin
|
133
|
+
el.click
|
134
|
+
rescue Exception => e
|
135
|
+
retry_select(e)
|
136
|
+
end
|
137
|
+
check_errors
|
138
|
+
end
|
139
|
+
|
140
|
+
# Overwrite in your project if desired
|
141
|
+
def check_errors; end
|
142
|
+
def retry_select(exception)
|
143
|
+
raise "Locator at #{location} can not be interacted with - Failed with #{exception}"
|
144
|
+
end
|
103
145
|
end
|
104
146
|
|
105
147
|
module TextElementHelpers
|
@@ -133,6 +133,13 @@ module SeleniumFury
|
|
133
133
|
end
|
134
134
|
elements << element_sym unless elements.include? element_sym
|
135
135
|
end
|
136
|
+
|
137
|
+
def selectable_element(element_sym, locator, opt={})
|
138
|
+
define_method(element_sym) do
|
139
|
+
SelectableElement.new(locator, driver, opt)
|
140
|
+
end
|
141
|
+
elements << element_sym unless elements.include? element_sym
|
142
|
+
end
|
136
143
|
end
|
137
144
|
end
|
138
145
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Selenium::WebDriver::Timeouts do
|
4
|
+
|
5
|
+
it 'should allow reading of implict wait' do
|
6
|
+
launch_web_driver
|
7
|
+
driver.manage.timeouts.implicit_wait.should == 0
|
8
|
+
driver.manage.timeouts.implicit_wait = 2
|
9
|
+
driver.manage.timeouts.implicit_wait.should == 2
|
10
|
+
end
|
11
|
+
end
|
@@ -5,48 +5,63 @@ describe PageObject do
|
|
5
5
|
let(:test_page) { TestPage.new(driver) }
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
load
|
8
|
+
load 'test_page/test_page.rb'
|
9
9
|
launch_web_driver TEST_PAGE_URL
|
10
10
|
end
|
11
11
|
|
12
|
+
describe 'Dynamic Locators' do
|
13
|
+
|
14
|
+
it 'should allow a single dynamic selection of an element with id' do
|
15
|
+
specific_element = test_page.dynamic_locator_id.update_locator(id: 222222)
|
16
|
+
specific_element.location.should == {id: 'link222222'}
|
17
|
+
specific_element.link.should == 'http://yahoo.com/'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should allow multiple dynamic selections of an element with css' do
|
21
|
+
specific_element = test_page.dynamic_locator_css.update_locator(locator: 'id', id: 333333)
|
22
|
+
specific_element.location.should == {css: "a[id='link333333']"}
|
23
|
+
specific_element.link.should == 'http://google.com/'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
12
27
|
describe SeleniumFury::SeleniumWebDriver::PageObjectComponents::GenericElement do
|
13
28
|
|
14
|
-
it
|
29
|
+
it 'should return correct object type' do
|
15
30
|
test_page.input_checkbox_element.should be_an SeleniumFury::SeleniumWebDriver::PageObjectComponents::CheckboxElement
|
16
31
|
end
|
17
32
|
|
18
|
-
it
|
33
|
+
it 'should return correct superclass object type' do
|
19
34
|
test_page.input_checkbox_element.should be_an SeleniumFury::SeleniumWebDriver::PageObjectComponents::GenericElement
|
20
35
|
end
|
21
36
|
|
22
|
-
it
|
37
|
+
it 'should provide location' do
|
23
38
|
test_page.form_element.location.should == {id: 'form'}
|
24
39
|
end
|
25
40
|
|
26
|
-
it
|
41
|
+
it 'should return a web driver element' do
|
27
42
|
test_page.form_element.el.should be_an Selenium::WebDriver::Element
|
28
43
|
end
|
29
44
|
|
30
|
-
it
|
45
|
+
it 'should find visible elements' do
|
31
46
|
test_page.form_element.visible?.should be_true
|
32
47
|
end
|
33
48
|
|
34
|
-
it
|
49
|
+
it 'should return the value' do
|
35
50
|
test_page.input_button_element.value.should == 'Click me'
|
36
51
|
end
|
37
52
|
|
38
|
-
it
|
53
|
+
it 'When there is more than one element with the provided locator, it should return an array of all of them' do
|
39
54
|
test_page.listings_element.list.should be_an Array
|
40
55
|
test_page.listings_element.list[0].should be_an Selenium::WebDriver::Element
|
41
56
|
end
|
42
57
|
|
43
58
|
describe Selenium::WebDriver::Element
|
44
59
|
|
45
|
-
it
|
60
|
+
it 'should return the correct value of a method defined in WebDriver::Element, but not GenericElement class' do
|
46
61
|
test_page.input_button_element.tag_name.should == 'input'
|
47
62
|
end
|
48
63
|
|
49
|
-
it
|
64
|
+
it 'should throw an WebDriver Element error when using a method not defined in either WebDriver::Element or GenericElement classes' do
|
50
65
|
expect { test_page.input_checkbox.clickit_good }.to raise_error(NoMethodError)
|
51
66
|
end
|
52
67
|
end
|
@@ -54,27 +69,27 @@ describe PageObject do
|
|
54
69
|
|
55
70
|
describe SeleniumFury::SeleniumWebDriver::PageObjectComponents::CheckboxElement do
|
56
71
|
|
57
|
-
it
|
72
|
+
it 'should check a checkbox not checked' do
|
58
73
|
test_page.input_checkbox_element.selected?.should be_false
|
59
74
|
test_page.input_checkbox_element.checked(true)
|
60
75
|
test_page.input_checkbox_element.selected?.should be_true
|
61
76
|
end
|
62
77
|
|
63
|
-
it
|
78
|
+
it 'should leave a checkbox checked when already checked' do
|
64
79
|
test_page.input_checkbox_element.click
|
65
80
|
test_page.input_checkbox_element.selected?.should be_true
|
66
81
|
test_page.input_checkbox_element.checked(true)
|
67
82
|
test_page.input_checkbox_element.selected?.should be_true
|
68
83
|
end
|
69
84
|
|
70
|
-
it
|
85
|
+
it 'should uncheck a checkbox when checked' do
|
71
86
|
test_page.input_checkbox_element.click
|
72
87
|
test_page.input_checkbox_element.selected?.should be_true
|
73
88
|
test_page.input_checkbox_element.checked(false)
|
74
89
|
test_page.input_checkbox_element.selected?.should be_false
|
75
90
|
end
|
76
91
|
|
77
|
-
it
|
92
|
+
it 'should leave a checkbox alone when already checked' do
|
78
93
|
test_page.input_checkbox_element.selected?.should be_false
|
79
94
|
test_page.input_checkbox_element.checked(false)
|
80
95
|
test_page.input_checkbox_element.selected?.should be_false
|
@@ -84,18 +99,18 @@ describe PageObject do
|
|
84
99
|
|
85
100
|
describe SeleniumFury::SeleniumWebDriver::PageObjectComponents::DropDownElement do
|
86
101
|
|
87
|
-
it
|
102
|
+
it 'should select from a dropdown by value' do
|
88
103
|
test_page.select_element.select_option(:value, 'mercedes')
|
89
104
|
test_page.select_element.selected_option.should == 'Mercedes'
|
90
105
|
end
|
91
106
|
|
92
|
-
it
|
107
|
+
it 'should select from a dropdown by text' do
|
93
108
|
what = 'Mercedes'
|
94
109
|
test_page.select_element.select_option(:text, what)
|
95
110
|
test_page.select_element.selected_option.should == what
|
96
111
|
end
|
97
112
|
|
98
|
-
it
|
113
|
+
it 'should select from a dropdown by index' do
|
99
114
|
test_page.select_element.select_option(:index, 3)
|
100
115
|
test_page.select_element.selected_option.should == 'Audi'
|
101
116
|
end
|
@@ -104,7 +119,7 @@ describe PageObject do
|
|
104
119
|
|
105
120
|
describe SeleniumFury::SeleniumWebDriver::PageObjectComponents::ImageElement do
|
106
121
|
|
107
|
-
it
|
122
|
+
it 'should return the alternate text for an image' do
|
108
123
|
test_page.input_image_element.text.should == 'input image'
|
109
124
|
end
|
110
125
|
|
@@ -116,45 +131,191 @@ describe PageObject do
|
|
116
131
|
|
117
132
|
describe SeleniumFury::SeleniumWebDriver::PageObjectComponents::LinkElement do
|
118
133
|
|
119
|
-
it
|
134
|
+
it 'should return the link location' do
|
120
135
|
test_page.link_element.link.should == 'http://news.ycombinator.com/'
|
121
136
|
end
|
122
137
|
end
|
123
138
|
|
124
139
|
|
125
140
|
describe SelectableElementHelpers do
|
141
|
+
let(:wait_element) { WaitElement.new(driver) }
|
142
|
+
|
143
|
+
class WaitElement < PageObject
|
144
|
+
generic_element :not_a_element, {id: 'not a element'}
|
145
|
+
selectable_element :not_visible, {id: 'not_visible'}
|
146
|
+
end
|
126
147
|
|
127
|
-
it
|
128
|
-
text =
|
148
|
+
it 'should properly submit a form' do
|
149
|
+
text = 'Hey buddy'
|
129
150
|
test_page.input_message_element.send_keys(text)
|
130
151
|
test_page.input_msg_button_element.select
|
131
152
|
test_page.message_element.text.should == text
|
132
153
|
end
|
133
154
|
|
134
|
-
it
|
155
|
+
it 'should verify option is not selected' do
|
135
156
|
test_page.input_checkbox_element.selected?.should be_false
|
136
157
|
end
|
137
158
|
|
138
|
-
it
|
159
|
+
it 'should verify option is selected' do
|
139
160
|
test_page.input_checkbox_element.select
|
140
161
|
test_page.input_checkbox_element.selected?.should be_true
|
141
162
|
end
|
163
|
+
|
164
|
+
it 'should throw not visible error if element to select is not visible and ! is specified' do
|
165
|
+
expect {wait_element.not_visible.select!}.
|
166
|
+
to raise_exception(RuntimeError, "Locator at #{wait_element.not_visible.location.to_s} is not visible")
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should throw timeout error if element to select is not visible and ! is not specified' do
|
170
|
+
expect {wait_element.not_visible.select}.
|
171
|
+
to raise_exception(Selenium::WebDriver::Error::TimeOutError)
|
172
|
+
end
|
142
173
|
end
|
143
174
|
|
144
175
|
|
145
176
|
describe TextElementHelpers do
|
146
177
|
|
147
|
-
it
|
148
|
-
text =
|
178
|
+
it 'should clear and write text' do
|
179
|
+
text = 'Hey buddy'
|
149
180
|
test_page.textarea_element.send_keys(text)
|
150
181
|
test_page.textarea_element.value.should == text
|
151
182
|
end
|
152
183
|
|
153
|
-
it
|
184
|
+
it 'should write text without clearing' do
|
154
185
|
existing_text = "This is a textarea field.\n "
|
155
|
-
new_text =
|
186
|
+
new_text = 'Hey buddy'
|
156
187
|
test_page.textarea_element.send_keys!(new_text)
|
157
188
|
test_page.textarea_element.value.should == existing_text+new_text
|
158
189
|
end
|
159
190
|
end
|
160
|
-
|
191
|
+
|
192
|
+
describe ElementWaitHelpers do
|
193
|
+
class TestPage < PageObject
|
194
|
+
generic_element :not_a_element, {id: 'not a element'}
|
195
|
+
generic_element :not_visible, {id: 'not_visible'}
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'With implicit waits' do
|
199
|
+
it 'should error immediately with traditional element check and implicit wait not set' do
|
200
|
+
start_time = Time.now
|
201
|
+
expect { driver.find_element(id: 'not a element') }.
|
202
|
+
to raise_exception(Selenium::WebDriver::Error::NoSuchElementError, 'The element could not be found')
|
203
|
+
(Time.now-start_time).should < 1
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should error after waiting the time set by implicit wait' do
|
207
|
+
driver.manage.timeouts.implicit_wait = 2
|
208
|
+
|
209
|
+
start_time = Time.now
|
210
|
+
expect { driver.find_element(id: 'not a element') }.
|
211
|
+
to raise_exception(Selenium::WebDriver::Error::NoSuchElementError, 'The element could not be found')
|
212
|
+
(Time.now-start_time).should > 2
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should ignore implicit wait for new element check, and reset wait after done' do
|
216
|
+
implicit_wait = 2
|
217
|
+
driver.manage.timeouts.implicit_wait = implicit_wait
|
218
|
+
test_element = test_page.not_a_element
|
219
|
+
test_element.implicit_wait = implicit_wait
|
220
|
+
|
221
|
+
start_time = Time.now
|
222
|
+
test_element.present?
|
223
|
+
(Time.now-start_time).should < 1
|
224
|
+
|
225
|
+
start_time = Time.now
|
226
|
+
expect { driver.find_element(id: 'not a element') }.
|
227
|
+
to raise_exception(Selenium::WebDriver::Error::NoSuchElementError, 'The element could not be found')
|
228
|
+
(Time.now-start_time).should > 2
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context 'With explicit waits' do
|
233
|
+
it 'should wait for something with wait time and message parameters set' do
|
234
|
+
start_time = Time.now
|
235
|
+
begin
|
236
|
+
test_page.not_a_element.wait_for(timeout: 2, message: 'This is the message to return') { false }
|
237
|
+
raise 'This should have failed'
|
238
|
+
rescue Exception => e
|
239
|
+
e.message.should == 'This is the message to return'
|
240
|
+
time_taken = (Time.now-start_time)
|
241
|
+
time_taken.should > 2
|
242
|
+
time_taken.should < 10
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'should wait for something with wait time set but no message' do
|
247
|
+
start_time = Time.now
|
248
|
+
begin
|
249
|
+
test_page.not_a_element.wait_for(timeout: 2) { false }
|
250
|
+
raise 'This should have failed'
|
251
|
+
rescue Exception => e
|
252
|
+
e.message.should == ''
|
253
|
+
time_taken = (Time.now-start_time)
|
254
|
+
time_taken.should > 2
|
255
|
+
time_taken.should < 10
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'should wait for something with message parameters set but not wait time' do
|
260
|
+
start_time = Time.now
|
261
|
+
begin
|
262
|
+
test_page.not_a_element.wait_for(message: 'This is the message to return') { false }
|
263
|
+
raise 'This should have failed'
|
264
|
+
rescue Exception => e
|
265
|
+
e.message.should == 'This is the message to return'
|
266
|
+
(Time.now-start_time).should > 10
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'should wait for something with no parameters set' do
|
271
|
+
start_time = Time.now
|
272
|
+
begin
|
273
|
+
test_page.not_a_element.wait_for { false }
|
274
|
+
raise 'This should have failed'
|
275
|
+
rescue Exception => e
|
276
|
+
e.message.should == ''
|
277
|
+
(Time.now-start_time).should > 10
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'should return the value in of the condition' do
|
282
|
+
result = test_page.not_a_element.wait_for { true }
|
283
|
+
result.should be_a TrueClass
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'should error on missing element if specify !' do
|
287
|
+
start_time = Time.now
|
288
|
+
expect { test_page.not_a_element.wait_visible! }.
|
289
|
+
to raise_exception(RuntimeError, "Locator at #{test_page.not_a_element.location.to_s} is not present")
|
290
|
+
(Time.now-start_time).should < 1
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'should timeout without erroring on missing element if do not specify !' do
|
294
|
+
start_time = Time.now
|
295
|
+
expect { test_page.not_a_element.wait_visible(2) }.
|
296
|
+
to raise_exception(Selenium::WebDriver::Error::TimeOutError)
|
297
|
+
time_taken = (Time.now-start_time)
|
298
|
+
time_taken.should > 2
|
299
|
+
time_taken.should < 10
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'should wait for element present and not visible for !' do
|
303
|
+
start_time = Time.now
|
304
|
+
expect { test_page.not_visible.wait_visible(2) }.
|
305
|
+
to raise_exception(Selenium::WebDriver::Error::TimeOutError)
|
306
|
+
time_taken = (Time.now-start_time)
|
307
|
+
time_taken.should > 2
|
308
|
+
time_taken.should < 10
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'should wait for element present and not visible without !' do
|
312
|
+
start_time = Time.now
|
313
|
+
expect { test_page.not_visible.wait_visible(2) }.
|
314
|
+
to raise_exception(Selenium::WebDriver::Error::TimeOutError)
|
315
|
+
time_taken = (Time.now-start_time)
|
316
|
+
time_taken.should > 2
|
317
|
+
time_taken.should < 10
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
@@ -42,7 +42,7 @@ describe PageObject do
|
|
42
42
|
launch_web_driver TEST_PAGE_URL
|
43
43
|
test_page = TestPage.new(driver)
|
44
44
|
test_page.class.elements.should_not be_nil
|
45
|
-
test_page.class.elements.should have(
|
45
|
+
test_page.class.elements.should have(39).elements
|
46
46
|
test_page.method(test_page.class.elements[0]).call.class.should == Selenium::WebDriver::Element
|
47
47
|
end
|
48
48
|
|
data/spec/test_page/test_page.rb
CHANGED
@@ -34,6 +34,8 @@ class TestPage < PageObject
|
|
34
34
|
image_element :input_image_element, {id: 'input_image'}
|
35
35
|
|
36
36
|
link_element :link_element, {id: 'link111111'}
|
37
|
+
link_element :dynamic_locator_css, {css: "a[^locator$='link^id$']"}
|
38
|
+
link_element :dynamic_locator_id, {id: 'link^id$'}
|
37
39
|
|
38
40
|
radio_button_element :input_radio_element, {id: 'input_radio'}
|
39
41
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selenium_fury
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: selenium-webdriver
|
@@ -116,7 +116,8 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- .gitignore
|
119
|
-
- .
|
119
|
+
- .ruby-gemset
|
120
|
+
- .ruby-version
|
120
121
|
- Changelog.md
|
121
122
|
- Gemfile
|
122
123
|
- LICENSE
|
@@ -128,6 +129,7 @@ files:
|
|
128
129
|
- features/support/env.rb
|
129
130
|
- features/support/hooks.rb
|
130
131
|
- features/validate_page_object.feature
|
132
|
+
- lib/selenium/webdriver/common/timeouts.rb
|
131
133
|
- lib/selenium_fury.rb
|
132
134
|
- lib/selenium_fury/common/page_parser.rb
|
133
135
|
- lib/selenium_fury/selenium_web_driver/create_selenium_web_driver.rb
|
@@ -141,6 +143,7 @@ files:
|
|
141
143
|
- lib/selenium_fury/version.rb
|
142
144
|
- selenium_fury.gemspec
|
143
145
|
- spec/common/page_parser_spec.rb
|
146
|
+
- spec/selenium/webdriver/common/timeouts_spec.rb
|
144
147
|
- spec/selenium_web_driver/element_finder_spec.rb
|
145
148
|
- spec/selenium_web_driver/generic_elements_spec.rb
|
146
149
|
- spec/selenium_web_driver/page_generator_spec.rb
|
@@ -165,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
168
|
version: '0'
|
166
169
|
segments:
|
167
170
|
- 0
|
168
|
-
hash:
|
171
|
+
hash: -1088754158506320944
|
169
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
173
|
none: false
|
171
174
|
requirements:
|
@@ -174,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
177
|
version: '0'
|
175
178
|
segments:
|
176
179
|
- 0
|
177
|
-
hash:
|
180
|
+
hash: -1088754158506320944
|
178
181
|
requirements: []
|
179
182
|
rubyforge_project:
|
180
183
|
rubygems_version: 1.8.25
|
@@ -189,6 +192,7 @@ test_files:
|
|
189
192
|
- features/support/hooks.rb
|
190
193
|
- features/validate_page_object.feature
|
191
194
|
- spec/common/page_parser_spec.rb
|
195
|
+
- spec/selenium/webdriver/common/timeouts_spec.rb
|
192
196
|
- spec/selenium_web_driver/element_finder_spec.rb
|
193
197
|
- spec/selenium_web_driver/generic_elements_spec.rb
|
194
198
|
- spec/selenium_web_driver/page_generator_spec.rb
|
data/.rvmrc
DELETED