I am currently in the process of creating a login function specifically for mocha testing and selenium-webdriver to facilitate unit testing. I have numerous tasks that involve scenarios where "user logs in and...".
My attempt at the code below seems to be causing issues as when I run it, the console just displays:
Already registered user logs in and sees homepage
1) should work (it's red text)
Login an existing user
After this display, nothing further happens, forcing me to exit the process using control-C. The code was functioning perfectly until I attempted to implement this modular login system, leading me to believe that is where the problem lies. Could there be something vital that I'm overlooking? Any feedback on my approach towards creating the login
function would also be greatly appreciated considering my limited experience with webdriver.
Displayed below is all of the code, contained within a single JavaScript file.
var test = require('selenium-webdriver/testing'),
chai = require('chai');
chai.use(require('chai-string'));
chai.use(require('chai-as-promised'));
var expect = chai.expect,
webdriver = require('selenium-webdriver'),
By = webdriver.By;
// My aim is to create a reusable modular login function
function login(driver) {
test.describe('Login an existing user', function() {
test.it('should work', function() {
this.timeout(0);
var email = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f02160a020e06032f1b0a1c1b410c0002">[email protected]</a>';
var password = 'password';
driver.get('http://localhost:9000');
driver.getTitle().then(function(title) {
expect(title).to.equal('my title');
})
.then(function() {
// do login stuff and click login button
});
.then(function() {
return driver;
});
});
});
}
// Example showcasing the usage of the login function
test.describe('Already registered user logs in and sees homepage', function() {
test.it('should work', function() {
this.timeout(0);
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver = login(driver)
.then(function() {
driver.findElement(By.xpath("relevant xpath")).click();
})
})
})