Description
Description
Repro
git am
the patch below and run the new test with bazel test py:common-chrome
https://gist.github.com/victorvianna/d3930c0962b8fe322d6341b3f29f1fe5
Expected: works fine
Actual: "local variable 'ws_url' referenced before assignment"
We have concrete cases in Chromium benchmarks where this is a problem.
Root cause
devtools
is a global and thus outlives individual WebDrivers
. When start_devtools()
is called the second time, the if not devtools
block containing ws_url
initialization is skipped
Discussion
Having the devtools
auto-generated module be a global seems conceptually wrong. For one thing, this value depends on the browser version (the protocol changes over time). The least invasive change is probably to turn it into a WebDriver
member like _websocket_connection
.
On a separate note, I wonder:
-
Why was a global used in the first place? Would it be costly to include the module again on every call? Because
bidi_connection()
is doing exactly that ATM (notice how there's noglobal devtools
line in the function) -
_websocket_connection
a single central websocket, shared with other methods. But why limit to a single socket, why not return a new one on every call? Does the browser not support it? One advantage I could imagine is guaranteeing that WebDriver calls close() when its done, but that's not done right now AFAICT
Reproducible Code
See above
Debugging Logs
See above