Protrator页面对象错误 - indexPage.getTitle不是函数

时间:2016-09-23 15:47:21

标签: protractor angularjs-e2e

所以我用我的量角器e2e测试设置page objects,并立即调用这些对象。我相信这应该很简单,但我似乎在苦苦挣扎。

首先,一旦我开始测试,我就会看到Chrome浏览器启动时使用我指定的网址 - 例如,从7厘米的胜利提示:

> protractor conf.js

但是,在浏览器启动后,我在cmd控制台中看到了这个错误:

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

以下是实施细节:

* index.page.js *

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

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

  • sat.index.spec.js *

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
    });
	
});

  • conf.js *

exports.config = {
    directConnect: true,

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

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

    suites: {

    },
    
    jasmineNodeOpts: {
        defaultTimeoutInterval: 30000
    }
};

我意识到这应该是使用Protractor的简单页面对象实现,但我必须遗漏一些东西。

建议再次受到高度赞赏......

鲍勃

1 个答案:

答案 0 :(得分:1)

我不确定你是否发现了这个,你的导入错误地映射了

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