Quits the driver only if it's not the default/initial driver. If a driver is given, quits that, otherwise quits the active driver. Raises an Exception if quitting the default/initial driver. Should only be called if a test has already called get_new_driver(). Afterwar
(self, driver=None)
| 11436 | ############ |
| 11437 | |
| 11438 | def quit_extra_driver(self, driver=None): |
| 11439 | """Quits the driver only if it's not the default/initial driver. |
| 11440 | If a driver is given, quits that, otherwise quits the active driver. |
| 11441 | Raises an Exception if quitting the default/initial driver. |
| 11442 | Should only be called if a test has already called get_new_driver(). |
| 11443 | Afterwards, self.driver points to the default/initial driver |
| 11444 | if self.driver was the one being quit. |
| 11445 | ---- |
| 11446 | If a test never calls get_new_driver(), this method isn't needed. |
| 11447 | SeleniumBase automatically quits browsers after tests have ended. |
| 11448 | Even if tests do call get_new_driver(), you don't need to use this |
| 11449 | method unless you want to quit extra browsers before a test ends. |
| 11450 | ---- |
| 11451 | Terminology and important details: |
| 11452 | * Active driver: The one self.driver is set to. Used within methods. |
| 11453 | * Default/initial driver: The one that is spun up when tests start. |
| 11454 | Initially, the active driver and the default driver are the same. |
| 11455 | The active driver can change when one of these methods is called: |
| 11456 | > self.get_new_driver() |
| 11457 | > self.switch_to_default_driver() |
| 11458 | > self.switch_to_driver() |
| 11459 | > self.quit_extra_driver() """ |
| 11460 | self.__check_scope() |
| 11461 | if not driver: |
| 11462 | driver = self.driver |
| 11463 | if type(driver).__name__ == "NoneType": |
| 11464 | raise Exception("The driver to quit was a NoneType variable!") |
| 11465 | elif ( |
| 11466 | not hasattr(driver, "get") |
| 11467 | or not hasattr(driver, "name") |
| 11468 | or not hasattr(driver, "quit") |
| 11469 | or not hasattr(driver, "capabilities") |
| 11470 | or not hasattr(driver, "window_handles") |
| 11471 | ): |
| 11472 | raise Exception("The driver to quit does not match a Driver!") |
| 11473 | elif self._reuse_session and driver == self._default_driver: |
| 11474 | raise Exception( |
| 11475 | "Cannot quit the initial driver in --reuse-session mode!\n" |
| 11476 | "This is done automatically after all tests have ended.\n" |
| 11477 | "Use this method only if get_new_driver() has been called." |
| 11478 | ) |
| 11479 | elif ( |
| 11480 | driver == self._default_driver |
| 11481 | or (driver in self._drivers_list and len(self._drivers_list) == 1) |
| 11482 | ): |
| 11483 | raise Exception( |
| 11484 | "Cannot quit the default/initial driver!\n" |
| 11485 | "This is done automatically at the end of each test.\n" |
| 11486 | "Use this method only if get_new_driver() has been called." |
| 11487 | ) |
| 11488 | try: |
| 11489 | if ( |
| 11490 | not is_windows |
| 11491 | or self.browser == "ie" |
| 11492 | or driver.service.process |
| 11493 | ): |
| 11494 | driver.quit() |
| 11495 | except AttributeError: |