bob.mazzo
bob.mazzo

Reputation: 5637

Protrator page objects error - indexPage.getTitle is not a function

So I'm setting up page objects with my Protractor e2e tests, and straight away having an issue calling into those objects. I believe this should be simple, however I seem to be struggling.

Firstly, as soon as I start my test I am seeing the Chrome browser launch with the URL I have specified - for example, from a win 7 cmd prompt:

> protractor conf.js

However, after the browser launches I see this error in my cmd console:

Failures:
1) Launching the SAT Application Should display the correct browser title
  Message:
     Failed: indexPage.getTitle is not a function
  Stack:
     TypeError: indexPage.getTitle is not a function

Here are the implementation details:

* index.page.js *

module.exports = function () {
    this.get = function () {

        browser.get("http://localhost:64174/SAT.html");
        
    };
            
    this.getTitle = function () {
        return browser.getTitle();
    };
    
};

var IndexPage = require('./pageObjects/dataCard.page.js');
var DataCardPage = require('./pageObjects/index.page.js');

describe('Launching SAT Application', function () {
    var indexPage = new IndexPage();
    var dataCardpage = new DataCardPage();
    
    beforeEach(function () {
        //indexPage.get;  // not working...
        
        browser.get("http://localhost:64174/sat.html");   // launch successful
    });

    
    it('Should display the correct browser title', function () {        
       expect(indexPage.getTitle()).toBe('My awesome applicatoin');	// not found error in cmd console
    });
	
});

exports.config = {
    directConnect: true,

    capabilities: {
        'browserName': 'chrome'
    },
    framework: 'jasmine',

    specs: ['sat.index.spec.js'],

    suites: {

    },
    
    jasmineNodeOpts: {
        defaultTimeoutInterval: 30000
    }
};

I realize this should be a simple page object implementation using Protractor, but I must be missing something.

Advice greatly appreciated again...

Bob

Upvotes: 0

Views: 313

Answers (1)

AdityaReddy
AdityaReddy

Reputation: 3645

I am not sure if you have spotted this, you have got the imports wrongly mapped

var IndexPage = require('./pageObjects/dataCard.page.js');
var DataCardPage = require('./pageObjects/index.page.js');

Upvotes: 1

Related Questions