|
21 | 21 | from appium import webdriver |
22 | 22 | from appium.options.android import UiAutomator2Options |
23 | 23 | from appium.webdriver.appium_connection import AppiumConnection |
24 | | -from appium.webdriver.webdriver import ExtensionBase, WebDriver |
| 24 | +from appium.webdriver.client_config import AppiumClientConfig |
| 25 | +from appium.webdriver.webdriver import ExtensionBase, WebDriver, _get_remote_connection_and_client_config |
25 | 26 | from test.helpers.constants import SERVER_URL_BASE |
26 | 27 | from test.unit.helper.test_helper import ( |
27 | 28 | android_w3c_driver, |
@@ -124,10 +125,11 @@ def test_create_session_register_uridirect(self): |
124 | 125 | 'app': 'path/to/app', |
125 | 126 | 'automationName': 'UIAutomator2', |
126 | 127 | } |
| 128 | + client_config = AppiumClientConfig(remote_server_addr=SERVER_URL_BASE, direct_connection=True) |
127 | 129 | driver = webdriver.Remote( |
128 | 130 | SERVER_URL_BASE, |
129 | 131 | options=UiAutomator2Options().load_capabilities(desired_caps), |
130 | | - direct_connection=True, |
| 132 | + client_config=client_config, |
131 | 133 | ) |
132 | 134 |
|
133 | 135 | assert 'http://localhost2:4800/special/path/wd/hub' == driver.command_executor._client_config.remote_server_addr |
@@ -164,16 +166,54 @@ def test_create_session_register_uridirect_no_direct_connect_path(self): |
164 | 166 | 'app': 'path/to/app', |
165 | 167 | 'automationName': 'UIAutomator2', |
166 | 168 | } |
| 169 | + client_config = AppiumClientConfig(remote_server_addr=SERVER_URL_BASE, direct_connection=True) |
167 | 170 | driver = webdriver.Remote( |
168 | | - SERVER_URL_BASE, |
169 | | - options=UiAutomator2Options().load_capabilities(desired_caps), |
170 | | - direct_connection=True, |
| 171 | + SERVER_URL_BASE, options=UiAutomator2Options().load_capabilities(desired_caps), client_config=client_config |
171 | 172 | ) |
172 | 173 |
|
173 | 174 | assert SERVER_URL_BASE == driver.command_executor._client_config.remote_server_addr |
174 | 175 | assert ['NATIVE_APP', 'CHROMIUM'] == driver.contexts |
175 | 176 | assert isinstance(driver.command_executor, AppiumConnection) |
176 | 177 |
|
| 178 | + @httpretty.activate |
| 179 | + def test_create_session_remote_server_addr_treatment_with_appiumclientconfig(self): |
| 180 | + # remote server add in AppiumRemoteCong will be prior than the string of 'command_executor' |
| 181 | + # as same as Selenium behavior. |
| 182 | + httpretty.register_uri( |
| 183 | + httpretty.POST, |
| 184 | + f'{SERVER_URL_BASE}/session', |
| 185 | + body=json.dumps( |
| 186 | + { |
| 187 | + 'sessionId': 'session-id', |
| 188 | + 'capabilities': { |
| 189 | + 'deviceName': 'Android Emulator', |
| 190 | + }, |
| 191 | + } |
| 192 | + ), |
| 193 | + ) |
| 194 | + |
| 195 | + httpretty.register_uri( |
| 196 | + httpretty.GET, |
| 197 | + f'{SERVER_URL_BASE}/session/session-id/contexts', |
| 198 | + body=json.dumps({'value': ['NATIVE_APP', 'CHROMIUM']}), |
| 199 | + ) |
| 200 | + |
| 201 | + desired_caps = { |
| 202 | + 'platformName': 'Android', |
| 203 | + 'deviceName': 'Android Emulator', |
| 204 | + 'app': 'path/to/app', |
| 205 | + 'automationName': 'UIAutomator2', |
| 206 | + } |
| 207 | + client_config = AppiumClientConfig(remote_server_addr=SERVER_URL_BASE, direct_connection=True) |
| 208 | + driver = webdriver.Remote( |
| 209 | + 'http://localhost:8080/something/path', |
| 210 | + options=UiAutomator2Options().load_capabilities(desired_caps), |
| 211 | + client_config=client_config, |
| 212 | + ) |
| 213 | + |
| 214 | + assert SERVER_URL_BASE == driver.command_executor._client_config.remote_server_addr |
| 215 | + assert isinstance(driver.command_executor, AppiumConnection) |
| 216 | + |
177 | 217 | @httpretty.activate |
178 | 218 | def test_get_events(self): |
179 | 219 | driver = ios_w3c_driver() |
@@ -380,21 +420,54 @@ def test_extention_command_check(self): |
380 | 420 | 'script': 'mobile: startActivity', |
381 | 421 | } == get_httpretty_request_body(httpretty.last_request()) |
382 | 422 |
|
| 423 | + def test_get_client_config_and_connection_with_empty_config(self): |
| 424 | + command_executor, client_config = _get_remote_connection_and_client_config( |
| 425 | + command_executor='http://127.0.0.1:4723', client_config=None |
| 426 | + ) |
| 427 | + |
| 428 | + assert isinstance(command_executor, AppiumConnection) |
| 429 | + assert command_executor._client_config == client_config |
| 430 | + assert isinstance(client_config, AppiumClientConfig) |
| 431 | + assert client_config.remote_server_addr == 'http://127.0.0.1:4723' |
| 432 | + |
| 433 | + def test_get_client_config_and_connection(self): |
| 434 | + command_executor, client_config = _get_remote_connection_and_client_config( |
| 435 | + command_executor='http://127.0.0.1:4723', |
| 436 | + client_config=AppiumClientConfig(remote_server_addr='http://127.0.0.1:4723/wd/hub'), |
| 437 | + ) |
| 438 | + |
| 439 | + assert isinstance(command_executor, AppiumConnection) |
| 440 | + # the client config in the command_executor is the given client config. |
| 441 | + assert command_executor._client_config == client_config |
| 442 | + assert isinstance(client_config, AppiumClientConfig) |
| 443 | + assert client_config.remote_server_addr == 'http://127.0.0.1:4723/wd/hub' |
| 444 | + |
| 445 | + def test_get_client_config_and_connection_custom_appium_connection(self): |
| 446 | + c_config = AppiumClientConfig(remote_server_addr='http://127.0.0.1:4723') |
| 447 | + appium_connection = AppiumConnection(client_config=c_config) |
| 448 | + |
| 449 | + command_executor, client_config = _get_remote_connection_and_client_config( |
| 450 | + command_executor=appium_connection, client_config=AppiumClientConfig(remote_server_addr='http://127.0.0.1:4723') |
| 451 | + ) |
| 452 | + |
| 453 | + assert isinstance(command_executor, AppiumConnection) |
| 454 | + # client config already defined in the command_executor will be used. |
| 455 | + assert command_executor._client_config != client_config |
| 456 | + assert client_config is None |
| 457 | + |
383 | 458 |
|
384 | 459 | class SubWebDriver(WebDriver): |
385 | | - def __init__(self, command_executor, direct_connection=False, options=None): |
| 460 | + def __init__(self, command_executor, options=None): |
386 | 461 | super().__init__( |
387 | 462 | command_executor=command_executor, |
388 | | - direct_connection=direct_connection, |
389 | 463 | options=options, |
390 | 464 | ) |
391 | 465 |
|
392 | 466 |
|
393 | 467 | class SubSubWebDriver(SubWebDriver): |
394 | | - def __init__(self, command_executor, direct_connection=False, options=None): |
| 468 | + def __init__(self, command_executor, options=None): |
395 | 469 | super().__init__( |
396 | 470 | command_executor=command_executor, |
397 | | - direct_connection=direct_connection, |
398 | 471 | options=options, |
399 | 472 | ) |
400 | 473 |
|
|
0 commit comments