rufus 0.3 → 0.4
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 +8 -8
- data/README.md +11 -7
- data/RufusApp/RufusApp/DisplayedPageViewController.h +15 -0
- data/RufusApp/RufusApp/DisplayedPageViewController.m +44 -0
- data/RufusApp/RufusApp/DisplayedPageViewController.xib +37 -0
- data/RufusApp/RufusApp/EnabledPageViewController.h +13 -0
- data/RufusApp/RufusApp/EnabledPageViewController.m +38 -0
- data/RufusApp/RufusApp/EnabledPageViewController.xib +20 -0
- data/RufusApp/RufusApp/ExistsPageViewController.h +13 -0
- data/RufusApp/RufusApp/ExistsPageViewController.m +48 -0
- data/RufusApp/RufusApp/ExistsPageViewController.xib +20 -0
- data/RufusApp/RufusApp/RUViewController.h +5 -0
- data/RufusApp/RufusApp/RUViewController.m +15 -0
- data/RufusApp/RufusApp/RufusPageViewController.m +5 -1
- data/RufusApp/RufusApp/en.lproj/RUViewController.xib +34 -2
- data/RufusApp/RufusApp.xcodeproj/project.pbxproj +41 -3
- data/features/alert.feature +4 -3
- data/features/driver.feature +11 -0
- data/features/step_definitions/alert_steps.rb.rb +9 -0
- data/features/step_definitions/driver_steps.rb +11 -8
- data/features/step_definitions/view_steps.rb +14 -3
- data/features/support/env.rb +2 -1
- data/features/support/hooks.rb +8 -1
- data/features/support/routes.rb +12 -0
- data/features/support/screens/displayed_page.rb +12 -0
- data/features/support/screens/exists_page.rb +16 -0
- data/features/support/screens/home_page.rb +7 -1
- data/features/view.feature +23 -0
- data/lib/rufus/accessors/view.rb +1 -2
- data/lib/rufus/driver.rb +21 -2
- data/lib/rufus/drivers/iOS_device.rb +0 -1
- data/lib/rufus/drivers/iOS_simulator.rb +2 -2
- data/lib/rufus.rb +33 -1
- data/rufus.gemspec +1 -1
- data/spec/drivers_specs/driver_spec.rb +72 -20
- data/spec/drivers_specs/iOS_device_spec.rb +19 -0
- data/spec/drivers_specs/iOS_simulator_spec.rb +21 -0
- data/spec/rufus_spec.rb +88 -0
- metadata +15 -2
@@ -10,9 +10,20 @@ end
|
|
10
10
|
Given(/^I start the driver$/) do
|
11
11
|
puts selenium
|
12
12
|
end
|
13
|
-
Then(/^I am presented with an alert with the title "([^"]*)"$/) do |title|
|
14
13
|
|
14
|
+
Then(/^the view defined "([^"]*)" does( not)? exist$/) do |which, exist|
|
15
|
+
on(HomePage).send("view_#{which}_view").exists?.should == exist.nil?
|
15
16
|
end
|
16
|
-
|
17
|
-
|
17
|
+
|
18
|
+
Given(/^I have navigated to the "([^"]*)" using the "([^"]*)" route$/) do |page, which_route|
|
19
|
+
navigate_to(page.to_class, :using => which_route.to_sym)
|
20
|
+
end
|
21
|
+
Then(/^I will not find the view marked "([^"]*)" after waiting$/) do |arg|
|
22
|
+
view = on(HomePage).view_zilch_view
|
23
|
+
exists_after_wait?(view).should be_false
|
24
|
+
end
|
25
|
+
When(/^the view marked "([^"]*)" exists is( not)? displayed$/) do |which, not_displayed|
|
26
|
+
on(DisplayedPage).active?.should be_true
|
27
|
+
view = on(DisplayedPage).send("view_#{which}_view")
|
28
|
+
displayed_after_wait?(view).should == not_displayed.nil?
|
18
29
|
end
|
data/features/support/env.rb
CHANGED
data/features/support/hooks.rb
CHANGED
@@ -4,8 +4,14 @@ class HomePage
|
|
4
4
|
include Rufus
|
5
5
|
|
6
6
|
view(:view_rufus, :name =>'rufusButton')
|
7
|
+
view(:view_zilch, :name => 'zilch')
|
7
8
|
button(:view_show_alert, :name => 'showAlertButton')
|
8
|
-
alert(:
|
9
|
+
alert(:alert_rufus, :name => 'Rufus Alert')
|
10
|
+
button(:view_exists, :name => 'existsButton')
|
11
|
+
button(:view_displayed, :name => 'displayedPageButton')
|
12
|
+
button(:alert_Ok, :name => 'Ok')
|
13
|
+
button(:alert_Cancel, :name => 'Cancel')
|
14
|
+
|
9
15
|
|
10
16
|
|
11
17
|
def active?
|
data/features/view.feature
CHANGED
@@ -1,6 +1,29 @@
|
|
1
|
+
@view
|
1
2
|
Feature: Interacting with views
|
2
3
|
|
3
4
|
Scenario: Clicking a view
|
4
5
|
Given I am on the "HomePage"
|
5
6
|
When I click the view defined "rufus"
|
6
7
|
Then I am on the "RufusPage"
|
8
|
+
|
9
|
+
Scenario: Finding a view
|
10
|
+
Given I am on the "HomePage"
|
11
|
+
Then the view defined "rufus" does exist
|
12
|
+
|
13
|
+
Scenario: Not finding a view
|
14
|
+
Given I am on the "HomePage"
|
15
|
+
Then the view defined "zilch" does not exist
|
16
|
+
|
17
|
+
Scenario: Waiting for a view to exist
|
18
|
+
Given I have navigated to the "ExistsPage" using the "to_exists" route
|
19
|
+
Then I am on the "ExistsPage"
|
20
|
+
|
21
|
+
Scenario: Waiting for a view that is not there
|
22
|
+
Given I am on the "HomePage"
|
23
|
+
Then I will not find the view marked "zilch" after waiting
|
24
|
+
@displayed
|
25
|
+
Scenario: Waiting for a view to be displayed
|
26
|
+
Given I have navigated to the "DisplayedPage" using the "to_displayed" route
|
27
|
+
Then I am on the "DisplayedPage"
|
28
|
+
And the view marked "invisible" exists is not displayed
|
29
|
+
|
data/lib/rufus/accessors/view.rb
CHANGED
data/lib/rufus/driver.rb
CHANGED
@@ -2,13 +2,15 @@ require 'yaml'
|
|
2
2
|
require 'rufus/drivers/iOS_device'
|
3
3
|
require 'rufus/drivers/iOS_simulator'
|
4
4
|
require 'selenium-webdriver'
|
5
|
+
require 'erb'
|
6
|
+
require 'selenium/webdriver/safari/extension'
|
5
7
|
|
6
8
|
module Rufus
|
7
9
|
class Driver
|
8
10
|
|
9
11
|
def initialize
|
10
12
|
raise 'No config.yml found' if !File.exists?('config.yml')
|
11
|
-
@config = YAML.
|
13
|
+
@config = YAML.load(ERB.new(File.read('config.yml')).result)
|
12
14
|
@url = url(@config)
|
13
15
|
end
|
14
16
|
|
@@ -16,6 +18,11 @@ module Rufus
|
|
16
18
|
driver.get @url
|
17
19
|
end
|
18
20
|
|
21
|
+
def quit
|
22
|
+
driver.quit
|
23
|
+
@selenium = nil
|
24
|
+
end
|
25
|
+
|
19
26
|
def config
|
20
27
|
@config
|
21
28
|
end
|
@@ -27,7 +34,11 @@ module Rufus
|
|
27
34
|
def find(locator)
|
28
35
|
how = locator.keys[0].to_sym
|
29
36
|
what = locator[how]
|
30
|
-
|
37
|
+
begin
|
38
|
+
driver.find_element(how, what)
|
39
|
+
rescue Selenium::WebDriver::Error::NoSuchElementError
|
40
|
+
return nil
|
41
|
+
end
|
31
42
|
end
|
32
43
|
|
33
44
|
def click(locator)
|
@@ -46,6 +57,14 @@ module Rufus
|
|
46
57
|
find(locator).displayed?
|
47
58
|
end
|
48
59
|
|
60
|
+
def orientation
|
61
|
+
driver.orientation.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
def rotate(orientation)
|
65
|
+
driver.rotate orientation
|
66
|
+
end
|
67
|
+
|
49
68
|
def type(keys, name)
|
50
69
|
locator = {:name => name}
|
51
70
|
find(locator).send_keys keys
|
@@ -6,10 +6,10 @@ module Rufus
|
|
6
6
|
|
7
7
|
def self.for(config,url)
|
8
8
|
@config = config
|
9
|
-
|
9
|
+
Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => url)
|
10
|
+
#driver(url)
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
13
|
private
|
14
14
|
def self.capabilities
|
15
15
|
{
|
data/lib/rufus.rb
CHANGED
@@ -8,4 +8,36 @@ module Rufus
|
|
8
8
|
cls.extend Rufus::Accessors
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
def exists_after_wait?(view, timeout = 5)
|
12
|
+
wait = Selenium::WebDriver::Wait.new :timeout => timeout
|
13
|
+
begin
|
14
|
+
wait.until{view.exists?}
|
15
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def displayed_after_wait?(view, timeout = 5)
|
22
|
+
wait = Selenium::WebDriver::Wait.new :timeout => timeout
|
23
|
+
begin
|
24
|
+
wait.until{view.displayed?}
|
25
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def enabled_after_wait?(view, timeout = 5)
|
32
|
+
wait = Selenium::WebDriver::Wait.new :timeout => timeout
|
33
|
+
begin
|
34
|
+
wait.until{view.displayed?}
|
35
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
data/rufus.gemspec
CHANGED
@@ -15,7 +15,7 @@ describe Rufus::Driver do
|
|
15
15
|
context 'config file exists' do
|
16
16
|
before(:each) do
|
17
17
|
File.stub(:exists?).and_return(true)
|
18
|
-
YAML.should_receive(:
|
18
|
+
YAML.should_receive(:load).and_return("browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app")
|
19
19
|
@driver = Rufus::Driver.new
|
20
20
|
end
|
21
21
|
it 'loads the config file' do
|
@@ -47,41 +47,53 @@ describe Rufus::Driver do
|
|
47
47
|
let(:mock_elements){double('mock selenium driver elements list')}
|
48
48
|
let(:mock_element){double('mock selenium driver element')}
|
49
49
|
|
50
|
+
|
50
51
|
before(:each) do
|
51
52
|
File.stub(:exists?).and_return(true)
|
52
|
-
YAML.should_receive(:
|
53
|
-
|
53
|
+
YAML.should_receive(:load).and_return("browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app")
|
54
54
|
@driver = Rufus::Driver.new
|
55
|
-
|
56
|
-
Selenium::WebDriver.should_receive(:for).and_return(mock_driver)
|
57
|
-
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
55
|
+
Rufus::Drivers::IOS_Simulator.should_receive(:for).and_return(mock_driver)
|
58
56
|
end
|
59
57
|
|
60
|
-
|
61
|
-
|
58
|
+
context 'finding elements' do
|
59
|
+
|
60
|
+
it 'can find an element by name' do
|
61
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
62
|
+
@driver.find({:name => 'rufusButton'}).should == mock_element
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'can tell if an element does not exist' do
|
66
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_raise(Selenium::WebDriver::Error::NoSuchElementError)
|
67
|
+
@driver.find({:name => 'rufusButton'}).should be_nil
|
68
|
+
end
|
62
69
|
end
|
63
70
|
|
64
71
|
it 'can click on an element by name' do
|
72
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
65
73
|
mock_element.should_receive(:click)
|
66
74
|
@driver.click({:name =>'rufusButton'})
|
67
75
|
end
|
68
76
|
|
69
77
|
it 'can click a button by name only' do
|
78
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
70
79
|
mock_element.should_receive(:click)
|
71
80
|
@driver.press_button 'rufusButton'
|
72
81
|
end
|
73
82
|
|
74
83
|
it 'can tell if an element is enabled' do
|
84
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
75
85
|
mock_element.should_receive(:enabled?).and_return(true)
|
76
86
|
@driver.enabled?(:name => 'rufusButton').should be_true
|
77
87
|
end
|
78
88
|
|
79
89
|
it 'can tell if an element is displayed on screen' do
|
90
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
80
91
|
mock_element.should_receive(:displayed?).and_return(true)
|
81
92
|
@driver.displayed?(:name => 'rufusButton').should be_true
|
82
93
|
end
|
83
94
|
|
84
95
|
it 'can enter text into an element' do
|
96
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
85
97
|
mock_element.should_receive(:send_keys).with('text')
|
86
98
|
@driver.type('text', 'rufusButton')
|
87
99
|
end
|
@@ -96,11 +108,11 @@ describe Rufus::Driver do
|
|
96
108
|
|
97
109
|
before(:each) do
|
98
110
|
File.stub(:exists?).and_return(true)
|
99
|
-
YAML.should_receive(:
|
111
|
+
YAML.should_receive(:load).and_return("browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app")
|
100
112
|
|
101
113
|
@test_driver = Rufus::Driver.new
|
102
114
|
|
103
|
-
|
115
|
+
Rufus::Drivers::IOS_Simulator.should_receive(:for).and_return(mock_driver)
|
104
116
|
|
105
117
|
end
|
106
118
|
|
@@ -132,7 +144,7 @@ describe Rufus::Driver do
|
|
132
144
|
context 'choosing the url' do
|
133
145
|
before(:each) do
|
134
146
|
File.stub(:exists?).and_return(true)
|
135
|
-
YAML.should_receive(:
|
147
|
+
YAML.should_receive(:load).and_return("browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app")
|
136
148
|
@driver = Rufus::Driver.new
|
137
149
|
end
|
138
150
|
it 'sets the default url' do
|
@@ -148,9 +160,9 @@ describe Rufus::Driver do
|
|
148
160
|
|
149
161
|
before(:each) do
|
150
162
|
File.stub(:exists?).and_return(true)
|
151
|
-
YAML.should_receive(:
|
163
|
+
YAML.should_receive(:load).and_return("browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app")
|
152
164
|
@driver = Rufus::Driver.new
|
153
|
-
|
165
|
+
Rufus::Drivers::IOS_Simulator.should_receive(:for).and_return(mock_driver)
|
154
166
|
end
|
155
167
|
|
156
168
|
it 'can click buttons in sequence' do
|
@@ -172,9 +184,9 @@ describe Rufus::Driver do
|
|
172
184
|
|
173
185
|
before(:each) do
|
174
186
|
File.stub(:exists?).and_return(true)
|
175
|
-
YAML.should_receive(:
|
187
|
+
YAML.should_receive(:load).and_return("browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app")
|
176
188
|
@driver = Rufus::Driver.new
|
177
|
-
|
189
|
+
Rufus::Drivers::IOS_Simulator..should_receive(:for).and_return(mock_driver)
|
178
190
|
end
|
179
191
|
end
|
180
192
|
|
@@ -184,7 +196,7 @@ describe Rufus::Driver do
|
|
184
196
|
|
185
197
|
before(:each) do
|
186
198
|
File.stub(:exists?).and_return(true)
|
187
|
-
YAML.should_receive(:
|
199
|
+
YAML.should_receive(:load).and_return("browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app")
|
188
200
|
@driver = Rufus::Driver.new
|
189
201
|
end
|
190
202
|
|
@@ -211,7 +223,7 @@ describe Rufus::Driver do
|
|
211
223
|
|
212
224
|
before(:each) do
|
213
225
|
File.stub(:exists?).and_return(true)
|
214
|
-
YAML.should_receive(:
|
226
|
+
YAML.should_receive(:load).and_return("browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app")
|
215
227
|
@driver = Rufus::Driver.new
|
216
228
|
|
217
229
|
end
|
@@ -232,7 +244,7 @@ describe Rufus::Driver do
|
|
232
244
|
|
233
245
|
it 'can click an alert button' do
|
234
246
|
mock_driver.should_receive(:find_elements).at_least(2).times.with(:tag_name, 'UIAElement').and_return([mock_element])
|
235
|
-
|
247
|
+
Rufus::Drivers::IOS_Simulator.should_receive(:for).and_return(mock_driver)
|
236
248
|
mock_element.should_receive(:tag_name).at_least(2).times.and_return('UIAAlert')
|
237
249
|
@driver.click_alert('Ok')
|
238
250
|
end
|
@@ -249,7 +261,7 @@ describe Rufus::Driver do
|
|
249
261
|
before(:each) do
|
250
262
|
File.stub(:exists?).and_return(true)
|
251
263
|
@config = {"browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app", "use_physical" => true}
|
252
|
-
YAML.should_receive(:
|
264
|
+
YAML.should_receive(:load).and_return(@config)
|
253
265
|
@driver = Rufus::Driver.new
|
254
266
|
end
|
255
267
|
|
@@ -264,7 +276,7 @@ describe Rufus::Driver do
|
|
264
276
|
before(:each) do
|
265
277
|
File.stub(:exists?).and_return(true)
|
266
278
|
@config = {"browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app", "use_physical" => false}
|
267
|
-
YAML.should_receive(:
|
279
|
+
YAML.should_receive(:load).and_return(@config)
|
268
280
|
@driver = Rufus::Driver.new
|
269
281
|
end
|
270
282
|
|
@@ -274,6 +286,46 @@ describe Rufus::Driver do
|
|
274
286
|
@driver.start
|
275
287
|
end
|
276
288
|
end
|
289
|
+
end
|
290
|
+
context 'verifying and setting device orientation' do
|
291
|
+
|
292
|
+
let(:yaml){double('YAML loader')}
|
293
|
+
let(:mock_driver){'a mock app driver'}
|
294
|
+
let(:url){'http://127.0.0.1:4723/wd/hub'}
|
295
|
+
|
296
|
+
context 'orientation' do
|
297
|
+
|
298
|
+
before(:each) do
|
299
|
+
File.stub(:exists?).and_return(true)
|
300
|
+
@config = {"browser_name" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app", "use_physical" => false}
|
301
|
+
YAML.should_receive(:load).and_return(@config)
|
302
|
+
@driver = Rufus::Driver.new
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'can get the device orientation in landscape' do
|
306
|
+
Rufus::Drivers::IOS_Simulator.should_receive(:for).with(@config, url).and_return(mock_driver)
|
307
|
+
mock_driver.should_receive(:orientation).and_return(:landscape)
|
308
|
+
@driver.orientation.should eq('landscape')
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'can set the device orientation to portrait' do
|
312
|
+
|
313
|
+
Rufus::Drivers::IOS_Simulator.should_receive(:for).with(@config, url).and_return(mock_driver)
|
314
|
+
mock_driver.should_receive(:rotate).with('portrait')
|
315
|
+
@driver.rotate('portrait')
|
316
|
+
end
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
end
|
326
|
+
|
327
|
+
|
328
|
+
|
277
329
|
end
|
278
330
|
end
|
279
331
|
end
|
@@ -8,6 +8,7 @@ describe Rufus::Drivers::IOS_Device do
|
|
8
8
|
let(:config){ {"browser" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app", "use_physical" => "true"}}
|
9
9
|
let(:capabilities){{"browserName" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app"}}
|
10
10
|
let(:url){'http://127.0.0.1:4723/wd/hub'}
|
11
|
+
let(:mock_driver){'mock selenium driver'}
|
11
12
|
|
12
13
|
context 'initializing driver for iOS device' do
|
13
14
|
it 'can create a selenium driver for an iOS device' do
|
@@ -15,4 +16,22 @@ describe Rufus::Drivers::IOS_Device do
|
|
15
16
|
Rufus::Drivers::IOS_Device.for config, url
|
16
17
|
end
|
17
18
|
end
|
19
|
+
|
20
|
+
context 'getting the orientation' do
|
21
|
+
it 'can get the current orientation' do
|
22
|
+
Selenium::WebDriver.should_receive(:for).with(:remote, :desired_capabilities => capabilities, :url => 'http://127.0.0.1:4723/wd/hub').and_return(mock_driver)
|
23
|
+
mock_driver.should_receive(:orientation).and_return(:landscape)
|
24
|
+
driver = Rufus::Drivers::IOS_Device.for config, url
|
25
|
+
driver.orientation
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'setting the orientation' do
|
30
|
+
it 'can set a new orientation' do
|
31
|
+
Selenium::WebDriver.should_receive(:for).with(:remote, :desired_capabilities => capabilities, :url => 'http://127.0.0.1:4723/wd/hub').and_return(mock_driver)
|
32
|
+
mock_driver.should_receive(:rotate).with(:landscape)
|
33
|
+
driver = Rufus::Drivers::IOS_Device.for config, url
|
34
|
+
driver.rotate :landscape
|
35
|
+
end
|
36
|
+
end
|
18
37
|
end
|
@@ -2,11 +2,13 @@ require 'spec_helper'
|
|
2
2
|
require 'rufus/drivers/iOS_Simulator'
|
3
3
|
require 'selenium-webdriver'
|
4
4
|
|
5
|
+
|
5
6
|
describe Rufus::Drivers::IOS_Simulator do
|
6
7
|
|
7
8
|
let(:config){ {"browser" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app", "use_physical" => "true", "sim_app_path" => "/path/to/simulator.app"}}
|
8
9
|
let(:capabilities){{"browserName" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/path/to/simulator.app", "device" => "iPhoneSimulator"}}
|
9
10
|
let(:url){'http://127.0.0.1:4723/wd/hub'}
|
11
|
+
let(:mock_driver){'mock selenium driver'}
|
10
12
|
|
11
13
|
context 'initializing driver for iOS device' do
|
12
14
|
it 'can create a selenium driver for an iOS device' do
|
@@ -14,4 +16,23 @@ describe Rufus::Drivers::IOS_Simulator do
|
|
14
16
|
Rufus::Drivers::IOS_Simulator.for config, url
|
15
17
|
end
|
16
18
|
end
|
19
|
+
|
20
|
+
context 'getting the orientation' do
|
21
|
+
it 'can get the current orientation' do
|
22
|
+
Selenium::WebDriver.should_receive(:for).with(:remote, :desired_capabilities => capabilities, :url => 'http://127.0.0.1:4723/wd/hub').and_return(mock_driver)
|
23
|
+
mock_driver.should_receive(:orientation).and_return(:landscape)
|
24
|
+
driver = Rufus::Drivers::IOS_Simulator.for config, url
|
25
|
+
driver.orientation
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'setting the orientation' do
|
30
|
+
it 'can set a new orientation' do
|
31
|
+
Selenium::WebDriver.should_receive(:for).with(:remote, :desired_capabilities => capabilities, :url => 'http://127.0.0.1:4723/wd/hub').and_return(mock_driver)
|
32
|
+
mock_driver.should_receive(:rotate).with(:landscape)
|
33
|
+
driver = Rufus::Drivers::IOS_Simulator.for config, url
|
34
|
+
driver.rotate :landscape
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
17
38
|
end
|
data/spec/rufus_spec.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rufus/driver'
|
3
|
+
require 'rufus/drivers/iOS_device'
|
4
|
+
require 'rufus/drivers/iOS_simulator'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
describe Rufus do
|
8
|
+
include Rufus
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
context 'waiting for an element to exist' do
|
13
|
+
|
14
|
+
let(:mock_wait){'mock Selenium::WebDriver::Wait'}
|
15
|
+
let(:mock_view){'a mock view object'}
|
16
|
+
|
17
|
+
context 'element exists with timeout given' do
|
18
|
+
it 'returns true if an element is found before given timeout occurs' do
|
19
|
+
Selenium::WebDriver::Wait.should_receive(:new).with(:timeout => 20).and_return(mock_wait)
|
20
|
+
mock_wait.should_receive(:until)
|
21
|
+
exists_after_wait?(mock_view, 20).should be_true
|
22
|
+
end
|
23
|
+
it 'returns true if an element is found before default timeout occurs' do
|
24
|
+
Selenium::WebDriver::Wait.should_receive(:new).with(:timeout => 5).and_return(mock_wait)
|
25
|
+
mock_wait.should_receive(:until)
|
26
|
+
exists_after_wait?(mock_view).should be_true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context 'element does not exist' do
|
30
|
+
it 'returns false if the timeout is reached' do
|
31
|
+
Selenium::WebDriver::Wait.should_receive(:new).with(:timeout => 5).and_return(mock_wait)
|
32
|
+
mock_wait.should_receive(:until).and_raise(Selenium::WebDriver::Error::TimeOutError)
|
33
|
+
exists_after_wait?(mock_view).should be_false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'waiting for an element to be displayed' do
|
39
|
+
|
40
|
+
let(:mock_wait){'mock Selenium::WebDriver::Wait'}
|
41
|
+
let(:mock_view){'a mock view object'}
|
42
|
+
|
43
|
+
context 'element is displayed with timeout given' do
|
44
|
+
it 'returns true if an element is displayed before given timeout occurs' do
|
45
|
+
Selenium::WebDriver::Wait.should_receive(:new).with(:timeout => 20).and_return(mock_wait)
|
46
|
+
mock_wait.should_receive(:until)
|
47
|
+
displayed_after_wait?(mock_view, 20).should be_true
|
48
|
+
end
|
49
|
+
it 'returns true if an element is displayed before default timeout occurs' do
|
50
|
+
Selenium::WebDriver::Wait.should_receive(:new).with(:timeout => 5).and_return(mock_wait)
|
51
|
+
mock_wait.should_receive(:until)
|
52
|
+
displayed_after_wait?(mock_view).should be_true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context 'element does not exist' do
|
56
|
+
it 'returns false if the timeout is reached' do
|
57
|
+
Selenium::WebDriver::Wait.should_receive(:new).with(:timeout => 5).and_return(mock_wait)
|
58
|
+
mock_wait.should_receive(:until).and_raise(Selenium::WebDriver::Error::TimeOutError)
|
59
|
+
displayed_after_wait?(mock_view).should be_false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
context 'waiting for an element to be enabled' do
|
64
|
+
|
65
|
+
let(:mock_wait){'mock Selenium::WebDriver::Wait'}
|
66
|
+
let(:mock_view){'a mock view object'}
|
67
|
+
|
68
|
+
context 'element is enabled with timeout given' do
|
69
|
+
it 'returns true if an element is displayed before given timeout occurs' do
|
70
|
+
Selenium::WebDriver::Wait.should_receive(:new).with(:timeout => 20).and_return(mock_wait)
|
71
|
+
mock_wait.should_receive(:until)
|
72
|
+
enabled_after_wait?(mock_view, 20).should be_true
|
73
|
+
end
|
74
|
+
it 'returns true if an element is enabled before default timeout occurs' do
|
75
|
+
Selenium::WebDriver::Wait.should_receive(:new).with(:timeout => 5).and_return(mock_wait)
|
76
|
+
mock_wait.should_receive(:until)
|
77
|
+
enabled_after_wait?(mock_view).should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
context 'element does not exist' do
|
81
|
+
it 'returns false if the timeout is reached' do
|
82
|
+
Selenium::WebDriver::Wait.should_receive(:new).with(:timeout => 5).and_return(mock_wait)
|
83
|
+
mock_wait.should_receive(:until).and_raise(Selenium::WebDriver::Error::TimeOutError)
|
84
|
+
enabled_after_wait?(mock_view).should be_false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|