Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splinter tests not failing when element not found on the page and wait_time set to 1 second #1284

Closed
nburt opened this issue May 28, 2024 · 1 comment
Labels

Comments

@nburt
Copy link

nburt commented May 28, 2024

I first mentioned this issue here and opening a separate issue as requested.

I don't have an error message to share because the test just hangs. However, I have been able to reproduce the error and I believe the issue is caused by freezegun.

The test in question uses the following Splinter configuration:

from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from splinter import Browser, Config


class SplinterTestCase(StaticLiveServerTestCase):

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        config = Config(headless=True)
        cls.browser = Browser('chrome', config=config, wait_time=1)

    @classmethod
    def tearDownClass(cls):
        cls.browser.quit()
        super().tearDownClass()

    def tearDown(self):
        super().tearDown()

The following test fails with splinter.exceptions.ElementDoesNotExist: no elements could be found with text "Model does not exist"

class AdminTest(SplinterTestCase):
    def setUp(self):
        superuser = create_superuser()
        self.browser.visit(self.live_server_url + "/admin/")

        self.browser.fill("username", superuser.email)
        self.browser.fill("password", "password")
        self.browser.find_by_value('Log in').click()

    def test_splinter_hang(self):
        self.browser.find_by_text('Model does not exist').click()
        self.assertTrue(True)

However, if I freeze the date, it hangs:

@freeze_time("2024-05-21")
class AdminTest(SplinterTestCase):
    def setUp(self):
        superuser = create_superuser()
        self.browser.visit(self.live_server_url + "/admin/")

        self.browser.fill("username", superuser.email)
        self.browser.fill("password", "password")
        self.browser.find_by_value('Log in').click()


    def test_splinter_hang(self):
        print(datetime.now())
        self.browser.find_by_text('Model does not exist').click()
        self.assertTrue(True)

I assume this is caused by freezegun stubbing datetime which is used for the wait_time object. I am able to get test failures when I manually stop and start freezegun (see below) so I probably could wrap splinter element finders with something like this but wondering if there's another way to make that work.

class AdminTest(SplinterTestCase):
    def setUp(self):
        self.freezer = freeze_time("2024-05-21")
        self.freezer.start()

        superuser = create_superuser()
        self.browser.visit(self.live_server_url + "/admin/")

        self.browser.fill("username", superuser.email)
        self.browser.fill("password", "password")
        self.browser.find_by_value('Log in').click()

    def tearDown(self):
        self.freezer.stop()

    def test_splinter_hang(self):
        self.freezer.stop()
        self.browser.find_by_text('Model does not exist').click()
        self.freezer.start()
        self.assertTrue(True)
@nburt
Copy link
Author

nburt commented Jun 5, 2024

Was able to figure this out using freezegun.configure: freezegun.configure(default_ignore_list=['splinter'])

Not an issue with splinter, closing

@nburt nburt closed this as completed Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants