@@ -81,9 +81,16 @@ describe('Selenium chromedriver', function () {
8181 ) ;
8282 } ) ;
8383
84- beforeEach ( async function ( ) {
85- logger . debug ( `Launching Chrome at ${ chromeBuild . executablePath } ` ) ;
84+ afterEach ( async function ( ) {
85+ if ( driver ) {
86+ await driver . quit ( ) ;
87+ }
88+ } ) ;
8689
90+ /**
91+ * This test is intended to verify the setup is correct.
92+ */
93+ it ( 'should be able to navigate to google.com' , async function ( ) {
8794 const options = new chrome . Options ( ) ;
8895 options . addArguments ( '--headless' ) ;
8996 options . addArguments ( '--no-sandbox' ) ;
@@ -95,7 +102,7 @@ describe('Selenium chromedriver', function () {
95102 }
96103 const chromedriverLogFile = path . join (
97104 chromedriverLogDir ,
98- `chromedriver-${ new Date ( ) . toISOString ( ) } .log` ,
105+ `chromedriver-${ new Date ( ) . toISOString ( ) } .log`
99106 ) ;
100107
101108 const service = new chrome . ServiceBuilder ( chromedriverBuild . executablePath )
@@ -107,22 +114,65 @@ describe('Selenium chromedriver', function () {
107114 . setChromeOptions ( options )
108115 . setChromeService ( service )
109116 . build ( ) ;
110- } ) ;
111-
112- afterEach ( async function ( ) {
113- await driver . quit ( ) ;
114- } ) ;
115117
116- /**
117- * This test is intended to verify the setup is correct.
118- */
119- it ( 'should be able to navigate to google.com' , async function ( ) {
120118 await driver . get ( 'https://www.google.com' ) ;
121119 const title = await driver . getTitle ( ) ;
122120 expect ( title ) . toBe ( 'Google' ) ;
123121 } ) ;
124122
125- it ( 'ISSUE REPRODUCTION' , async function ( ) {
126- // Add test reproducing the issue here.
123+ it ( 'navigator.webdriver should be true even with --remote-debugging-port and enable-automation excluded' , async function ( ) {
124+ // This test reproduces https://crbug.com/chromedriver/4107.
125+ // The bug causes `navigator.webdriver` to be false when the
126+ // `enable-automation` switch is excluded and a remote debugging port is
127+ // set.
128+ //
129+ // The test configures the ChromeDriver to launch Chrome with the exact
130+ // capabilities described in the bug report.
131+ //
132+ // 1. Exclude the 'enable-automation' switch.
133+ // 2. Set a non-zero remote debugging port.
134+ //
135+ // It then navigates to a blank page and executes a script to get the value
136+ // of `navigator.webdriver`.
137+ //
138+ // The WebDriver specification states that `navigator.webdriver` should be
139+ // `true` when the browser is under control of a WebDriver. In this case,
140+ // even though 'enable-automation' is excluded, ChromeDriver should ensure
141+ // that `navigator.webdriver` remains `true`. The bug causes this to be
142+ // `false`.
143+ //
144+ // Therefore, this test asserts that the value is `true`, and it is
145+ // expected to fail if the bug is present.
146+ const options = new chrome . Options ( ) ;
147+ options . addArguments ( '--headless' ) ;
148+ options . addArguments ( '--no-sandbox' ) ;
149+ options . addArguments ( '--remote-debugging-port=9222' ) ;
150+ options . excludeSwitches ( 'enable-automation' ) ;
151+ options . setBinaryPath ( chromeBuild . executablePath ) ;
152+
153+ const chromedriverLogDir = path . join ( __dirname , 'logs' ) ;
154+ if ( ! fs . existsSync ( chromedriverLogDir ) ) {
155+ fs . mkdirSync ( chromedriverLogDir ) ;
156+ }
157+ const chromedriverLogFile = path . join (
158+ chromedriverLogDir ,
159+ `chromedriver-${ new Date ( ) . toISOString ( ) } .log`
160+ ) ;
161+
162+ const service = new chrome . ServiceBuilder ( chromedriverBuild . executablePath )
163+ . loggingTo ( chromedriverLogFile )
164+ . enableVerboseLogging ( ) ;
165+
166+ driver = await new Builder ( )
167+ . forBrowser ( 'chrome' )
168+ . setChromeOptions ( options )
169+ . setChromeService ( service )
170+ . build ( ) ;
171+
172+ await driver . get ( 'about:blank' ) ;
173+ const navigatorWebdriver = await driver . executeScript (
174+ 'return navigator.webdriver'
175+ ) ;
176+ expect ( navigatorWebdriver ) . toBe ( true ) ;
127177 } ) ;
128178} ) ;
0 commit comments