I am using selenium for a super simple test, using chrome; I am trying to get in the chrome tools some console.log
s for debugging, but for some reasons logs are not available at all. I also tried console.warn
and console.error
to check if it was a matter of debug levels, but still nothing.
I used an argument to open chrome tools at start: options.addArguments('--auto-open-devtools-for-tabs')
(you can see it below);
Here’s my code:
import { Builder, By, Key } from 'selenium-webdriver'
import { assert, expect, should as loadShould } from 'chai'
import { it } from 'mocha'
import chrome from 'selenium-webdriver/chrome.js'
// patch to make should chainable
const should = loadShould()
let driver = {}
describe('a second test block', async () => {
before(async () => {
let options = new chrome.Options()
options.addArguments('--window-size=1980,1024')
options.addArguments('--auto-open-devtools-for-tabs')
options.SetLoggingPreference(LogType.Browser, LogLevel.All) // <--- here I'm trying to enable logging
var capabilities = {
'browserstack.timezone': 'Rome',
// ... other capabilities
}
driver = await new Builder()
.withCapabilities(capabilities)
.forBrowser('chrome')
.setChromeOptions(options)
.build()
})
it('another test', async () => {
// trying to log, but nothing shows up
console.log('start')
// navigate to app
await driver.get('https://lambdatest.github.io/sample-todo-app/')
// add a todo
await driver.findElement(By.id('sampletodotext')).sendKeys('learn selenium', Key.RETURN)
// assert
let todoText = await driver.findElement(By.xpath('//li[last()]')).getText()
assert.strictEqual(todoText, 'learn selenium')
expect(todoText).that.is.not.a('number')
todoText.should.equal('learn selenium')
// close the browser
// await driver.quit() // <--- commented out to check chrome tools console
})
})
This code throws an error about the arguments in options.SetLoggingPreference
; if I remove this line, instead of printing in chrome tools console start
, it shows nothing.
I read about this question in which the answer is made using Python, but I need to do it in Javascript.
I also tried reading all the chrome capabilities and the chrome command line arguments (which can be added with options.addArguments()
, but nothing worked.
any clue on how to do it?