Test Automation Best Practices: Pinning Browser Version in Selenium Python for Stability
Introduction
Ensuring browser compatibility is crucial to maintaining test stability when running Selenium tests in a CI/CD pipeline. Recently, while executing tests in my Selenium Python example project, I encountered a breaking issue related to ChromeDriver v133 and Xvfb. This issue prevented Selenium from executing JavaScript code properly, causing tests to fail unexpectedly.
In this article, I'll walk you through the issue, its root cause, and the solution I implemented to restore test execution.
The Problem
During a test run, I observed the following log output in the GitHub actions workflow run:
The key takeaway from this error log was:
The Solution
The solution code can be found here.
领英推荐
After debugging the issue, I found that Chrome v133 had a compatibility problem when used with Xvfb in Selenium tests. The simplest solution was to pin the browser version to v132 using Selenium’s built-in browser version setting.
Here’s the fix that worked for me:
Why This Works
By explicitly setting chrome_options.browser_version = "132", we instruct Selenium Manager to:
Key Takeaways
Conclusion
Implementing this solution resolved the issues in my Selenium tests. If you're experiencing similar challenges in your automation pipeline, consider pinning your browser version to maintain stability.
Happy testing!