【问题标题】:Protractor: TypeError: fn is not a function量角器:TypeError:fn 不是函数
【发布时间】:2017-02-28 03:32:07
【问题描述】:

我在运行 UI 测试时遇到以下错误。我是 Javascript 的新手,所以我一直在关注示例代码,但我不确定我哪里出错了。有人可以解释为什么我会收到此错误以及适当的修复方法吗?

错误:

[13:00:19] E/launcher - fn is not a function
[13:00:19] E/launcher - TypeError: fn is not a function

主页对象:

Homepage.prototype = Object.create({}, {
    checkInBtn: {
        get: function () {
            return element(by.css('div.checkin.booking-date input'));
        }
    }, datePickerDay: {
        value: function (day) {
            return element(by.cssContainingText('.ui-datepicker-calendar a', day));
        }
    }, selectCheckInDate: {
        value: function (day) {
            return this.checkInBtn.click().then(this.datePickerDay(day).click());
        }
    },
});
module.exports = Homepage;

黄瓜量角器步骤文件

this.When(/^I enter the trip information and search$/, function (table) {
var page = new homepage();
        var checkOutDay = new Date(data["DepartureDate"]).getDate();
        page.selectCheckInDate(checkInDay);
        expect(page.checkInBtn.getText()).to.eventually.have.string(checkInDay);
        });

【问题讨论】:

  • 你打电话给var page = new homepage(),不应该是你在页面对象中声明的大写HHomepage()吗?

标签: javascript protractor cucumber


【解决方案1】:

问题在于selectedCheckInDate

Homepage.prototype = Object.create({}, {
    checkInBtn: {
        get: function() {
            return element(by.css('div.checkin.booking-date input'));
        }
    },
    datePickerDay: {
        value: function(day) {
            return element(by.cssContainingText('.ui-datepicker-calendar a', day));
        }
    },
    selectCheckInDate: {
        value: function(day) {
            var self = this;
            this.checkInBtn.click().then(function() {
                self.datePickerDay(day).click();
            });
        }
    }
});
module.exports = Homepage;

【讨论】:

  • 你能解释一下你的答案吗?
猜你喜欢
  • 2020-06-21
  • 2016-09-13
  • 2019-02-20
  • 1970-01-01
  • 2016-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多