Skip to content

[rust] Offline mode in Selenium Manager (#11639) - #12373

Merged
diemol merged 1 commit into
trunkfrom
se_mgr_offline
Jul 19, 2023
Merged

[rust] Offline mode in Selenium Manager (#11639)#12373
diemol merged 1 commit into
trunkfrom
se_mgr_offline

Conversation

@bonigarcia

Copy link
Copy Markdown
Member

Description

This PR includes a new flag in Selenium Manager called --offline that forbids making any network call from Selenium Manager. This way, Selenium Manager can only execute shell commands to find drivers in PATH (and browser binary paths).

Selenium Manager throws no errors but warnings when the offline mode is enabled. The following snippets showcase its behavior for different cases:

Offline mode with empty cache

C:\Users\boni\Documents\dev\selenium\rust>cargo run -- --browser chrome --debug --clear-cache --offline
    Finished dev [unoptimized + debuginfo] target(s) in 0.23s
     Running `target\debug\selenium-manager.exe --browser chrome --debug --clear-cache --offline`
DEBUG   Clearing cache at: C:\Users\boni\.cache\selenium
DEBUG   Running command: "chromedriver --version"
DEBUG   Output: ""
DEBUG   Using shell command to find out chrome version
DEBUG   Running command: "set PFILES=%PROGRAMFILES: (x86)=%&& wmic datafile where name='!PFILES:\\=\\\\!\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe' get Version /value"
DEBUG   Output: "\r\r\n\r\r\nVersion=114.0.5735.199\r\r\n\r\r\n\r\r\n\r"
DEBUG   Detected browser: chrome 114.0.5735.199
WARN    Unable to discover proper chromedriver version in offline mode

Offline mode with driver in cache

C:\Users\boni\Documents\dev\selenium\rust>cargo run -- --browser chrome --debug --offline
    Finished dev [unoptimized + debuginfo] target(s) in 0.23s
     Running `target\debug\selenium-manager.exe --browser chrome --debug --offline`
DEBUG   Running command: "chromedriver --version"
DEBUG   Output: ""
DEBUG   Using shell command to find out chrome version
DEBUG   Running command: "set PFILES=%PROGRAMFILES: (x86)=%&& wmic datafile where name='!PFILES:\\=\\\\!\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe' get Version /value"
DEBUG   Output: "\r\r\n\r\r\nVersion=114.0.5735.199\r\r\n\r\r\n\r\r\n\r"
DEBUG   Detected browser: chrome 114.0.5735.199
DEBUG   Required driver: chromedriver 114.0.5735.90
DEBUG   chromedriver 114.0.5735.90 already in the cache
INFO    C:\Users\boni\.cache\selenium\chromedriver\win64\114.0.5735.90\chromedriver.exe

Offline mode with driver in PATH

C:\Users\boni\Documents\dev\selenium\rust>cargo run -- --browser chrome --debug --offline
    Finished dev [unoptimized + debuginfo] target(s) in 0.23s
     Running `target\debug\selenium-manager.exe --browser chrome --debug --offline`
DEBUG   Running command: "chromedriver --version"
DEBUG   Output: "ChromeDriver 107.0.5304.62 (1eec40d3a5764881c92085aaee66d25075c159aa-refs/branch-heads/5304@{#942})"
DEBUG   Running command: "where chromedriver"
DEBUG   Output: "C:\\Users\\boni\\Documents\\bat\\chromedriver.exe"
DEBUG   Found chromedriver 107.0.5304.62 in PATH: C:\Users\boni\Documents\bat\chromedriver.exe
DEBUG   Using shell command to find out chrome version
DEBUG   Running command: "set PFILES=%PROGRAMFILES: (x86)=%&& wmic datafile where name='!PFILES:\\=\\\\!\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe' get Version /value"
DEBUG   Output: "\r\r\n\r\r\nVersion=114.0.5735.199\r\r\n\r\r\n\r\r\n\r"
DEBUG   Detected browser: chrome 114.0.5735.199
WARN    Exception trying to discover chromedriver version: Unable to discover proper chromedriver version in offline mode
INFO    C:\Users\boni\Documents\bat\chromedriver.exe

As usual, the flag --offline flag is equivalent to using the configuration file (offline = true) or an environment variable SE_OFFLINE=true.

Motivation and Context

This PR implements #11639.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@bonigarcia bonigarcia added the C-rust Rust code is mostly Selenium Manager label Jul 17, 2023
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Patch and project coverage have no change.

Comparison is base (ca60c22) 57.28% compared to head (f0186fc) 57.28%.

❗ Current head f0186fc differs from pull request most recent head aff71bc. Consider uploading reports for the commit aff71bc to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #12373   +/-   ##
=======================================
  Coverage   57.28%   57.28%           
=======================================
  Files          86       86           
  Lines        5333     5333           
  Branches      193      193           
=======================================
  Hits         3055     3055           
  Misses       2085     2085           
  Partials      193      193           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@titusfortner

Copy link
Copy Markdown
Member

Excellent!

My only concern is would it confuse people to set SE_OFFLINE if it only applies to Selenium manager?

I know it follows the convention we use elsewhere, so wondering if a different name might be more clear?

@bonigarcia

Copy link
Copy Markdown
Member Author

My only concern is would it confuse people to set SE_OFFLINE if it only applies to Selenium manager?

I know it follows the convention we use elsewhere, so wondering if a different name might be more clear?

Yes, the prefix SE_ is the behavior defined by default for environment variables (see doc). But that prefix can be easily changed in this line. If we do that, all the envs will follow the new notation (e.g., SE_MGR_PROXY, SE_MGR_OFFLINE, SE_MGR_BROWSER, etc.).

@titusfortner

Copy link
Copy Markdown
Member

I think I would prefer that? But I'll agree with whatever Diego thinks is best overall.

@bonigarcia
bonigarcia requested a review from diemol July 18, 2023 20:22
@diemol

diemol commented Jul 19, 2023

Copy link
Copy Markdown
Member

I think we can leave SE_ for now, we don't have so many things around to add more prefixes.

@diemol diemol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @bonigarcia!

@diemol
diemol merged commit 4173713 into trunk Jul 19, 2023
@diemol
diemol deleted the se_mgr_offline branch July 19, 2023 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-rust Rust code is mostly Selenium Manager

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants