Skip to content

Commit 2c20ae4

Browse files
authored
feat: update server url and automationName used in Appium 2 (Telefonica#335)
1 parent 469edd8 commit 2c20ae4

18 files changed

+187
-53
lines changed

CHANGELOG.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ v3.0.0
1313

1414
| It only needs PIL library to compare images and generate the differences images
1515
| Old PerceptualDiff and Magick engines have been removed
16-
| Config property 'visualtests_engine' in [Server] section has been removed
16+
| Config property `engine` in [VisualTests] section has been removed
1717
| Images distance calculation method has changed, it is recommended to review thresholds in tests
1818
1919
- Now `gecko_driver_path`, `chrome_driver_path`, `explorer_driver_path` and `edge_driver_path` config properties
2020
in [Driver] section are optional, due to new SeleniumManager feature, that downloads drivers automatically
2121
- New optional config property `safari_driver_path` in [Driver] section to configure Safari driver
22-
- New optional config property `options` in [Chromer] section to configure Chrome options instead of using old
22+
- New optional config property `options` in [Chrome] section to configure Chrome options instead of using old
2323
property `goog:chromeOptions` in [Capabilities] section.
24+
- New optional config property `base_path` in [Server] section to allow using old Selenium 3 or Appium 1 remote servers
2425
- Update [RANDOM_PHONE_NUMBER] replacement using new `DataGenerator` class
2526
- Remove support for lettuce tests
2627
- Remove deprecated parameter `context` from `map_param` and POEditor methods

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0a4
1+
3.0.0b1

docs/bdd_integration.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ functions or check the :ref:`dataset <dataset>` module for more implementation d
164164
* :code:`[B]`: Generates a blank space
165165
* :code:`[UUID]`: Generates a v4 UUID
166166
* :code:`[RANDOM]`: Generates a random value
167-
* :code:`[RANDOM_PHONE_NUMBER]`: Generates a random phone number following the pattern +34654XXXXXX, using the language and country specified in dataset.language and dataset.country
167+
* :code:`[RANDOM_PHONE_NUMBER]`: Generates a random phone number for language and country configured in dataset.language and dataset.country
168168
* :code:`[TIMESTAMP]`: Generates a timestamp from the current time
169169
* :code:`[DATETIME]`: Generates a datetime from the current time
170170
* :code:`[NOW]`: Similar to DATETIME without milliseconds; the format depends on the language

docs/mobile_configuration.rst

+16-11
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,30 @@ Mobile Configuration
44
====================
55

66
To choose mobile operating system in which Appium will execute the tests, configure *type* property in *[Driver]*
7-
section in properties.cfg file with one of these values: ios or android.
7+
section in properties.cfg file with one of these values: :code:`ios` or :code:`android`. Moreover, configure Appium
8+
properties in *[AppiumCapabilities]* section in properties.cfg file.
89

9-
The following example shows how to choose Android::
10+
The following example shows how to configure Appium to run tests over TestApp app on an iPhone 14 with iOS 16.1::
1011

1112
[Driver]
12-
type: android
13+
type: ios
1314

15+
[AppiumCapabilities]
16+
automationName: XCUITest
17+
platformName: iOS
18+
deviceName: iPhone 14
19+
platformVersion: 16.1
20+
app: http://server_url/TestApp.zip
1421

15-
Moreover, configure Appium properties in *[AppiumCapabilities]* section in properties.cfg file. The following example
16-
shows how to configure Appium to run tests over TestApp app on an iPhone 6 with iOS 8.3::
22+
And this example shows how to choose Android::
1723

1824
[Driver]
19-
type: ios
25+
type: android
2026

2127
[AppiumCapabilities]
22-
automationName: Appium
23-
platformName: iOS
24-
deviceName: iPhone 6
25-
platformVersion: 8.3
26-
app: http://server_url/TestApp.zip
28+
automationName: UiAutomator2
29+
platformName: Android
30+
deviceName: Android
31+
app: http://server_url/TestApp.apk
2732

2833
See https://appium.github.io/appium/docs/en/2.0/guides/caps/ for the complete Appium capabilities list.

docs/page_objects.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -222,28 +222,28 @@ The corresponding Android page object, where page elements are defined with thei
222222

223223
.. code-block:: python
224224
225-
from selenium.webdriver.common.by import By
225+
from appium.webdriver.common.appiumby import AppiumBy
226226
from toolium.pageelements import InputText, Button
227227
from toolium_examples.pageobjects.base.login import BaseLoginPageObject
228228
229229
class AndroidLoginPageObject(BaseLoginPageObject):
230-
username = InputText(By.ID, 'io.appium.android.apis:id/username')
231-
password = InputText(By.ID, 'io.appium.android.apis:id/password')
232-
login_button = Button(By.ID, "io.appium.android.apis:id/login_button")
230+
username = InputText(AppiumBy.ID, 'io.appium.android.apis:id/username')
231+
password = InputText(AppiumBy.ID, 'io.appium.android.apis:id/password')
232+
login_button = Button(AppiumBy.ID, "io.appium.android.apis:id/login_button")
233233
234234
235235
And the iOS page object, where page elements are defined with their specific iOS locators:
236236

237237
.. code-block:: python
238238
239-
from appium.webdriver.common.mobileby import MobileBy
239+
from appium.webdriver.common.appiumby import AppiumBy
240240
from toolium.pageelements import InputText, Button
241241
from toolium_examples.pageobjects.base.login import BaseLoginPageObject
242242
243243
class IosLoginPageObject(BaseLoginPageObject):
244-
username = InputText(MobileBy.IOS_UIAUTOMATION, '.textFields()[0]')
245-
password = InputText(MobileBy.IOS_UIAUTOMATION, '.secureTextFields()[0]')
246-
login_button = Button(MobileBy.IOS_UIAUTOMATION, '.buttons()[0]')
244+
username = InputText(AppiumBy.IOS_UIAUTOMATION, '.textFields()[0]')
245+
password = InputText(AppiumBy.IOS_UIAUTOMATION, '.secureTextFields()[0]')
246+
login_button = Button(AppiumBy.IOS_UIAUTOMATION, '.buttons()[0]')
247247
248248
249249
Base, Android and iOS page objects must be defined in different files following this structure::

docs/remote_configuration.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ section in properties.cfg file::
1919
video_enabled: false
2020
logs_enabled: false
2121
log_types: all
22+
base_path:
2223

2324
enabled
2425
~~~~~~~
@@ -61,13 +62,19 @@ logs_enabled
6162
| *false*: webdriver and GGR logs are downloaded and saved to local files only if the test fails
6263
6364
log_types
64-
~~~~~~~~~~
65+
~~~~~~~~~
6566
| Comma-separated list of webdriver log types that will be downloaded if remote test fails or if *logs_enabled* is true
6667
|
6768
| *all*: all available log types in remote server will be downloaded (default value)
6869
| '': setting an empty string, no log types will be downloaded
6970
| *client,server*: in this example, only client and server logs will be downloaded
7071
72+
base_path
73+
~~~~~~~~~
74+
| Base path to use as prefix for all webdriver routes running on the server, empty by default.
75+
|
76+
| */wd/hub*: use this base path with old Selenium 3 or Appium 1 remote servers
77+
7178

7279
Remote Driver Capabilities
7380
--------------------------

toolium/config_driver.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _create_remote_driver(self):
102102
capabilities = self._get_capabilities_from_driver_type()
103103

104104
# Get server url
105-
server_url = f'{self.utils.get_server_url()}/wd/hub'
105+
server_url = f"{self.utils.get_server_url()}{self.config.get_optional('Server', 'base_path', '')}"
106106

107107
driver_name = self.utils.get_driver_name()
108108
if driver_name in ('android', 'ios', 'iphone'):
@@ -192,6 +192,7 @@ def _add_capabilities_from_properties(self, capabilities, section):
192192
cap_type = {'Capabilities': 'server', 'AppiumCapabilities': 'Appium server'}
193193
try:
194194
for cap, cap_value in dict(self.config.items(section)).items():
195+
cap = f'appium:{cap}' if section == 'AppiumCapabilities' else cap
195196
self.logger.debug("Added %s capability: %s = %s", cap_type[section], cap, cap_value)
196197
cap_value = cap_value if cap == 'browserVersion' else self._convert_property_type(cap_value)
197198
self._update_dict(capabilities, {cap: cap_value}, initial_key=cap)

toolium/test/conf/android-properties.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type: android
33
appium_app_strings: true
44

55
[AppiumCapabilities]
6-
automationName: Android
6+
automationName: UiAutomator2
77
platformName: Android
88
deviceName: Android Emulator
99
browserName:

toolium/test/conf/properties.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ selenoid___options: {'enableVNC': True, 'enableVideo': True}
4343
cloud___options: {'name': 'test'}
4444

4545
[AppiumCapabilities]
46-
automationName: Appium
46+
automationName: UiAutomator2
4747
platformName: Android
4848
deviceName: Android Emulator
4949
browserName:

toolium/test/test_config_driver_appium.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ def test_create_remote_driver_appium(appiumdriver_mock, driver_type, config, uti
7878

7979
config_driver._create_remote_driver()
8080

81+
# Check that appium options contain expected capabilities
82+
args, kwargs = appiumdriver_mock.Remote.call_args
83+
options = kwargs['options']
84+
assert isinstance(options, AppiumOptions)
85+
assert options.capabilities == expected_capabilities
86+
appiumdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
87+
88+
89+
@mock.patch('toolium.config_driver.appiumdriver')
90+
@pytest.mark.parametrize('driver_type', appium_driver_types)
91+
def test_create_remote_driver_appium_basepath(appiumdriver_mock, driver_type, config, utils):
92+
utils.get_driver_name.return_value = driver_type
93+
config.set('Driver', 'type', driver_type)
94+
config.set('Server', 'base_path', '/wd/hub')
95+
server_url = 'http://10.20.30.40:5555'
96+
utils.get_server_url.return_value = server_url
97+
config_driver = ConfigDriver(config, utils)
98+
DriverWrappersPool.output_directory = ''
99+
expected_capabilities = DEFAULT_CAPABILITIES
100+
101+
config_driver._create_remote_driver()
102+
81103
# Check that appium options contain expected capabilities
82104
args, kwargs = appiumdriver_mock.Remote.call_args
83105
options = kwargs['options']
@@ -92,15 +114,15 @@ def test_create_remote_driver_android_capabilities(appiumdriver_mock, config, ut
92114
utils.get_driver_name.return_value = driver_type
93115
config.set('Driver', 'type', driver_type)
94116
config.add_section('AppiumCapabilities')
95-
config.set('AppiumCapabilities', 'automationName', 'Appium')
117+
config.set('AppiumCapabilities', 'automationName', 'UiAutomator2')
96118
config.set('AppiumCapabilities', 'platformName', 'Android')
97119
server_url = 'http://10.20.30.40:5555'
98120
utils.get_server_url.return_value = server_url
99121
config_driver = ConfigDriver(config, utils)
100122
DriverWrappersPool.output_directory = ''
101123
expected_capabilities = DEFAULT_CAPABILITIES
102-
expected_capabilities['automationName'] = 'Appium'
103-
expected_capabilities['platformName'] = 'Android'
124+
expected_capabilities['appium:automationName'] = 'UiAutomator2'
125+
expected_capabilities['appium:platformName'] = 'Android'
104126

105127
config_driver._create_remote_driver()
106128

@@ -109,7 +131,7 @@ def test_create_remote_driver_android_capabilities(appiumdriver_mock, config, ut
109131
options = kwargs['options']
110132
assert isinstance(options, AppiumOptions)
111133
assert options.capabilities == expected_capabilities
112-
appiumdriver_mock.Remote.assert_called_once_with(command_executor=f'{server_url}/wd/hub', options=options)
134+
appiumdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
113135

114136

115137
@mock.patch('toolium.config_driver.appiumdriver')
@@ -118,15 +140,15 @@ def test_create_remote_driver_ios_capabilities(appiumdriver_mock, config, utils)
118140
utils.get_driver_name.return_value = driver_type
119141
config.set('Driver', 'type', driver_type)
120142
config.add_section('AppiumCapabilities')
121-
config.set('AppiumCapabilities', 'automationName', 'Appium')
143+
config.set('AppiumCapabilities', 'automationName', 'XCUITest')
122144
config.set('AppiumCapabilities', 'platformName', 'iOS')
123145
server_url = 'http://10.20.30.40:5555'
124146
utils.get_server_url.return_value = server_url
125147
config_driver = ConfigDriver(config, utils)
126148
DriverWrappersPool.output_directory = ''
127149
expected_capabilities = DEFAULT_CAPABILITIES
128-
expected_capabilities['automationName'] = 'Appium'
129-
expected_capabilities['platformName'] = 'iOS'
150+
expected_capabilities['appium:automationName'] = 'XCUITest'
151+
expected_capabilities['appium:platformName'] = 'iOS'
130152

131153
config_driver._create_remote_driver()
132154

@@ -135,4 +157,4 @@ def test_create_remote_driver_ios_capabilities(appiumdriver_mock, config, utils)
135157
options = kwargs['options']
136158
assert isinstance(options, AppiumOptions)
137159
assert options.capabilities == expected_capabilities
138-
appiumdriver_mock.Remote.assert_called_once_with(command_executor=f'{server_url}/wd/hub', options=options)
160+
appiumdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)

toolium/test/test_config_driver_chrome.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,25 @@ def test_create_remote_driver_chrome(webdriver_mock, config, utils):
245245

246246
config_driver._create_remote_driver()
247247

248+
# Check that chrome options contain expected capabilities
249+
args, kwargs = webdriver_mock.Remote.call_args
250+
options = kwargs['options']
251+
assert isinstance(options, Options)
252+
assert options.capabilities == expected_capabilities
253+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
254+
255+
256+
@mock.patch('toolium.config_driver.webdriver')
257+
def test_create_remote_driver_chrome_basepath(webdriver_mock, config, utils):
258+
config.set('Driver', 'type', 'chrome')
259+
config.set('Server', 'base_path', '/wd/hub')
260+
server_url = 'http://10.20.30.40:5555'
261+
utils.get_server_url.return_value = server_url
262+
config_driver = ConfigDriver(config, utils)
263+
expected_capabilities = DEFAULT_CAPABILITIES
264+
265+
config_driver._create_remote_driver()
266+
248267
# Check that chrome options contain expected capabilities
249268
args, kwargs = webdriver_mock.Remote.call_args
250269
options = kwargs['options']
@@ -270,7 +289,7 @@ def test_create_remote_driver_chrome_with_version_and_platform(webdriver_mock, c
270289
options = kwargs['options']
271290
assert isinstance(options, Options)
272291
assert options.capabilities == expected_capabilities
273-
webdriver_mock.Remote.assert_called_once_with(command_executor=f'{server_url}/wd/hub', options=options)
292+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
274293

275294

276295
@mock.patch('toolium.config_driver.webdriver')
@@ -290,4 +309,4 @@ def test_create_remote_driver_chrome_with_version_and_platform_uppercase(webdriv
290309
options = kwargs['options']
291310
assert isinstance(options, Options)
292311
assert options.capabilities == expected_capabilities
293-
webdriver_mock.Remote.assert_called_once_with(command_executor=f'{server_url}/wd/hub', options=options)
312+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)

toolium/test/test_config_driver_edge.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,26 @@ def test_create_remote_driver_edge(webdriver_mock, config, utils):
137137

138138
config_driver._create_remote_driver()
139139

140+
# Check that edge options contain expected capabilities
141+
args, kwargs = webdriver_mock.Remote.call_args
142+
options = kwargs['options']
143+
assert isinstance(options, Options)
144+
assert options.capabilities == expected_capabilities
145+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
146+
147+
148+
@mock.patch('toolium.config_driver.webdriver')
149+
def test_create_remote_driver_edge_basepath(webdriver_mock, config, utils):
150+
config.set('Driver', 'type', 'edge')
151+
config.set('Server', 'base_path', '/wd/hub')
152+
server_url = 'http://10.20.30.40:5555'
153+
utils.get_server_url.return_value = server_url
154+
config_driver = ConfigDriver(config, utils)
155+
DriverWrappersPool.output_directory = ''
156+
expected_capabilities = DEFAULT_CAPABILITIES
157+
158+
config_driver._create_remote_driver()
159+
140160
# Check that edge options contain expected capabilities
141161
args, kwargs = webdriver_mock.Remote.call_args
142162
options = kwargs['options']
@@ -163,7 +183,7 @@ def test_create_remote_driver_edge_with_version_and_platform(webdriver_mock, con
163183
options = kwargs['options']
164184
assert isinstance(options, Options)
165185
assert options.capabilities == expected_capabilities
166-
webdriver_mock.Remote.assert_called_once_with(command_executor=f'{server_url}/wd/hub', options=options)
186+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
167187

168188

169189
@mock.patch('toolium.config_driver.webdriver')
@@ -184,4 +204,4 @@ def test_create_remote_driver_edge_with_version_and_platform_uppercase(webdriver
184204
options = kwargs['options']
185205
assert isinstance(options, Options)
186206
assert options.capabilities == expected_capabilities
187-
webdriver_mock.Remote.assert_called_once_with(command_executor=f'{server_url}/wd/hub', options=options)
207+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)

toolium/test/test_config_driver_firefox.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,26 @@ def test_create_remote_driver_firefox(webdriver_mock, config, utils):
263263

264264
config_driver._create_remote_driver()
265265

266+
# Check that firefox options contain expected capabilities
267+
args, kwargs = webdriver_mock.Remote.call_args
268+
options = kwargs['options']
269+
assert isinstance(options, Options)
270+
assert options.capabilities == expected_capabilities
271+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
272+
273+
274+
@mock.patch('toolium.config_driver.webdriver')
275+
def test_create_remote_driver_firefox_basepath(webdriver_mock, config, utils):
276+
config.set('Driver', 'type', 'firefox')
277+
config.set('Server', 'base_path', '/wd/hub')
278+
server_url = 'http://10.20.30.40:5555'
279+
utils.get_server_url.return_value = server_url
280+
config_driver = ConfigDriver(config, utils)
281+
DriverWrappersPool.output_directory = ''
282+
expected_capabilities = DEFAULT_CAPABILITIES
283+
284+
config_driver._create_remote_driver()
285+
266286
# Check that firefox options contain expected capabilities
267287
args, kwargs = webdriver_mock.Remote.call_args
268288
options = kwargs['options']
@@ -289,7 +309,7 @@ def test_create_remote_driver_firefox_with_version_and_platform(webdriver_mock,
289309
options = kwargs['options']
290310
assert isinstance(options, Options)
291311
assert options.capabilities == expected_capabilities
292-
webdriver_mock.Remote.assert_called_once_with(command_executor=f'{server_url}/wd/hub', options=options)
312+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
293313

294314

295315
@mock.patch('toolium.config_driver.webdriver')
@@ -310,7 +330,7 @@ def test_create_remote_driver_firefox_with_version_and_platform_uppercase(webdri
310330
options = kwargs['options']
311331
assert isinstance(options, Options)
312332
assert options.capabilities == expected_capabilities
313-
webdriver_mock.Remote.assert_called_once_with(command_executor=f'{server_url}/wd/hub', options=options)
333+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
314334

315335

316336
@mock.patch('toolium.config_driver.webdriver')
@@ -331,7 +351,7 @@ def test_create_remote_driver_firefox_extension(webdriver_mock, config, utils):
331351
options = kwargs['options']
332352
assert isinstance(options, Options)
333353
assert options.capabilities == expected_capabilities
334-
webdriver_mock.Remote.assert_called_once_with(command_executor=f'{server_url}/wd/hub', options=options)
354+
webdriver_mock.Remote.assert_called_once_with(command_executor=server_url, options=options)
335355

336356
# Check that extension has been added to driver
337357
webdriver_mock.Firefox.install_addon.assert_called_once_with(webdriver_mock.Remote(),

0 commit comments

Comments
 (0)