|
| 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 json |
| 16 | +import os |
| 17 | +import tempfile |
| 18 | + |
| 19 | +import httpretty |
| 20 | + |
| 21 | +from appium.webdriver.webelement import WebElement as MobileWebElement |
| 22 | +from test.unit.helper.test_helper import ( |
| 23 | + android_w3c_driver, |
| 24 | + appium_command, |
| 25 | + get_httpretty_request_body |
| 26 | +) |
| 27 | + |
| 28 | + |
| 29 | +class TestWebElement(object): |
| 30 | + |
| 31 | + @httpretty.activate |
| 32 | + def test_send_key(self): |
| 33 | + driver = android_w3c_driver() |
| 34 | + httpretty.register_uri( |
| 35 | + httpretty.POST, |
| 36 | + appium_command('/session/1234567890/element/element_id/value') |
| 37 | + ) |
| 38 | + |
| 39 | + element = MobileWebElement(driver, 'element_id', w3c=True) |
| 40 | + element.send_keys('happy testing') |
| 41 | + |
| 42 | + d = get_httpretty_request_body(httpretty.last_request()) |
| 43 | + assert d['text'] == ''.join(d['value']) |
| 44 | + |
| 45 | + @httpretty.activate |
| 46 | + def test_send_key_with_file(self): |
| 47 | + driver = android_w3c_driver() |
| 48 | + # Should not send this file |
| 49 | + tmp_f = tempfile.NamedTemporaryFile() |
| 50 | + httpretty.register_uri( |
| 51 | + httpretty.POST, |
| 52 | + appium_command('/session/1234567890/element/element_id/value') |
| 53 | + ) |
| 54 | + |
| 55 | + try: |
| 56 | + element = MobileWebElement(driver, 'element_id', w3c=True) |
| 57 | + element.send_keys(tmp_f.name) |
| 58 | + finally: |
| 59 | + tmp_f.close() |
| 60 | + |
| 61 | + d = get_httpretty_request_body(httpretty.last_request()) |
| 62 | + assert d['text'] == ''.join(d['value']) |
0 commit comments