create creates new instance of WebDriver if necessary, assign defined (or newly generated) session_id to the instance and returns the session object. If a new session has been created second argument is set to True. Note: The function is idempotent, so in case if ses
(self, session_id: Optional[str] = None, proxy: Optional[dict] = None,
force_new: Optional[bool] = False)
| 26 | self.sessions = {} |
| 27 | |
| 28 | def create(self, session_id: Optional[str] = None, proxy: Optional[dict] = None, |
| 29 | force_new: Optional[bool] = False) -> Tuple[Session, bool]: |
| 30 | """create creates new instance of WebDriver if necessary, |
| 31 | assign defined (or newly generated) session_id to the instance |
| 32 | and returns the session object. If a new session has been created |
| 33 | second argument is set to True. |
| 34 | |
| 35 | Note: The function is idempotent, so in case if session_id |
| 36 | already exists in the storage a new instance of WebDriver won't be created |
| 37 | and existing session will be returned. Second argument defines if |
| 38 | new session has been created (True) or an existing one was used (False). |
| 39 | """ |
| 40 | session_id = session_id or str(uuid1()) |
| 41 | |
| 42 | if force_new: |
| 43 | self.destroy(session_id) |
| 44 | |
| 45 | if self.exists(session_id): |
| 46 | return self.sessions[session_id], False |
| 47 | |
| 48 | driver = utils.get_webdriver(proxy) |
| 49 | created_at = datetime.now() |
| 50 | session = Session(session_id, driver, created_at) |
| 51 | |
| 52 | self.sessions[session_id] = session |
| 53 | |
| 54 | return session, True |
| 55 | |
| 56 | def exists(self, session_id: str) -> bool: |
| 57 | return session_id in self.sessions |
no test coverage detected