forked from appium/python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebdriver_tests.py
More file actions
108 lines (86 loc) · 4.18 KB
/
webdriver_tests.py
File metadata and controls
108 lines (86 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING
import pytest
from selenium.webdriver.support.ui import WebDriverWait
from appium import webdriver
from appium.webdriver.applicationstate import ApplicationState
from test.functional.ios.helper.test_helper import BaseTestCase
from test.functional.test_helper import get_available_from_port_range
from ..test_helper import is_ci
from .helper import desired_capabilities
if TYPE_CHECKING:
from appium.webdriver.webdriver import WebDriver
class TestWebDriver(BaseTestCase):
# TODO Due to not created 2nd session somehow
@pytest.mark.skipif(condition=is_ci(), reason='Need to fix flaky test during running on CI.')
def test_all_sessions(self) -> None:
port = get_available_from_port_range(8200, 8300)
desired_caps = desired_capabilities.get_desired_capabilities('UICatalog.app.zip')
desired_caps['deviceName'] = 'iPhone Xs Max'
desired_caps['wdaLocalPort'] = port
class session_counts_is_two:
TIMEOUT = 10
def __call__(self, driver: 'WebDriver') -> bool:
return len(driver.all_sessions) == 2
driver2 = None
try:
driver2 = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
WebDriverWait(
driver2, session_counts_is_two.TIMEOUT).until(session_counts_is_two())
assert len(self.driver.all_sessions) == 2
finally:
if driver2 is not None:
driver2.quit()
def test_app_management(self) -> None:
# this only works in Xcode9+
if float(desired_capabilities.get_desired_capabilities(
desired_capabilities.BUNDLE_ID)['platformVersion']) < 11:
return
assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND
self.driver.background_app(-1)
assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) < ApplicationState.RUNNING_IN_FOREGROUND
self.driver.activate_app(desired_capabilities.BUNDLE_ID)
assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND
def test_clear(self) -> None:
self._move_to_textbox()
el = self.driver.find_elements_by_class_name('XCUIElementTypeTextField')[0]
# Verify default text
def_text = 'Placeholder text'
text = el.get_attribute('value')
assert text == def_text
# Input some text, verify
input_text = 'blah'
el.click()
el.send_keys(input_text)
self.driver.hide_keyboard()
# TODO Needs to get the element again to update value in the element. Remove below one line when it's fixed.
el = self.driver.find_elements_by_class_name('XCUIElementTypeTextField')[0]
text = el.get_attribute('value')
assert text == input_text
# Clear text, verify
el.clear()
text = el.get_attribute('value')
assert text == def_text
def test_press_button(self) -> None:
self.driver.press_button("Home")
if float(desired_capabilities.get_desired_capabilities(
desired_capabilities.BUNDLE_ID)['platformVersion']) < 11:
return
assert self.driver.query_app_state(desired_capabilities.BUNDLE_ID) == ApplicationState.RUNNING_IN_FOREGROUND
def _move_to_textbox(self) -> None:
el1 = self.driver.find_element_by_accessibility_id('Sliders')
el2 = self.driver.find_element_by_accessibility_id('Buttons')
self.driver.scroll(el1, el2)
# Click text fields
self.driver.find_element_by_accessibility_id('Text Fields').click()