Skip to content

Edge-case when saving a screenshot for the logs when using multiple drivers in one test #857

@mdmintz

Description

@mdmintz

Edge-case when saving a screenshot for the logs when using multiple drivers in one test.

There's a very specific edge case that can occur if a test opens a second browser driver using self.get_new_driver() and then the user navigates to an unresponsive page (or the browser window is closed) if there is also a custom tearDown() method that navigates back to the original driver. Currently, the screenshot that would appear in the logs would be of the original driver browser that is also open. The expected behavior here should be that if the screenshot can't be taken using self.save_teardown_screenshot() in the custom tearDown() (because a site is unresponsive or the browser window closed prematurely), then there should be no screenshot at all in the logs, because that would be misleading. The screenshot should match the page where a stack trace occurred.

Here's an example that reproduces the bug:

from seleniumbase import BaseCase

class MyTestClass(BaseCase):

    def tearDown(self):
        self.save_teardown_screenshot()
        self.switch_to_default_driver()
        super(MyTestClass, self).tearDown()

    def test_steps_to_reproduce_bug(self):
        self.open("https://xkcd.com/353/")
        self.get_new_driver()
        self.driver.quit()  # Simulate an unresponsive site
        self.assert_element("fake.item", timeout=1)

Adding a related error message in the page_source.html file in the logs would also be helpful.

Metadata

Metadata

Assignees

Labels

bugUh oh... Something needs to be fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions