Good morning,
Currently, I am in the process of learning how to use Selenium with JavaScript (specifically using Mocha). I have created a very basic test that is causing some issues during runtime. Whenever I run the test, a new instance of Chrome opens and the browser displays. Initially, the browser shows "data:," in the URL bar before navigating to google.com. However, I encounter an error as follows:
$ mocha test
Array
#indexOf()
✓ should return -1 when the value is not present!
Google Search
1) should work
1 passing (2s)
1 failing
1) Google Search should work:
Error: timeout of 2000ms exceeded
at null.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:157:19)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
Below is the code for the test:
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
webdriver = require('selenium-webdriver'),
chrome = require('selenium-webdriver/chrome');
test.describe('Google Search', function() {
test.it('should work', function() {
var chromeOptions = new chrome.Options();
chromeOptions.addArguments(['test-type']);
var driver = new webdriver.Builder().withCapabilities(chromeOptions.toCapabilities()).build();
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
driver.quit();
});
});