MCPcopy
hub / github.com/appium/python-client / start_session

Method start_session

appium/webdriver/webdriver.py:331–363  ·  view source on GitHub ↗

Creates a new session with the desired capabilities. Override for Appium Args: capabilities: Read https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md for more details. browser_profile: Browser profile

(self, capabilities: Union[Dict, AppiumOptions], browser_profile: Optional[str] = None)

Source from the content-addressed store, hash-verified

329 # https://github.com/SeleniumHQ/selenium/blob/06fdf2966df6bca47c0ae45e8201cd30db9b9a49/py/selenium/webdriver/remote/webdriver.py#L277
330 # noinspection PyAttributeOutsideInit
331 def start_session(self, capabilities: Union[Dict, AppiumOptions], browser_profile: Optional[str] = None) -> None:
332 """Creates a new session with the desired capabilities.
333
334 Override for Appium
335
336 Args:
337 capabilities: Read https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
338 for more details.
339 browser_profile: Browser profile
340 """
341 if not isinstance(capabilities, (dict, AppiumOptions)):
342 raise InvalidArgumentException('Capabilities must be a dictionary or AppiumOptions instance')
343
344 w3c_caps = AppiumOptions.as_w3c(capabilities) if isinstance(capabilities, dict) else capabilities.to_w3c()
345 response = self.execute(RemoteCommand.NEW_SESSION, w3c_caps)
346 # https://w3c.github.io/webdriver/#new-session
347 if not isinstance(response, dict):
348 raise SessionNotCreatedException(
349 f'A valid W3C session creation response must be a dictionary. Got "{response}" instead'
350 )
351 # Due to a W3C spec parsing misconception some servers
352 # pack the createSession response stuff into 'value' dictionary and
353 # some other put it to the top level of the response JSON nesting hierarchy
354 get_response_value: Callable[[str], Optional[Any]] = lambda key: (
355 response.get(key) or (response['value'].get(key) if isinstance(response.get('value'), dict) else None)
356 )
357 session_id = get_response_value('sessionId')
358 if not session_id:
359 raise SessionNotCreatedException(
360 f'A valid W3C session creation response must contain a non-empty "sessionId" entry. Got "{response}" instead'
361 )
362 self.session_id = session_id
363 self.caps = get_response_value('capabilities') or {}
364
365 def get_status(self) -> Dict:
366 """

Callers

nothing calls this directly

Calls 3

as_w3cMethod · 0.80
to_w3cMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected