Oscar Oscar - 2 months ago 15
Javascript Question

WebdriverJS : driver.manage().logs().get('browser') returns empty array

I have the following mocha test case, I'm trying to print the webdriver logs in the end, but its returning an empty array. The result is the same even when I pass 'browser' as argument to the logs().get(). Can someone please tell me why the logs are empty?

it('should open a url', function(done){
var By = nemo.wd.By;
driver.manage().logs();
driver.get("http://www.google.com");
driver.findElement(By.name('q')).sendKeys("webdriver");
driver.findElement(By.name('btnG')).click()
driver.manage().logs().get('driver').then(function(logs){
console.log(logs);
done();
});
});

Answer

It was because I didn't enable the logging option in the list of capabilities while creating the driver instance. Resolved now with these changes.

var pref = new webdriver.logging.Preferences();
pref.setLevel('browser', webdriver.logging.Level.ALL); 
pref.setLevel('driver', webdriver.logging.Level.ALL); 

var driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.firefox())
    .setLoggingPrefs(pref).build();
Comments