I am actually finishing the unit tests of my Angular app. I am currently working on E2E tests using Protractor and Jasmine. Unfortunately, I have the following problem:
I did loads of research online such as http://ift.tt/1v21SFY and I clearly never see the use of the "done" callback to launch tests.
This first test goes on the createUser page and makes sure that the user tab attribute is set to active. It passes ONLY if I use the done method, which I should not use.
'use strict';
var UserCreate = require('./page-objects/userCreate.pageObjects');
describe('on init', function () {
beforeEach(function() {
var rootUrl = browser.baseUrl + '/#/users/create';
browser.driver.get(rootUrl);
});
it('should set the user tab active', function(done) { // DONE callback
UserCreate.tabs.getAttribute('class').then(function(value) {
expect(value).toEqual('active');
done(); // calling callback
});
});
});
If I repeat the same test without using done(), the test passes even if this time, I want it to fail.
'use strict';
var UserCreate = require('./page-objects/userCreate.pageObjects');
describe('on init', function () {
beforeEach(function() {
var rootUrl = browser.baseUrl + '/#/users/create';
browser.driver.get(rootUrl);
});
it('should set the user tab active', function() {
UserCreate.tabs.getAttribute('class').then(function(value) {
expect(value).toEqual('activeWRONG');
});
});
});
It only fails if I use the done callback.
Here is my config file:
/* conf.js */
' use strict';
exports.config = {
rootElement: '#myApp',
directConnect: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 1
},
framework: 'jasmine',
// specs: ['./*.spec.js'],
baseUrl: 'http://localhost:9001',
defaultTimeoutInterval: 0000,
jasmineNodeOpts: {
showColors: true,
},
suites: {
wip: './userCreate.spec.js',
all: './*spec.js'
},
onPrepare: function() {
browser.driver.get('http://localhost:9001/#/');
element(by.id('ld-link-login')).click();
browser.sleep(500);
element(by.model('username')).sendKeys('test');
element(by.model('password')).sendKeys('test');
element(by.id('nv-login-submit')).click();
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return /dashboard/.test(url);
});
}, 10000);
}
};
I am having asynchronous problems in deeper tests with the use of done everywhere, so I want to fix this before continuing my tests.
Thank you for your help.
Edit:
Protractor version: ./node_modules/.bin/protractor --version gives Version 3.2.2
userCreate.pageObjects :
'use strict';
module.exports = {
tabs: element(by.id('cc-tab-user'))
};
Aucun commentaire:
Enregistrer un commentaire