我定义了`loginpage.js':
'use strict';
( function () {
var ptor;
var navigate = function () {
//browser.ignoreSynchronization = true ;
ptor = protractor.getInstance();
ptor.ignoreSynchronization = true;
ptor.waitForAngular();
ptor.get('http://store.demoqa.com');
//browser.get('http://store.demoqa.com/');
};
var login = function ( username, password ) {
this.username.sendKeys( username );
this.password.sendKeys( password );
this.loginButton.click();
};
var LoginPage = function () {
this.username = dv.findElement( by.id( 'log' ) );
this.password = dv.findElement( by.id( 'pwd' ) );
this.loginButton = dv.findElement( by.id( 'login' ) );
};
LoginPage.prototype.navigate = navigate;
LoginPage.prototype.login = login;
module.exports = LoginPage;
} )();
然后我在spec.js
this.Before( function ( callback ) {
var loginPage = new LoginPage();
isAngularSite(false);
loginPage.navigate();
callback();
} );
但是当我运行测试时,会显示以下错误:
c:\Users\binhlex\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108
var template = new Error(this.message);
^
NoSuchElementError: Unable to locate element: {"method":"id","selector":"log"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'HSSSC1PCL02018', ip: '192.168.197.24', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'
Driver info: driver.version: unknown
at new bot.Error (c:\Users\binhlex\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108:18)
at Object.bot.response.checkResponse (c:\Users\binhlex\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:109:9)
at c:\Users\binhlex\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:379:20
at [object Object].promise.ControlFlow.runInFrame_ (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
at [object Object].goog.defineClass.notify (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
at [object Object].promise.Promise.notify_ (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
at Array.forEach (native)
at [object Object].promise.Promise.notifyAll_ (c:/Users/binhlex/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15)
at goog.async.run.processWorkQueue (c:\Users\binhlex\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
at process._tickDomainCallback (node.js:409:9)
[launcher] Process exited with error code 1
此时,浏览器已打开,但未在地址栏中打开任何网址。
我在定义pageobject并从登录页面调用navigate
函数时做错了什么?
我在这里的完整代码:Protractor-cucumberjs: browser.get() does not work