I am new to Mocha and Webdriver.io.
Here is my code:
// required libraries
var webdriverio = require('webdriverio'),
should = require('should');
// a test script block or suite
describe('Login to ND', function() {
// set timeout to 10 seconds
this.timeout(10000);
var driver = {};
// hook to run before tests
before( function () {
// load the driver for browser
driver = webdriverio.remote({ desiredCapabilities: {browserName: 'firefox'} });
return driver.init();
});
// a test spec - "specification"
it('should be load correct page and title', function () {
// load page, then call function()
return driver
.url('https://ND/ilogin.php3')
// get title, then pass title to function()
.getTitle().then( function (title) {
// verify title
(title).should.be.equal("NetDespatch Login");
// uncomment for console debug
console.log('Current Page Title: ' + title);
return driver.setValue("#userid", "user");
return driver.setValue("#password", "pass");
return driver.click("input[alt='Log in']");
});
});
// a "hook" to run after all tests in this block
after(function() {
return driver.end();
});
});
I can execute this with Mocha, and the test passes, even though it doesn't seem to do all of the "steps" I have defined..
It opens the page, logs the website title, and enters 'user' in the userid, BUT.. It doesn't populate the password field, or select the login link, and there doesn't appear to be any errors displayed..
Login to ND
Current Page Title: ND Login
✓ should be load correct page and title (2665ms)
1 passing (13s)
But, as it hasn't executed all the steps, I don't expect it to pass, though, I also don't understand why it won't do the last few steps.
As mentioned in the original post comments, you should only have one return
in your test:
it('should be load correct page and title', function () {
// load page, then call function()
return driver
.url('https://ND/ilogin.php3')
// get title, then pass title to function()
.getTitle().then( function (title) {
// verify title
(title).should.be.equal("NetDespatch Login");
// uncomment for console debug
console.log('Current Page Title: ' + title);
})
.setValue("#userid", "user")
.setValue("#password", "pass")
.click("input[alt='Log in']");
});