|
17 | 17 | import base64
|
18 | 18 | import copy
|
19 | 19 |
|
20 |
| -from selenium import webdriver |
21 | 20 | from selenium.common.exceptions import TimeoutException, InvalidArgumentException
|
22 | 21 | from selenium.webdriver.common.by import By
|
23 | 22 | from selenium.webdriver.remote.command import Command as RemoteCommand
|
|
29 | 28 | from appium.webdriver.common.multi_action import MultiAction
|
30 | 29 | from appium.webdriver.common.touch_action import TouchAction
|
31 | 30 | from .errorhandler import MobileErrorHandler
|
| 31 | +from .extensions.context import Context |
| 32 | +from .extensions.location import Location |
32 | 33 | from .mobilecommand import MobileCommand as Command
|
33 | 34 | from .switch_to import MobileSwitchTo
|
34 | 35 | from .webelement import WebElement as MobileWebElement
|
@@ -87,7 +88,7 @@ def _make_w3c_caps(caps):
|
87 | 88 | return {'firstMatch': [first_match]}
|
88 | 89 |
|
89 | 90 |
|
90 |
| -class WebDriver(webdriver.Remote): |
| 91 | +class WebDriver(Location, Context): |
91 | 92 |
|
92 | 93 | def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
|
93 | 94 | desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False):
|
@@ -161,36 +162,6 @@ def _merge_capabilities(self, capabilities):
|
161 | 162 | w3c_caps = _make_w3c_caps(capabilities)
|
162 | 163 | return {'capabilities': w3c_caps, 'desiredCapabilities': capabilities}
|
163 | 164 |
|
164 |
| - @property |
165 |
| - def contexts(self): |
166 |
| - """ |
167 |
| - Returns the contexts within the current session. |
168 |
| -
|
169 |
| - :Usage: |
170 |
| - driver.contexts |
171 |
| - """ |
172 |
| - return self.execute(Command.CONTEXTS)['value'] |
173 |
| - |
174 |
| - @property |
175 |
| - def current_context(self): |
176 |
| - """ |
177 |
| - Returns the current context of the current session. |
178 |
| -
|
179 |
| - :Usage: |
180 |
| - driver.current_context |
181 |
| - """ |
182 |
| - return self.execute(Command.GET_CURRENT_CONTEXT)['value'] |
183 |
| - |
184 |
| - @property |
185 |
| - def context(self): |
186 |
| - """ |
187 |
| - Returns the current context of the current session. |
188 |
| -
|
189 |
| - :Usage: |
190 |
| - driver.context |
191 |
| - """ |
192 |
| - return self.current_context |
193 |
| - |
194 | 165 | def find_element(self, by=By.ID, value=None):
|
195 | 166 | """
|
196 | 167 | Override for Appium
|
@@ -812,7 +783,7 @@ def push_file(self, destination_path, base64data=None, source_path=None):
|
812 | 783 | try:
|
813 | 784 | with open(source_path, 'rb') as file:
|
814 | 785 | data = file.read()
|
815 |
| - except FileNotFoundError: |
| 786 | + except IOError: |
816 | 787 | message = 'source_path {} could not be found. Are you sure the file exists?'.format(source_path)
|
817 | 788 | raise InvalidArgumentException(message)
|
818 | 789 | base64data = base64.b64encode(data).decode('utf-8')
|
@@ -1164,30 +1135,6 @@ def toggle_wifi(self):
|
1164 | 1135 | self.execute(Command.TOGGLE_WIFI, {})
|
1165 | 1136 | return self
|
1166 | 1137 |
|
1167 |
| - def toggle_location_services(self): |
1168 |
| - """Toggle the location services on the device. Android only. |
1169 |
| - """ |
1170 |
| - self.execute(Command.TOGGLE_LOCATION_SERVICES, {}) |
1171 |
| - return self |
1172 |
| - |
1173 |
| - def set_location(self, latitude, longitude, altitude): |
1174 |
| - """Set the location of the device |
1175 |
| -
|
1176 |
| - :Args: |
1177 |
| - - latitude - String or numeric value between -90.0 and 90.00 |
1178 |
| - - longitude - String or numeric value between -180.0 and 180.0 |
1179 |
| - - altitude - String or numeric value |
1180 |
| - """ |
1181 |
| - data = { |
1182 |
| - "location": { |
1183 |
| - "latitude": str(latitude), |
1184 |
| - "longitude": str(longitude), |
1185 |
| - "altitude": str(altitude) |
1186 |
| - } |
1187 |
| - } |
1188 |
| - self.execute(Command.SET_LOCATION, data) |
1189 |
| - return self |
1190 |
| - |
1191 | 1138 | def start_recording_screen(self, **options):
|
1192 | 1139 | """
|
1193 | 1140 | Start asynchronous screen recording process.
|
@@ -1465,12 +1412,7 @@ def finger_print(self, finger_id):
|
1465 | 1412 | # pylint: disable=protected-access
|
1466 | 1413 |
|
1467 | 1414 | def _addCommands(self):
|
1468 |
| - self.command_executor._commands[Command.CONTEXTS] = \ |
1469 |
| - ('GET', '/session/$sessionId/contexts') |
1470 |
| - self.command_executor._commands[Command.GET_CURRENT_CONTEXT] = \ |
1471 |
| - ('GET', '/session/$sessionId/context') |
1472 |
| - self.command_executor._commands[Command.SWITCH_TO_CONTEXT] = \ |
1473 |
| - ('POST', '/session/$sessionId/context') |
| 1415 | + super(WebDriver, self)._addCommands() |
1474 | 1416 | self.command_executor._commands[Command.TOUCH_ACTION] = \
|
1475 | 1417 | ('POST', '/session/$sessionId/touch/perform')
|
1476 | 1418 | self.command_executor._commands[Command.MULTI_ACTION] = \
|
@@ -1558,12 +1500,8 @@ def _addCommands(self):
|
1558 | 1500 | ('GET', '/session/$sessionId/appium/settings')
|
1559 | 1501 | self.command_executor._commands[Command.UPDATE_SETTINGS] = \
|
1560 | 1502 | ('POST', '/session/$sessionId/appium/settings')
|
1561 |
| - self.command_executor._commands[Command.TOGGLE_LOCATION_SERVICES] = \ |
1562 |
| - ('POST', '/session/$sessionId/appium/device/toggle_location_services') |
1563 | 1503 | self.command_executor._commands[Command.TOGGLE_WIFI] = \
|
1564 | 1504 | ('POST', '/session/$sessionId/appium/device/toggle_wifi')
|
1565 |
| - self.command_executor._commands[Command.SET_LOCATION] = \ |
1566 |
| - ('POST', '/session/$sessionId/location') |
1567 | 1505 | self.command_executor._commands[Command.LOCATION_IN_VIEW] = \
|
1568 | 1506 | ('GET', '/session/$sessionId/element/$id/location_in_view')
|
1569 | 1507 | self.command_executor._commands[Command.GET_DEVICE_TIME] = \
|
|
0 commit comments