问题
I've recently tried to use the Page Object Model with Protractor following this post http://engineering.wingify.com/posts/angularapp-e2e-testing-with-protractor/
However, when I run my tests, my it
blocks do not get executed.
Below is my login page object
/*File Name : loginPage.js*/
var loginPage = function () {
'use strict';
this.email = element(by.id('Email'));
this.next = element(by.id('next'));
this.pwd = element(by.id('Passwd'));
this.signin = element(by.id('signIn'));
this.submitButton = element(by.css('.login-form button[type="submit"]'));
//this.classitem = element(by.css('hap-class-item'));
//this.googlesigninbtn = element(by.css('[ng-click="login_google()"]'));
//******************** functions *******************
this.enterEmail = function (email) {
browser.ignoreSynchronization = true;
//browser.sleep(2000);
this.email.clear();
this.email.sendKeys(email);
this.next.click();
browser.sleep(2000);
};
this.enterPassword = function (pwd) {
browser.ignoreSynchronization = true;
this.pwd.clear();
browser.sleep(2000);
this.pwd.sendKeys(pwd);
this.signin.click();
browser.sleep(2000);
};
};
module.exports = {
log: new loginPage()
};
Below is my logout page object
/*File Name : logoutPage.js*/
var logoutPage = function () {
'use strict';
this.logoutcaret = element(by.css('[ng-if="api.userNav.items"]'));
this.logoutbtn = element(by.css('[ng-click="openModal()"]'));
this.googlelogout = element(by.css('[ng-click="logout()"]'));
var EC1 = protractor.ExpectedConditions;
//******************** functions *******************
this.logoutfn = function () {
browser.wait(EC1.visibilityOf(this.logoutcaret),15000);
this.logoutcaret.click();
this.logoutbtn.click();
this.googlelogout.click();
};
};
module.exports = {
log: new logoutPage()
};
Below is my Base Page that has login and logout functions created to be used in each test
/*File Name : LoginOut.js*/
//var switchwin = require('../commons/selectwindow.js');
var loginPage = require('../objects/loginpage.js'),
eml = 'abc',
password = 'pwd';
exports.login = function () {
//browser.driver.manage().deleteAllCookies();
browser.driver.get('https://accounts.google.com/ServiceLogin');
loginPage.log.enterEmail(eml);
loginPage.log.enterPassword(password);
browser.driver.get('URL');
};
var logoutPage = require('../objects/logoutpage.js');
exports.logout = function () {
logoutPage.log.logoutfn();
};
Lastly, below is my test, which always passes but it merely logs in and logs out however does not perform any actions in the 'it' block.
/*File Name : tests*/
'use strict';
describe('I want to test Smartshare', function () {
var loginMod = require('../commons/loginout.js');
//login before each test
beforeEach(function () {
loginMod.login();
});
var loginMod = require('../commons/loginout.js');
//logout after each test
afterEach(function () {
loginMod.logout();
});
var smartshareMod = require('../objects/smartsharepage.js');
//copy doc test
it('should test sharing a document', function () {
exports.copydoc = function () {
smartshareMod.log.copyDoc().then(function(){
console.log('document copied');
});
};
});
});
node.js version - v6.4.0
protractor version - 4.0.11
Running on MacOS Sierra
webdriver-manager updated to latest
回答1:
This is because you don't call any functions inside the it()
block, fix it:
it('should test sharing a document', function () {
smartshareMod.log.copyDoc().then(function() {
console.log('document copied');
});
});
Also note that you don't have to "require" your page objects every time you use them - require them at the top of your test spec once and reuse:
'use strict';
var loginMod = require('../commons/loginout.js');
var smartshareMod = require('../objects/smartsharepage.js');
describe('I want to test Smartshare', function () {
beforeEach(function () {
loginMod.login();
});
afterEach(function () {
loginMod.logout();
});
it('should test sharing a document', function () {
smartshareMod.log.copyDoc().then(function() {
console.log('document copied');
});
});
});
来源:https://stackoverflow.com/questions/41388351/protractor-passes-my-tests-without-executing-the-it-blocks