Selenium/Python tests pass locally but fail (element not visible/interactable) with Gitlab runner?

Hello everyone!

I’ve been having an especially frustrating time trying to get some tests to pass on the CI. I have a set of tests created with pytest that use selenium to crawl through our app and verify that all of the user flow is functional. These tests all pass locally and are dockerized. For some reason though, the tests fail on the CI, erroring out that an element is not interactable because it is not visible. The issue is, when looking at the screen shot that is taken on test failure, one can see that the element seems to be visible and interactable. It also appears that the app is running in mobile view instead of the properly configured 1920x1080. Again, this test can pass headlessly in the local environment.

I tested it today locally but with the gitlab runner. It ends up being the same error, so it would appear that this is an issue with the gitlab runner itself. I don’t have much experience with the specifics of gitlab runner, and I haven’t been able to find any resources that explain a similar problem. Does anyone have any ideas about what might be causing this behavior?

We are using docker 18.09.7, selenium 3.141.0, and driving firefox 66.0.5. You can see the screen shot on failure below:

screenshot-test_signup-failure-2020-08-20-16:50:10

And to compare resolutions, here’s the successful screen shot of the same test:

I’m not sure why the resolution is different at all. As far as I understand, it should be the same as its set up within the test due to the fact that its in docker.

Thank you very much for reading! Any thoughts and ideas would be tremendously helpful!

For anyone that may have found this that’s struggling with a similar issue, I finally solved this! The solution was to use pyvirtualdisplay with the context manager. For more details: