I figured out how to do this for my Ruby on Rails app that uses RSpec and Capybara. Here's the code that I use to configure my Capybara driver to select the Console tab and dock the devtools to the bottom:
options = Selenium::WebDriver::Chrome::Options.new
options.add_preference(
'devtools',
'preferences' => {
'currentDockState' => '"bottom"', # Or '"undocked"', '"right"', etc.
'panel-selectedTab' => '"console"',
}
)
...
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options,
desired_capabilities: capabilities,
You should be able to call the setUserPreferences
function to set user preferences: https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/chrome_exports_Options.html#setUserPreferences
const { Options } = require('selenium-webdriver/chrome');
// …
const options = new Options().addArguments([
"auto-open-devtools-for-tabs"
]).setUserPreferences({
"devtools": {
"preferences": {
"panel-selectedTab": "\"console\""
// "currentDockState": "\"bottom\"" // Or "\"undocked\"", "\"right\"", etc.
}
}
});
(I haven't tested this for JS, so please try it out and let me know if it works.)
I figured out how to set these preferences by looking at ~/Library/Application Support/Google/Chrome/Default/Preferences
. This is where my main Google Chrome installation stores my user preferences, and it's JSON data.
You can view all of the possible settings under devtools
=> preferences
. Note that all the values are strings that are parsed as JSON, so you need to "double-wrap" any strings in your code, e.g. "\"console\""
.
You can open your main Google Chrome browser and change the settings in the UI, and then re-open your Preferences file to see what JSON you need to set.
"panel-selected-tab"
with a hyphen from chrome://prefs-internals/. the camelcase didn't work for me (mac chrome v126.0.6478.127) – Mindoro