1"use strict";(globalThis.webpackChunkserenity_users_guide=globalThis.webpackChunkserenity_users_guide||[]).push([[8207],{6183(e){e.exports=JSON.parse('{"permalink":"/es/blog/2023/02/02/index","editUrl":"https://johnfergusonsmart.com/blog/blog/2023-02-02/index.md","source":"@site/blog/2023-02-02/index.md","title":"How To Configure Chrome In Serenity BDD","description":"These days Selenium is moving at a neck-breaking pace, and there are quite a few small changes coming through in the driver configuration options. And since Serenity BDD has many shortcuts to handle these options, it\'s worth knowing what has changed, what won\'t work any more, and what you need to update.","date":"2023-02-02T00:00:00.000Z","tags":[],"readingTime":3.79,"hasTruncateMarker":false,"authors":[],"frontMatter":{},"unlisted":false,"nextItem":{"title":"Serenity 3.4.1 Is Out!","permalink":"/es/blog/serenity-3.4.1-release"}}')},8453(e,n,s){s.d(n,{R:()=>r,x:()=>a});var o=s(6540);const i={},t=o.createContext(i);function r(e){const n=o.useContext(t);return o.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),o.createElement(t.Provider,{value:n},e.children)}},9348(e,n,s){s.r(n),s.d(n,{assets:()=>d,contentTitle:()=>a,default:()=>h,frontMatter:()=>r,metadata:()=>o,toc:()=>l});var o=s(6183),i=s(4848),t=s(8453);const r={},a="How To Configure Chrome In Serenity BDD",d={authorsImageUrls:[]},l=[{value:"No more downloading drivers",id:"no-more-downloading-drivers",level:2},{value:"Headless mode",id:"headless-mode",level:2},{value:"W3C configuration for Chrome",id:"w3c-configuration-for-chrome",level:2},{value:"Headless mode",id:"headless-mode-1",level:3},{value:"Arguments",id:"arguments",level:3},{value:"Excluded Switches",id:"excluded-switches",level:3}];function c(e){const n={code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.p,{children:"These days Selenium is moving at a neck-breaking pace, and there are quite a few small changes coming through in the driver configuration options. And since Serenity BDD has many shortcuts to handle these options, it's worth knowing what has changed, what won't work any more, and what you need to update."}),"\n",(0,i.jsx)(n.p,{children:"So here's the rundown (with a focus on Chrome, the most widely used driver):"}),"\n",(0,i.jsx)(n.h2,{id:"no-more-downloading-drivers",children:"No more downloading drivers"}),"\n",(0,i.jsxs)(n.p,{children:["In previous versions of Serenity BDD, you could use the ",(0,i.jsx)(n.code,{children:"webdriver.driver.autodownload"})," property to make Serenity (using WebDriverManager) automatically download the right driver for your platform.\nThe latest versions of Serenity BDD integrate with Selenium 4.8.0, which has this feature built-in, so you can now safely set the ",(0,i.jsx)(n.code,{children:"webdriver.driver.autodownload"})," property to false in your ",(0,i.jsx)(n.code,{children:"serenity.conf"})," file, or remove it entirely."]}),"\n",(0,i.jsx)(n.h2,{id:"headless-mode",children:"Headless mode"}),"\n",(0,i.jsxs)(n.p,{children:["Headless mode is going away! Well, not quite - but the convenience method provided in the ChromeOptions class to set the headless mode (",(0,i.jsx)(n.code,{children:"setHeadless()"}),") is being deprecated, and will be disabled in a future version. For this reason, the Serenity BDD ",(0,i.jsx)(n.code,{children:"headless.mode"})," property is now deprecated - you'll need to configure headless execution in the W3C configuration"]}),"\n",(0,i.jsx)(n.h2,{id:"w3c-configuration-for-chrome",children:"W3C configuration for Chrome"}),"\n",(0,i.jsxs)(n.p,{children:['In the latest versions of Serenity, all the chrome options can be configured using the "goog',":chromeOptions",'" section inside the ',(0,i.jsx)(n.code,{children:"webdriver.capabilities"})," section of your ",(0,i.jsx)(n.code,{children:"serenity.conf"})," file. (Other W3C capabilites, such as browserName and timeouts, also go in the ",(0,i.jsx)(n.code,{children:"webdriver.capabilities"})," section)."]}),"\n",(0,i.jsxs)(n.p,{children:["Let's have a look at a few of the more useful \"goog",":chromeOptions",'" arguments.']}),"\n",(0,i.jsx)(n.h3,{id:"headless-mode-1",children:"Headless mode"}),"\n",(0,i.jsxs)(n.p,{children:["To activate headless mode in newer version, you will need to use the ",(0,i.jsx)(n.code,{children:" - headless"})," argument. According to the Chrome docs, you should use use ' - headless=chrome' for browsers v94-108 and ' - headless=new' for browsers v
1109+. (The Serenity ",(0,i.jsx)(n.code,{children:"headless.mode"})," property uses the latter option, and is maintained for backward compatibility reasons)."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'webdriver {\n capabilities {\n "goog:chromeOptions" {\n args = ["headless=chrome"]\n }\n }\n}\n\n'})}),"\n",(0,i.jsx)(n.h3,{id:"arguments",children:"Arguments"}),"\n",(0,i.jsxs)(n.p,{children:["You can define the command-line you want to pass into chrome using the ",(0,i.jsx)(n.code,{children:"args"}),",\nThe args option in the ChromeDriver Java implementation is a list of command-line options to use when starting the Chrome browser. These options can be used to customize the behavior of the browser and to control how the test is run. For example, you can use the ",(0,i.jsx)(n.code,{children:"headless=chrome"})," argument discussed earlier to run the browser in headless mode, or the ",(0,i.jsx)(n.code,{children:"disable-gpu"})," argument to disable GPU acceleration."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'webdriver {\n capabilities {\n "goog:chromeOptions" {\n args = ["headless=chrome","disable-gpu"]\n }\n }\n}\n\n'})}),"\n",(0,i.jsx)(n.p,{children:"Some of the options include the following:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"disable-extensions: Disables all installed extensions."}),"\n",(0,i.jsx)(n.li,{children:"disable-popup-blocking: Allows popups to appear."}),"\n",(0,i.jsx)(n.li,{children:"disable-translate: Disables the translate feature."}),"\n",(0,i.jsx)(n.li,{children:"disable-plugins: Disables all plugins."}),"\n",(0,i.jsx)(n.li,{children:"disable-background-networking: Disables background networking, such as background updates."}),"\n",(0,i.jsx)(n.li,{children:"disable-web-security: Disables the same-origin policy, which can be useful for testing purposes."}),"\n",(0,i.jsx)(n.li,{children:"disable-notifications: Disables notifications."}),"\n",(0,i.jsx)(n.li,{children:"disable-infobars: Disables infobars (information bars that appear at the top of a page)."}),"\n",(0,i.jsx)(n.li,{children:"disable-sync: Disables synchronization."}),"\n",(0,i.jsx)(n.li,{children:"disable-offer-store-unmasked-wallet-cards: Disables the offering of unmasked credit card information when shopping."}),"\n",(0,i.jsx)(n.li,{children:"start-maximized: Starts the browser maximized."}),"\n",(0,i.jsx)(n.li,{children:"incognito: Opens the browser in an incognito mode."}),"\n",(0,i.jsx)(n.li,{children:"disable-gpu: Disables the use of GPU acceleration."}),"\n",(0,i.jsx)(n.li,{children:"disable-background-timer-throttling: Disables timer throttling in background pages."}),"\n",(0,i.jsx)(n.li,{children:"disable-renderer-backgrounding: Disables backgrounding of renderer processes."}),"\n"]}),"\n",(0,i.jsx)(n.h3,{id:"excluded-switches",children:"Excluded Switches"}),"\n",(0,i.jsxs)(n.p,{children:["The ",(0,i.jsx)(n.code,{children:"excludeSwitches"})," parameter lets you to exclude certain command-line options from being passed to the Chrome browser when it is launched. These options can control various aspects of the browser behavior, such as starting it in incognito mode, disabling plugins, or turning off the UI. By excluding these switches, you can ensure that the browser behaves in a consistent and expected manner, which can be useful for testing purposes."]}),"\n",(0,i.jsxs)(n.p,{children:["You can pass a list of switch names to the ",(0,i.jsx)(n.code,{children:"excludeSwitches"}),' parameter, which goes inside the "goog',":chromeOptions",'" section in your ',(0,i.jsx)(n.code,{children:"serenity.conf"})," file."]}),"\n",(0,i.jsx)(n.p,{children:'For example, you can use " - disable-extensions" to prevent extensions from being loaded, or " - incognito" to start the browser in incognito mode.'}),"\n",(0,i.jsxs)(n.p,{children:["Note that the ",(0,i.jsx)(n.code,{children:"useAutomationExtension"})," option is deprecated and no longer used by Chrome - if you want to do the equivalent of ",(0,i.jsx)(n.code,{children:"useAutomationExtension = false"}),', add "enable-automation" to the excludedSwitches parameter, e.g.']}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:'webdriver {\n capabilities {\n "goog:chromeOptions" {\n excludeSwitches = ["enable-automation","load-extension"],\n }\n }\n}\n\n'})}),"\n",(0,i.jsxs)(n.p,{children:["Here is a more complete example of a ",(0,i.jsx)(n.code,{children:"serenity.conf"})," file using the W3C options:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-json",children:' webdriver {\n driver = chrome\n\n capabilities {\n browserName = "chrome"\n acceptInsecureCerts = true,\n\n "goog:chromeOptions" {\n args = ["start-maximized", "no-sandbox", "ignore-certificate-errors", "disable-popup-blocking",\n "disable-default-apps", "disable-extensions-file-access-check", "disable-infobars", "disable-gpu","headless=chrome"]\n\n prefs {\n default_content_settings.popups = 0,\n default_content_settings.geolocation = 2,\n credentials_enable_service = false,\n password_manager_enabled = false\n }\n excludeSwitches = ["enable-automation","load-extension"],\n }\n\n timeouts {\n implicit = 15000\n pageLoad = 300000\n }\n }\n wait.for.timeout = 20000\n }\n\n'})})]})}function h(e={}){const{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(c,{...e})}):c(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.