Skip to content

Commit 24e3fb7

Browse files
ki4070maKazuCocoa
authored andcommitted
Add location unittest (appium#317)
* Add test_location * Add test_set_location * Add test_toggle_location_services
1 parent 4a28029 commit 24e3fb7

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from test.unit.helper.test_helper import (
16+
appium_command,
17+
android_w3c_driver,
18+
get_httpretty_request_body
19+
)
20+
21+
import httpretty
22+
23+
from appium.webdriver.webdriver import WebDriver
24+
25+
26+
class TestWebDriverLocation(object):
27+
28+
@httpretty.activate
29+
def test_toggle_location_services(self):
30+
driver = android_w3c_driver()
31+
httpretty.register_uri(
32+
httpretty.POST,
33+
appium_command('/session/1234567890/appium/device/toggle_location_services')
34+
)
35+
assert isinstance(driver.toggle_location_services(), WebDriver) == True
36+
37+
@httpretty.activate
38+
def test_set_location(self):
39+
driver = android_w3c_driver()
40+
httpretty.register_uri(
41+
httpretty.POST,
42+
appium_command('/session/1234567890/location')
43+
)
44+
assert isinstance(driver.set_location(11.1, 22.2, 33.3), WebDriver) == True
45+
46+
d = get_httpretty_request_body(httpretty.last_request())
47+
assert d['location']['latitude'] == '11.1'
48+
assert d['location']['longitude'] == '22.2'
49+
assert d['location']['altitude'] == '33.3'
50+
51+
@httpretty.activate
52+
def test_location(self):
53+
driver = android_w3c_driver()
54+
httpretty.register_uri(
55+
httpretty.GET,
56+
appium_command('/session/1234567890/location'),
57+
body='{"value": {"latitude": 11.1, "longitude": 22.2, "altitude": 33.3}}'
58+
)
59+
val = driver.location
60+
assert val['latitude'] == 11.1
61+
assert val['longitude'] == 22.2
62+
assert val['altitude'] == 33.3

0 commit comments

Comments
 (0)