rufus 0.7 → 0.8
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/RufusApp/RufusApp/en.lproj/RUViewController.xib +11 -19
- data/config.yml +4 -3
- data/features/step_definitions/driver_steps.rb +1 -1
- data/features/step_definitions/view_steps.rb +6 -0
- data/features/support/screens/home_page.rb +1 -0
- data/features/view.feature +8 -0
- data/lib/rufus.rb +5 -5
- data/lib/rufus/accessors/view.rb +7 -8
- data/lib/rufus/driver.rb +41 -118
- data/lib/rufus/drivers/driver_base.rb +212 -0
- data/lib/rufus/drivers/driver_factory.rb +41 -0
- data/lib/rufus/drivers/iOS_device.rb +4 -4
- data/lib/rufus/drivers/iOS_faster_device.rb +37 -0
- data/lib/rufus/drivers/iOS_faster_simulator.rb +37 -0
- data/lib/rufus/drivers/iOS_simulator.rb +4 -6
- data/lib/rufus/parser.rb +81 -0
- data/rufus.gemspec +1 -1
- data/spec/drivers_specs/driver_factory_spec.rb +38 -0
- data/spec/drivers_specs/driver_spec.rb +3 -372
- data/spec/drivers_specs/iOS_device_spec.rb +70 -12
- data/spec/drivers_specs/iOS_faster_device_spec.rb +105 -0
- data/spec/drivers_specs/iOS_faster_simulator_spec.rb +113 -0
- data/spec/drivers_specs/iOS_simulator_spec.rb +69 -13
- data/spec/parser_spec.rb +116 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/view_spec.rb +14 -22
- metadata +11 -2
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rufus/drivers/iOS_faster_device'
|
3
|
+
require 'rufus/parser'
|
4
|
+
|
5
|
+
describe Rufus::Drivers::IOS_FasterDevice do
|
6
|
+
|
7
|
+
let(:config){ {"browser" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app" =>"/Users/app/path/rufus.app", "use_physical" => "true", "device" => "iPhoneSimulator", "optimized" => true}}
|
8
|
+
let(:capabilities){{"browserName" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app"}}
|
9
|
+
let(:url){'http://127.0.0.1:4723/wd/hub'}
|
10
|
+
let(:mock_driver){'mock selenium driver'}
|
11
|
+
let(:driver){Rufus::Drivers::IOS_FasterDevice.new(config)}
|
12
|
+
let(:page_data){'mock page source'}
|
13
|
+
let(:mock_parser){'a mock rufus parser'}
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
Selenium::WebDriver.should_receive(:for).with(:remote, :desired_capabilities => capabilities, :url => 'http://127.0.0.1:4723/wd/hub').and_return(mock_driver)
|
17
|
+
end
|
18
|
+
context 'getting the orientation' do
|
19
|
+
it 'can get the current orientation' do
|
20
|
+
mock_driver.should_receive(:orientation).and_return(:landscape)
|
21
|
+
driver.orientation
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context 'setting the orientation' do
|
25
|
+
it 'can set a new orientation' do
|
26
|
+
mock_driver.should_receive(:rotate).with(:landscape)
|
27
|
+
driver = Rufus::Drivers::IOS_FasterDevice.new(config)
|
28
|
+
driver.rotate :landscape
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'dealing with elements' do
|
33
|
+
let(:mock_elements){double('mock selenium driver elements list')}
|
34
|
+
let(:mock_element){double('mock selenium driver element')}
|
35
|
+
|
36
|
+
context 'finding elements' do
|
37
|
+
it 'can find an element by name' do
|
38
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
39
|
+
driver.find({:name => 'rufusButton'}).should == mock_element
|
40
|
+
end
|
41
|
+
it 'can tell if an element does not exist' do
|
42
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_raise(Selenium::WebDriver::Error::NoSuchElementError)
|
43
|
+
driver.find({:name => 'rufusButton'}).should be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
it 'can click on an element by name' do
|
47
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
48
|
+
mock_element.should_receive(:click)
|
49
|
+
driver.click({:name =>'rufusButton'})
|
50
|
+
end
|
51
|
+
it 'can click a button by name only' do
|
52
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
53
|
+
mock_element.should_receive(:click)
|
54
|
+
driver.press_button 'rufusButton'
|
55
|
+
end
|
56
|
+
context 'checking read-only elements in expedited fashion' do
|
57
|
+
before(:each) do
|
58
|
+
mock_driver.should_receive(:page_source).and_return(page_data)
|
59
|
+
Rufus::Parser.should_receive(:new).with(page_data).and_return(mock_parser)
|
60
|
+
end
|
61
|
+
context 'existence' do
|
62
|
+
it 'can find out if its part of things' do
|
63
|
+
mock_parser.should_receive(:exists?).with('rufusButton').and_return(true)
|
64
|
+
driver.exists?(:name => 'rufusButton').should be_true
|
65
|
+
end
|
66
|
+
it 'can find out if it is not part of things' do
|
67
|
+
mock_parser.should_receive(:exists?).with('rufusButton').and_return(false)
|
68
|
+
driver.exists?(:name => 'rufusButton').should be_false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
it 'can tell if an element is enabled' do
|
72
|
+
mock_parser.should_receive(:enabled?).with('rufusButton').and_return(true)
|
73
|
+
driver.enabled?(:name => 'rufusButton').should be_true
|
74
|
+
end
|
75
|
+
it 'can tell if an element is displayed on screen' do
|
76
|
+
mock_parser.should_receive(:displayed?).with('rufusButton').and_return(true)
|
77
|
+
driver.displayed?(:name => 'rufusButton').should be_true
|
78
|
+
end
|
79
|
+
it 'can get the text value of an element' do
|
80
|
+
mock_parser.should_receive(:value).with('rufusButton').and_return("whateva")
|
81
|
+
driver.text(:name => 'rufusButton').should eq("whateva")
|
82
|
+
end
|
83
|
+
it 'can get the class of an element in expedited fashion' do
|
84
|
+
mock_parser.should_receive(:class_for).with('rufusButton').and_return("UIAButton")
|
85
|
+
driver.class(:name => 'rufusButton').should eq("UIAButton")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
context 'locator does not contain name key' do
|
89
|
+
it 'calls the super class implementation for exists?' do
|
90
|
+
mock_driver.should_receive(:find_element).with(:xpath, 'rufusButton')
|
91
|
+
driver.exists?(:xpath => 'rufusButton')
|
92
|
+
end
|
93
|
+
it 'calls the super class implementation for enabled?' do
|
94
|
+
mock_driver.should_receive(:find_element).with(:xpath, 'rufusButton').and_return(mock_element)
|
95
|
+
mock_element.should_receive(:enabled?)
|
96
|
+
driver.enabled?(:xpath => 'rufusButton')
|
97
|
+
end
|
98
|
+
it 'calls the super class implementation for displayed?' do
|
99
|
+
mock_driver.should_receive(:find_element).with(:xpath, 'rufusButton').and_return(mock_element)
|
100
|
+
mock_element.should_receive(:displayed?)
|
101
|
+
driver.displayed?(:xpath => 'rufusButton')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rufus/drivers/iOS_faster_simulator'
|
3
|
+
require 'rufus/parser'
|
4
|
+
require 'selenium-webdriver'
|
5
|
+
|
6
|
+
|
7
|
+
describe Rufus::Drivers::IOS_FasterSimulator do
|
8
|
+
|
9
|
+
let(:config){ {"browser" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "sim_app_path"=>"/Users/app/path/rufus.app", "use_physical" => "true", "device" => "iPhoneSimulator", "optimized" => true}}
|
10
|
+
let(:capabilities){{"browserName" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app", "device" => "iPhoneSimulator"}}
|
11
|
+
let(:url){'http://127.0.0.1:4723/wd/hub'}
|
12
|
+
let(:mock_driver){'mock selenium driver'}
|
13
|
+
let(:driver){Rufus::Drivers::IOS_FasterSimulator.new(config)}
|
14
|
+
let(:page_data){'mock page source'}
|
15
|
+
let(:mock_parser){'a mock rufus parser'}
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
Selenium::WebDriver.should_receive(:for).with(:remote, :desired_capabilities => capabilities, :url => 'http://127.0.0.1:4723/wd/hub').and_return(mock_driver)
|
19
|
+
end
|
20
|
+
context 'getting the orientation' do
|
21
|
+
it 'can get the current orientation' do
|
22
|
+
mock_driver.should_receive(:orientation).and_return(:landscape)
|
23
|
+
driver.orientation
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context 'setting the orientation' do
|
27
|
+
it 'can set a new orientation' do
|
28
|
+
mock_driver.should_receive(:rotate).with(:landscape)
|
29
|
+
driver = Rufus::Drivers::IOS_FasterSimulator.new(config)
|
30
|
+
driver.rotate :landscape
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'dealing with elements' do
|
35
|
+
let(:mock_elements){double('mock selenium driver elements list')}
|
36
|
+
let(:mock_element){double('mock selenium driver element')}
|
37
|
+
|
38
|
+
context 'finding elements' do
|
39
|
+
it 'can find an element by name' do
|
40
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
41
|
+
driver.find({:name => 'rufusButton'}).should == mock_element
|
42
|
+
end
|
43
|
+
it 'can tell if an element does not exist' do
|
44
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_raise(Selenium::WebDriver::Error::NoSuchElementError)
|
45
|
+
driver.find({:name => 'rufusButton'}).should be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
it 'can click on an element by name' do
|
49
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
50
|
+
mock_element.should_receive(:click)
|
51
|
+
driver.click({:name =>'rufusButton'})
|
52
|
+
end
|
53
|
+
it 'can click a button by name only' do
|
54
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
55
|
+
mock_element.should_receive(:click)
|
56
|
+
driver.press_button 'rufusButton'
|
57
|
+
end
|
58
|
+
context 'checking read-only elements in expedited fashion' do
|
59
|
+
before(:each) do
|
60
|
+
mock_driver.should_receive(:page_source).and_return(page_data)
|
61
|
+
Rufus::Parser.should_receive(:new).with(page_data).and_return(mock_parser)
|
62
|
+
end
|
63
|
+
context 'existence' do
|
64
|
+
it 'can find out if its part of things' do
|
65
|
+
mock_parser.should_receive(:exists?).with('rufusButton').and_return(true)
|
66
|
+
driver.exists?(:name => 'rufusButton').should be_true
|
67
|
+
end
|
68
|
+
it 'can find out if it is not part of things' do
|
69
|
+
mock_parser.should_receive(:exists?).with('rufusButton').and_return(false)
|
70
|
+
driver.exists?(:name => 'rufusButton').should be_false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
it 'can tell if an element is enabled' do
|
74
|
+
mock_parser.should_receive(:enabled?).with('rufusButton').and_return(true)
|
75
|
+
driver.enabled?(:name => 'rufusButton').should be_true
|
76
|
+
end
|
77
|
+
it 'can tell if an element is displayed on screen' do
|
78
|
+
mock_parser.should_receive(:displayed?).with('rufusButton').and_return(true)
|
79
|
+
driver.displayed?(:name => 'rufusButton').should be_true
|
80
|
+
end
|
81
|
+
it 'can get the text value of an element' do
|
82
|
+
mock_parser.should_receive(:value).with('rufusButton').and_return("whateva")
|
83
|
+
driver.text(:name => 'rufusButton').should eq("whateva")
|
84
|
+
end
|
85
|
+
it 'can get the class of an element in expedited fashion' do
|
86
|
+
mock_parser.should_receive(:class_for).with('rufusButton').and_return("UIAButton")
|
87
|
+
driver.class(:name => 'rufusButton').should eq("UIAButton")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
it 'can enter text into an element' do
|
91
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
92
|
+
mock_element.should_receive(:click)
|
93
|
+
mock_element.should_receive(:send_keys).with('text')
|
94
|
+
driver.type('text', 'rufusButton')
|
95
|
+
end
|
96
|
+
context 'locator does not contain name key' do
|
97
|
+
it 'calls the super class implementation for exists?' do
|
98
|
+
mock_driver.should_receive(:find_element).with(:xpath, 'rufusButton')
|
99
|
+
driver.exists?(:xpath => 'rufusButton')
|
100
|
+
end
|
101
|
+
it 'calls the super class implementation for enabled?' do
|
102
|
+
mock_driver.should_receive(:find_element).with(:xpath, 'rufusButton').and_return(mock_element)
|
103
|
+
mock_element.should_receive(:enabled?)
|
104
|
+
driver.enabled?(:xpath => 'rufusButton')
|
105
|
+
end
|
106
|
+
it 'calls the super class implementation for displayed?' do
|
107
|
+
mock_driver.should_receive(:find_element).with(:xpath, 'rufusButton').and_return(mock_element)
|
108
|
+
mock_element.should_receive(:displayed?)
|
109
|
+
driver.displayed?(:xpath => 'rufusButton')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -5,34 +5,90 @@ require 'selenium-webdriver'
|
|
5
5
|
|
6
6
|
describe Rufus::Drivers::IOS_Simulator do
|
7
7
|
|
8
|
-
let(:config){ {"browser" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "
|
9
|
-
let(:capabilities){{"browserName" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/path/
|
8
|
+
let(:config){ {"browser" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "sim_app_path"=>"/Users/app/path/rufus.app", "use_physical" => "true", "device" => "iPhoneSimulator"}}
|
9
|
+
let(:capabilities){{"browserName" =>"iOS", "platform"=>"Mac", "version"=>"6.1", "app"=>"/Users/app/path/rufus.app", "device" => "iPhoneSimulator"}}
|
10
10
|
let(:url){'http://127.0.0.1:4723/wd/hub'}
|
11
11
|
let(:mock_driver){'mock selenium driver'}
|
12
|
+
let(:driver){Rufus::Drivers::IOS_Simulator.new(config)}
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
Selenium::WebDriver.should_receive(:for).with(:remote, :desired_capabilities => capabilities, :url => 'http://127.0.0.1:4723/wd/hub')
|
16
|
-
Rufus::Drivers::IOS_Simulator.for config, url
|
17
|
-
end
|
14
|
+
before(:each) do
|
15
|
+
Selenium::WebDriver.should_receive(:for).with(:remote, :desired_capabilities => capabilities, :url => 'http://127.0.0.1:4723/wd/hub').and_return(mock_driver)
|
18
16
|
end
|
19
|
-
|
20
17
|
context 'getting the orientation' do
|
21
18
|
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
19
|
mock_driver.should_receive(:orientation).and_return(:landscape)
|
24
|
-
driver = Rufus::Drivers::IOS_Simulator.for config, url
|
25
20
|
driver.orientation
|
26
21
|
end
|
27
22
|
end
|
28
|
-
|
29
23
|
context 'setting the orientation' do
|
30
24
|
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
25
|
mock_driver.should_receive(:rotate).with(:landscape)
|
33
|
-
driver = Rufus::Drivers::IOS_Simulator.
|
26
|
+
driver = Rufus::Drivers::IOS_Simulator.new(config)
|
34
27
|
driver.rotate :landscape
|
35
28
|
end
|
36
29
|
end
|
37
30
|
|
31
|
+
context 'dealing with elements' do
|
32
|
+
let(:mock_elements){double('mock selenium driver elements list')}
|
33
|
+
let(:mock_element){double('mock selenium driver element')}
|
34
|
+
|
35
|
+
context 'finding elements' do
|
36
|
+
context 'existence' do
|
37
|
+
it 'can find out if its part of things' do
|
38
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
39
|
+
mock_element.should_receive(:nil?).and_return(false)
|
40
|
+
driver.exists?(:name => 'rufusButton').should be_true
|
41
|
+
end
|
42
|
+
it 'can find out if it is not part of things' do
|
43
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
44
|
+
mock_element.should_receive(:nil?).and_return(true)
|
45
|
+
driver.exists?(:name => 'rufusButton').should be_false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
it 'can find an element by name' do
|
49
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
50
|
+
driver.find({:name => 'rufusButton'}).should == mock_element
|
51
|
+
end
|
52
|
+
it 'can tell if an element does not exist' do
|
53
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_raise(Selenium::WebDriver::Error::NoSuchElementError)
|
54
|
+
driver.find({:name => 'rufusButton'}).should be_nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
it 'can click on an element by name' do
|
58
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
59
|
+
mock_element.should_receive(:click)
|
60
|
+
driver.click({:name =>'rufusButton'})
|
61
|
+
end
|
62
|
+
it 'can click a button by name only' do
|
63
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
64
|
+
mock_element.should_receive(:click)
|
65
|
+
driver.press_button 'rufusButton'
|
66
|
+
end
|
67
|
+
it 'can tell if an element is enabled' do
|
68
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
69
|
+
mock_element.should_receive(:enabled?).and_return(true)
|
70
|
+
driver.enabled?(:name => 'rufusButton').should be_true
|
71
|
+
end
|
72
|
+
it 'can tell if an element is displayed on screen' do
|
73
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
74
|
+
mock_element.should_receive(:displayed?).and_return(true)
|
75
|
+
driver.displayed?(:name => 'rufusButton').should be_true
|
76
|
+
end
|
77
|
+
it 'can enter text into an element' do
|
78
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusButton').and_return(mock_element)
|
79
|
+
mock_element.should_receive(:click)
|
80
|
+
mock_element.should_receive(:send_keys).with('text')
|
81
|
+
driver.type('text', 'rufusButton')
|
82
|
+
end
|
83
|
+
it 'can get the text of an element' do
|
84
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusLabel').and_return(mock_element)
|
85
|
+
mock_element.should_receive(:text)
|
86
|
+
driver.text(:name => 'rufusLabel')
|
87
|
+
end
|
88
|
+
it 'can get the class of an element' do
|
89
|
+
mock_driver.should_receive(:find_element).with(:name, 'rufusLabel').and_return(mock_element)
|
90
|
+
mock_element.should_receive(:tag_name)
|
91
|
+
driver.class(:name => 'rufusLabel')
|
92
|
+
end
|
93
|
+
end
|
38
94
|
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rufus/parser'
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
describe Rufus::Parser do
|
7
|
+
context 'initializing' do
|
8
|
+
context 'json is valid' do
|
9
|
+
valid = "{\"name\":\"showAlertButton\",\"type\":\"UIAButton\",\"label\":\"showAlertButton\",\"value\":null,\"rect\":{\"origin\":{\"x\":304,\"y\":302},\"size\":{\"width\":150,\"height\":30}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]}"
|
10
|
+
before(:each) do
|
11
|
+
@parser = Rufus::Parser.new(valid)
|
12
|
+
end
|
13
|
+
it 'loads the json' do
|
14
|
+
@parser.screen_data.should == {"name"=>"showAlertButton", "type"=>"UIAButton", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>304, "y"=>302}, "size"=>{"width"=>150, "height"=>30}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[]}
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
context 'json is invalid' do
|
19
|
+
invalid = "{some random}"
|
20
|
+
it 'does not like invalid json' do
|
21
|
+
expect{Rufus::Parser.new(invalid).to raise_error(JSON::ParserError)}
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'getting view data' do
|
28
|
+
|
29
|
+
single_view = "{\"name\":\"showAlertButton\",\"type\":\"UIAButton\",\"label\":\"showAlertButton\",\"value\":\"Hello\",\"rect\":{\"origin\":{\"x\":304,\"y\":302},\"size\":{\"width\":150,\"height\":30}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]}"
|
30
|
+
before(:each) do
|
31
|
+
@parser = Rufus::Parser.new(single_view)
|
32
|
+
end
|
33
|
+
context 'getting the view class' do
|
34
|
+
it 'can find the class of a view' do
|
35
|
+
@parser.class_for('showAlertButton').should == 'UIAButton'
|
36
|
+
end
|
37
|
+
it 'says the class is not there if it cannot find it' do
|
38
|
+
@parser.class_for('doesNotExist').should be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context 'getting the views value' do
|
42
|
+
it 'can get the value of view' do
|
43
|
+
@parser.value('showAlertButton').should == 'Hello'
|
44
|
+
end
|
45
|
+
it 'is nil if the view label is not found' do
|
46
|
+
@parser.value('doesNotExist').should be_nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'getting view dimensions' do
|
51
|
+
it 'can get the views width' do
|
52
|
+
@parser.width('showAlertButton').should == 150
|
53
|
+
end
|
54
|
+
it 'is nil if label not found when getting width' do
|
55
|
+
@parser.width('doesNotExist').should be_nil
|
56
|
+
end
|
57
|
+
it 'can get the views height' do
|
58
|
+
@parser.height('showAlertButton').should == 30
|
59
|
+
end
|
60
|
+
it 'is nil if label not found when getting width' do
|
61
|
+
@parser.height('doesNotExist').should be_nil
|
62
|
+
end
|
63
|
+
it 'can get the views x position' do
|
64
|
+
@parser.x_pos('showAlertButton').should == 304
|
65
|
+
end
|
66
|
+
it 'is nil if label not found when getting x position' do
|
67
|
+
@parser.x_pos('doesNotExist').should be_nil
|
68
|
+
end
|
69
|
+
it 'can get the views y position' do
|
70
|
+
@parser.y_pos('showAlertButton').should == 302
|
71
|
+
end
|
72
|
+
it 'is nil if label not found when getting y position' do
|
73
|
+
@parser.y_pos('doesNotExist').should be_nil
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'can get the label of the view' do
|
77
|
+
@parser.label_for('showAlertButton').should eq('showAlertButton')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
context 'getting view state' do
|
81
|
+
it 'can tell if the view is enabled' do
|
82
|
+
@parser.enabled?('showAlertButton').should be_true
|
83
|
+
end
|
84
|
+
it 'can tell if the view is visible' do
|
85
|
+
@parser.displayed?('showAlertButton').should be_true
|
86
|
+
end
|
87
|
+
context 'view does not exist in hierarchy data' do
|
88
|
+
it 'return false when checking enabled state' do
|
89
|
+
@parser.enabled?('unknownView').should be_false
|
90
|
+
end
|
91
|
+
it 'returns false when checking displayed state' do
|
92
|
+
@parser.displayed?('unknownView').should be_false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context 'getting nested views' do
|
98
|
+
view_data = "{\"name\":\"showAlertButton\",\"type\":\"UIAButton\",\"label\":\"showAlertButton\",\"value\":null,\"rect\":{\"origin\":{\"x\":304,\"y\":302},\"size\":{\"width\":150,\"height\":30}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[{\"name\":\"firstChild\",\"type\":\"UIAImage\",\"label\":\"showAlertButton\",\"value\":null,\"rect\":{\"origin\":{\"x\":0,\"y\":1023},\"size\":{\"width\":768,\"height\":1}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[{\"name\":\"firstNested\",\"type\":\"UIAStaticText\",\"label\":\"showAlertButton\",\"value\":null,\"rect\":{\"origin\":{\"x\":0,\"y\":1024},\"size\":{\"width\":668,\"height\":44}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]}]},{\"name\":\"secondChild\",\"type\":\"UIAButton\",\"label\":\"showAlertButton\",\"value\":null,\"rect\":{\"origin\":{\"x\":0,\"y\":1024},\"size\":{\"width\":568,\"height\":34}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[{\"name\":\"childOfSecondChild\",\"type\":\"UIATableViewCell\",\"label\":\"showAlertButton\",\"value\":null,\"rect\":{\"origin\":{\"x\":0,\"y\":1024},\"size\":{\"width\":468,\"height\":24}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]}]}]}"
|
99
|
+
before(:each) do
|
100
|
+
@parser = Rufus::Parser.new(view_data)
|
101
|
+
end
|
102
|
+
it 'can get the root view' do
|
103
|
+
@parser.view_by_label('showAlertButton').should == {"name"=>"showAlertButton", "type"=>"UIAButton", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>304, "y"=>302}, "size"=>{"width"=>150, "height"=>30}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[{"name"=>"firstChild", "type"=>"UIAImage", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>0, "y"=>1023}, "size"=>{"width"=>768, "height"=>1}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[{"name"=>"firstNested", "type"=>"UIAStaticText", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>0, "y"=>1024}, "size"=>{"width"=>668, "height"=>44}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[]}]}, {"name"=>"secondChild", "type"=>"UIAButton", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>0, "y"=>1024}, "size"=>{"width"=>568, "height"=>34}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[{"name"=>"childOfSecondChild", "type"=>"UIATableViewCell", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>0, "y"=>1024}, "size"=>{"width"=>468, "height"=>24}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[]}]}]}
|
104
|
+
end
|
105
|
+
it 'can get the first child of the root view' do
|
106
|
+
@parser.view_by_label('firstChild').should == {"name"=>"firstChild", "type"=>"UIAImage", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>0, "y"=>1023}, "size"=>{"width"=>768, "height"=>1}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[{"name"=>"firstNested", "type"=>"UIAStaticText", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>0, "y"=>1024}, "size"=>{"width"=>668, "height"=>44}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[]}]}
|
107
|
+
end
|
108
|
+
it 'can get the second child of the root view' do
|
109
|
+
@parser.view_by_label('secondChild').should == {"name"=>"secondChild", "type"=>"UIAButton", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>0, "y"=>1024}, "size"=>{"width"=>568, "height"=>34}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[{"name"=>"childOfSecondChild", "type"=>"UIATableViewCell", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>0, "y"=>1024}, "size"=>{"width"=>468, "height"=>24}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[]}]}
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'can get a child of the root views first child' do
|
113
|
+
@parser.view_by_label('childOfSecondChild').should == {"name"=>"childOfSecondChild", "type"=>"UIATableViewCell", "label"=>"showAlertButton", "value"=>nil, "rect"=>{"origin"=>{"x"=>0, "y"=>1024}, "size"=>{"width"=>468, "height"=>24}}, "dom"=>nil, "enabled"=>true, "valid"=>true, "visible"=>true, "children"=>[]}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|