Reputation: 93
I have a test written in pageobject model with Protractor v2.5.1, Cucumberjs v0.7.0:
---------------loginpage.js---------------------
'use strict';
( function () {
//var ptor;
var navigate = function () {
console.log("789");
isAngularSite(false);
browser.get("");
};
var login = function ( username, password ) {
browser.driver.findElement( by.id('log')).sendKeys(username);
browser.driver.findElement( by.id( 'pwd' ) ).sendKeys(password);
browser.driver.findElement( by.id( 'login' ) ).click();
browser.sleep(3000);
};
var LoginPage = function () {
//var username = browser.driver.findElement( by.id( 'log' ) );
//var password = browser.driver.findElement( by.id( 'pwd' ) );
//var loginButton = browser.driver.findElement( by.id( 'login' ) );
};
LoginPage.prototype.navigate = navigate();
LoginPage.prototype.login = login();
module.exports = LoginPage;
} )();
----------------spec.js-------------------
'use strict';
var LoginPage = require( './loginpage.js' );
//var HomePage = require( '../homepage/homepage.js' );
//var chai = require( 'chai' );
//
//var chaiAsPromised = require( 'chai-as-promised' );
//
//chai.use( chaiAsPromised );
//
//var expect = chai.expect;
module.exports = function () {
var loginPage;
var homePage;
this.Before( function ( callback ) {
loginPage = new LoginPage();
//homePage = new HomePage();
//isAngularSite(false);
loginPage.navigate();
callback();
} );
this.After( function ( callback ) {
//logout
callback();
} );
this.Given(/^I login using valid creadentials&/, function ( callback ) {
loginPage.login( 'binhle', '12345678' ); //valid creadential
callback();
} );
};
When i run my test with IDE Webstorm, the console output:
"C:\Program Files\JetBrains\WebStorm 10.0.4\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" c:\Users\Dave.Le\AppData\Roaming\npm\node_modules\protractor\lib\cli.js config.js
Using the selenium server at http://127.0.0.1:4444/wd/hub
[launcher] Running 1 instances of WebDriver
789
[launcher] 0 instance(s) of WebDriver still running
[launcher] firefox #1 passed
But when i observe on browser, it just input text "undefined" for username
and password
fields.
My questions is: 1. Why doesn't it input my text "binhle" instead "undefined"? 2. How to see text result (FAIL in this case) for the text?
Upvotes: 1
Views: 486
Reputation: 5515
In your page object, you are calling the login
and navigate
functions as you assign them:
LoginPage.prototype.navigate = navigate();
LoginPage.prototype.login = login();
What you actually want to do is this:
LoginPage.prototype.navigate = navigate;
LoginPage.prototype.login = login;
Or more simply:
var LoginPage = function LoginPage () { ... };
LoginPage.prototype.login = function (username, password) { ... };
Upvotes: 1