【问题标题】:Protractor page objects error量角器页面对象错误
【发布时间】:2016-11-02 06:58:02
【问题描述】:

我正在为页面对象模式构建我的 angularjs 量角器 e2e 测试。我在将脚本转换为页面对象时遇到了麻烦。

这是我的conf.js

// conf.js
exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['employee.js']
}

这是我的employee.js

// spec.js
var EmpPageObject = require('./EmpPageObject.js');
describe('Protractor Demo App', function() {
  it('should have a title', function() {

    var empPageObject = new EmpPageObject();
    empPageObject.get();

    empPageObject.setName('mee');
    empPageObject.setPassword('123');

  });
});

这是我的EmpPageObject.js

var EmpPageObject = function() {

    var nameInput = element(by.model('login.user_name'));
    var passwordInput = element(by.model('login.password'));
    var addButton = element(by.css('.btn'));

    this.get = function() {
    browser.get('http://');
  };

  this.setName = function(name) {
    nameInput.sendKeys(name);
  };

  this.setPassword = function(password) {
    passwordInput.sendKeys(password);
  };

  addButton.click();

};

但是,我的脚本未能给出以下错误。

Failures:
1) Protractor Demo App should have a title
  Message:
    Failed:  EmpPageObject is not defined

这可能是一个愚蠢的问题。但是,我找不到错误,因为这是我的第一次测试。 :)

【问题讨论】:

    标签: javascript angularjs jasmine pageobjects


    【解决方案1】:

    看起来你从这里复制粘贴代码 https://github.com/angular/protractor/blob/f9c8a37f7dbec1dccec2dde0bd6884ad7ae3f5c7/docs/tutorial.md

    describe('Protractor Demo App', function() {
      it('should have a title', function() {
        browser.get('http://juliemr.github.io/protractor-demo/');
    
        expect(browser.getTitle()).toEqual('Super Calculator');
      });
    });
    

    这里是protractor 尝试获取资源并检查 - 它是否有标题。

    此函数返回真或假进行测试。在你的情况下,函数返回undefined,它等于false,测试失败并且你得到错误信息。

    【讨论】:

    • 尝试从 protractortest.org/#/page-objects 转换为页面对象。但是,我怎样才能做到这一点呢?你能解释更多吗?
    • 对不起,我错了,还有其他问题。您有消息Failed: EmpPageObject is not defined,表示您没有定义(导入)EmpPageObject,并且您的测试失败,因为调用new EmpPageObject()时发生了异常。
    • 但是,我在EmpPageObject.js 中明确定义了EmpPageObject。我不明白你的重点朋友。 :(
    • 好的。明白了。将 var EmpPageObject = require('./EmpPageObject.js'); 添加到 employee.js 。但是,发生了另一个错误,`EmpPageObject 不是构造函数`。 :(
    • 得到了答案。谢谢:)
    猜你喜欢
    • 2017-06-13
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多