|
| 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 | +import textwrap |
| 16 | +from test.unit.helper.test_helper import ( |
| 17 | + android_w3c_driver, |
| 18 | + appium_command, |
| 19 | + get_httpretty_request_body |
| 20 | +) |
| 21 | + |
| 22 | +import httpretty |
| 23 | + |
| 24 | + |
| 25 | +class TestWebDriverDeviceActivities(object): |
| 26 | + |
| 27 | + @httpretty.activate |
| 28 | + def test_batch(self): |
| 29 | + driver = android_w3c_driver() |
| 30 | + httpretty.register_uri( |
| 31 | + httpretty.POST, |
| 32 | + appium_command('/session/1234567890/appium/execute_driver'), |
| 33 | + body='{"value": {"result":[' |
| 34 | + '{"element-6066-11e4-a52e-4f735466cecf":"39000000-0000-0000-D39A-000000000000",' |
| 35 | + '"ELEMENT":"39000000-0000-0000-D39A-000000000000"},' |
| 36 | + '{"y":237,"x":18,"width":67,"height":24}],"logs":{' |
| 37 | + '"error":[],"warn":["warning message"],"log":[]}}}' |
| 38 | + ) |
| 39 | + |
| 40 | + script = """ |
| 41 | + console.warn('warning message'); |
| 42 | + const element = await driver.findElement('accessibility id', 'Buttons'); |
| 43 | + const rect = await driver.getElementRect(element.ELEMENT); |
| 44 | + return [element, rect]; |
| 45 | + """ |
| 46 | + response = driver.execute_driver(script=textwrap.dedent(script)) |
| 47 | + # Python client convert an element item as WebElement in the result |
| 48 | + assert response.result[0].id == '39000000-0000-0000-D39A-000000000000' |
| 49 | + assert response.result[1]['y'] == 237 |
| 50 | + assert response.logs['warn'] == ['warning message'] |
| 51 | + |
| 52 | + d = get_httpretty_request_body(httpretty.last_request()) |
| 53 | + assert d['script'] == textwrap.dedent(script) |
| 54 | + assert d['type'] == 'webdriverio' |
| 55 | + assert 'timeout' not in d |
| 56 | + |
| 57 | + @httpretty.activate |
| 58 | + def test_batch_with_timeout(self): |
| 59 | + driver = android_w3c_driver() |
| 60 | + httpretty.register_uri( |
| 61 | + httpretty.POST, |
| 62 | + appium_command('/session/1234567890/appium/execute_driver'), |
| 63 | + body='{"value": {"result":[' |
| 64 | + '{"element-6066-11e4-a52e-4f735466cecf":"39000000-0000-0000-D39A-000000000000",' |
| 65 | + '"ELEMENT":"39000000-0000-0000-D39A-000000000000"},' |
| 66 | + '{"y":237,"x":18,"width":67,"height":24}],"logs":{' |
| 67 | + '"error":[],"warn":["warning message"],"log":[]}}}' |
| 68 | + ) |
| 69 | + |
| 70 | + script = """ |
| 71 | + console.warn('warning message'); |
| 72 | + const element = await driver.findElement('accessibility id', 'Buttons'); |
| 73 | + const rect = await driver.getElementRect(element.ELEMENT); |
| 74 | + return [element, rect]; |
| 75 | + """ |
| 76 | + response = driver.execute_driver(script=textwrap.dedent(script), timeout_ms=10000) |
| 77 | + assert response.result[0].id == '39000000-0000-0000-D39A-000000000000' |
| 78 | + assert response.result[1]['y'] == 237 |
| 79 | + assert response.logs['error'] == [] |
| 80 | + |
| 81 | + d = get_httpretty_request_body(httpretty.last_request()) |
| 82 | + assert d['script'] == textwrap.dedent(script) |
| 83 | + assert d['type'] == 'webdriverio' |
| 84 | + assert d['timeout'] == 10000 |
0 commit comments