Created
September 28, 2021 05:03
-
-
Save jimanx2/084ce5463109a545bc1f7c316c189f42 to your computer and use it in GitHub Desktop.
How to reconnect to existing session in appium server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Any, Dict, List, Optional, TypeVar, Union | |
| from appium import webdriver | |
| class AppiumWebDriver(webdriver.Remote): | |
| def __init__( | |
| self, | |
| session_id: None, | |
| command_executor: str = 'http://127.0.0.1:4444/wd/hub', | |
| browser_profile: str = None, | |
| proxy: str = None, | |
| keep_alive: bool = True, | |
| direct_connection: bool = False, | |
| ): | |
| desired_capabilities = dict( | |
| # define your capabilities here | |
| ) | |
| self._session_id = session_id | |
| self._capabilities = desired_capabilities | |
| super().__init__( | |
| command_executor, desired_capabilities, browser_profile, proxy, keep_alive, direct_connection | |
| ) | |
| def start_session(self, capabilities: Dict, browser_profile: Optional[str] = None) -> None: | |
| if self._session_id in (None, False, 0): | |
| super().start_session(capabilities, browser_profile) | |
| return | |
| """Connects with existing session with specified session id.""" | |
| self.session_id = self._session_id | |
| self.w3c = True | |
| self.command_executor.w3c = self.w3c |
Author
Author
# main.py
from .appium_webdriver import AppiumWebdriver
if __name__ == "__main__":
driver = AppiumWebdriver() # for new session
sessionid = driver.session_id
sessionurl = driver.command_executor._url
# later reconnect like follows:
driver = AppiumWebdriver(sessionid, sessionurl)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is to save precious time reinitializing new session by appium