Skip to content

Update examples test Chrome/Edge run on Ubuntu 24.04 hosted runners #2139

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

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented Jan 21, 2025

User description

Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.

Description

Recently, GitHub updated ubuntu-latest from 22.04 to 24.04.
In this update, it looks like Chrome/Edge didn't wrap with --no-sandbox by default anymore.
Which causes the error

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir

Refer to an explanation https://stackoverflow.com/questions/70385737/selenium-common-exceptions-invalidargumentexception-message-invalid-argument

Update ChromeOptions/EdgeOptions always append argument --no-sandbox when creating WebDriver looks like a solution till now. It makes CI is green back.

Motivation and Context

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

PR Type

Bug fix, Tests


Description

  • Added --no-sandbox argument to Chrome and Edge options to resolve browser initialization issues on Ubuntu 24.04.

  • Introduced get_default_options utility functions for Chrome and Edge in Python and Java tests.

  • Updated all relevant test cases to use the new default options functions.

  • Enhanced test reliability and compatibility with updated GitHub Actions runners.


Changes walkthrough 📝

Relevant files
Tests
16 files
test_chrome.py
Refactored Chrome tests to use `get_default_options`         
+11/-6   
test_edge.py
Refactored Edge tests to use `get_default_options`             
+11/-6   
conftest.py
Added `--no-sandbox` to Chrome options in fixtures             
+3/-0     
test_http_client.py
Refactored HTTP client tests to use `get_default_options`
+7/-2     
test_options.py
Refactored options tests to use `get_default_options`       
+18/-13 
test_remote_webdriver.py
Refactored remote WebDriver tests to use `get_default_options`
+8/-3     
test_service.py
Refactored service tests to use `get_default_options`       
+6/-1     
CdpApiTest.java
Updated CDP API test to use default Chrome options             
+1/-1     
ChromeTest.java
Refactored Chrome browser tests to use default options     
+7/-7     
EdgeTest.java
Refactored Edge browser tests to use default options         
+7/-7     
HttpClientTest.java
Updated HTTP client tests to use default Chrome options   
+3/-3     
OptionsTest.java
Refactored options tests to use default Chrome options     
+13/-13 
RemoteWebDriverTest.java
Updated remote WebDriver tests to use default Chrome options
+5/-5     
ServiceTest.java
Refactored service tests to use default Chrome options     
+2/-2     
AlertsTest.java
Updated alerts test to use default Chrome options               
+3/-2     
PrintsPageTest.java
Updated prints page test to use default Chrome options     
+1/-1     
Enhancement
1 files
BaseTest.java
Added utility methods for default Chrome and Edge options
+13/-0   

Need help?
  • Type /help how to ... in the comments thread for any question about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 Security concerns

    Browser sandbox bypass:
    The PR adds the --no-sandbox flag to Chrome/Edge options which disables the browser sandbox security feature. While this may be needed for CI environments, it reduces security isolation between browser processes and the host system. This should only be used in trusted environments.

    ⚡ Recommended focus areas for review

    Redundant Configuration

    The --no-sandbox flag is added multiple times in different fixtures. Consider consolidating the browser options configuration into a single helper function to avoid duplication.

            options.add_argument("--no-sandbox")
            options.enable_bidi = True
            driver = webdriver.Chrome(options=options)
        elif driver_type == "firefox":
            driver = webdriver.Firefox()
        else:
            driver = webdriver.Chrome()
    
        yield driver
    
        driver.quit()
    
    
    @pytest.fixture(scope='function')
    def chromedriver_bin():
        service = webdriver.ChromeService()
        options = webdriver.ChromeOptions()
        options.add_argument("--no-sandbox")
        options.browser_version = 'stable'

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Ensure proper driver cleanup

    Add a try-finally block to ensure driver cleanup in case of test failure. The
    driver.quit() should be in the finally block to guarantee proper resource cleanup.

    examples/python/tests/drivers/test_options.py [9-11]

     driver = webdriver.Chrome(options=options)
    -driver.get("https://www.selenium.dev/")
    -driver.quit()
    +try:
    +    driver.get("https://www.selenium.dev/")
    +finally:
    +    driver.quit()
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding a try-finally block is important for ensuring proper cleanup of WebDriver resources even if test fails, preventing resource leaks and browser processes from being orphaned.

    8

    Copy link

    netlify bot commented Jan 21, 2025

    Deploy Preview for selenium-dev ready!

    Name Link
    🔨 Latest commit 4ccf4d4
    🔍 Latest deploy log https://app.netlify.com/sites/selenium-dev/deploys/678f63206410af0008c79a1d
    😎 Deploy Preview https://deploy-preview-2139--selenium-dev.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    @VietND96 VietND96 merged commit f85c1de into trunk Jan 21, 2025
    18 checks passed
    @VietND96 VietND96 deleted the rerun-java branch January 21, 2025 09:45
    @VietND96
    Copy link
    Member Author

    @harsha509, I saw Js examples test run on Ubuntu with few cases are failing the same. Do you want to add arg --no-sandbox?

    alindeman added a commit to jeremiaheb/EntryApplication that referenced this pull request Feb 12, 2025
    alindeman added a commit to jeremiaheb/EntryApplication that referenced this pull request Feb 12, 2025
    alindeman added a commit to jeremiaheb/EntryApplication that referenced this pull request Feb 12, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant