As I embark on creating a system with an expanding assortment of single-page applications, I am exploring strategies to efficiently organize their UI tests. My current approach involves writing a test module for each page in order to validate it thoroughly. However, I have encountered difficulties when trying to execute driver.get() consecutively.
The code below shows the structure of the project:
var webdriver = require('selenium-webdriver');
var test = require('selenium-webdriver/testing');
var expect = require('chai').expect;
var server = new require('selenium-webdriver/remote').SeleniumServer(path, {port: 4444});
var specs = [
require('./google'), require('./bing')
];
//...
var driver = new webdriver.Builder()
.usingServer(server.address())
.withCapabilities(webdriver.Capabilities.firefox())
.build();
test.describe('while learning webdriverjs', function() {
test.after(function() {
driver.quit();
});
specs.forEach(function(spec) {
spec.run(driver, webdriver, test);
});
});
The 'bing.js' file contains the following:
var expect = require('chai').expect;
function run(browser, webdriver, test) {
test.describe('a trip to bing', function() {
browser.get('http://www.bing.com');
test.it('does not fail', function() {
browser.getTitle().then(function(title) {
expect(title).to.equal('Bing');
});
});
});
}
module.exports = { run: run };
Similarly, the 'google.js' file is structured as follows:
var expect = require('chai').expect;
function run(browser, webdriver, test) {
test.describe('a trip to google', function() {
browser.get('http://www.google.com');
test.it('does not fail', function() {
browser.getTitle().then(function(title) {
expect(title).to.equal('Google');
});
});
});
}
module.exports = { run: run };
While running either 'google.js' or 'bing.js' individually works fine, executing them sequentially results in the following error message:
Error Message Here
Detailed stack trace here.
I'm currently troubleshooting why invoking driver.get() seems to be faster than the execution of the tests themselves. Additionally, I've tried using the done() method to conclude asynchronous tests, but encountered issues due to its unavailability in selenium-webdriver/testing (resulting in an "undefined is not a function" error).
Experimenting without utilizing the selenium-wrapped Mocha globals provided unexpected outcomes - on my Windows machine, all tests pass immediately before launching the browser instance, whereas on Ubuntu, the tests also pass prematurely without loading the browser at all.
Despite these challenges, I believe there are alternative methods to organize and execute these tests effectively, even though I may not see them clearly at the moment.