我有一个:
TypeError: page.fillForm is not a function
每次我尝试运行我的测试。在我开始使用 PageObject 之前一切正常。
这是我的规范文件:contactBook_spec.js
describe("Contact book", function(){
beforeEach(function(){
browser.ignoreSynchronization = true;
browser.get("https://ddaawwiidd.github.io/contactbook/");
});
xit("Should be able to save new contact details", function(){
expect(browser.getCurrentUrl()).toContain("contactbook");
element(by.css("#nameInput")).sendKeys("Vladimir");
element(by.css("#surnameInput")).sendKeys("Putin");
element(by.css("#emailInput")).sendKeys("vlad@hack.ru");
element(by.css("#phoneInput")).sendKeys("+01 123456");
element(by.css("#saveBTN")).click();
});
xit("Should find saved contact", function(){
element(by.css("#nameInput")).sendKeys("Vladimir");
element(by.css("#surnameInput")).sendKeys("Putin");
element(by.css("#emailInput")).sendKeys("vlad@hack.ru");
element(by.css("#phoneInput")).sendKeys("+01 123456");
element(by.css("#searchBTN")).click();
expect(element(by.css('tr td')).getText()).toContain("Vladimir");
expect(element(by.css('tr td')).getText()).toContain("Vladimir");
});
var page = require('./page/home_page.js');
it("Should be able to test by page objects", function(){
page.fillForm('Adam', 'Eva', 'c@c.o', '1230');
page.clickSave();
});
});
这是页面对象文件:home_page.js
var home_page = function(){
this.fillForm = function(name, surname, email, phone){
element(by.css("#nameInput")).sendKeys(name);
element(by.css("#surnameInput")).sendKeys(surname);
element(by.css("#emailInput")).sendKeys(email);
element(by.css("#phoneInput")).sendKeys(phone);
};
this.clickSave = function(){
element(by.css("#saveBTN")).click();
};
};
module.exports = home_page;
我不知道哪里出了问题。我正在 Protractor v. 4.0.14 和 Node v. 6.9.2 上运行测试
最佳答案
调整您的页面对象以导出页面对象实例。替换:
module.exports = home_page;
与:
module.exports = new home_page();
旁注:HomePage
是一个更好的名字风格,考虑改进它。
关于javascript - 尝试将页面对象与 Protractor 一起使用时出现“失败的 : object. 方法不是函数”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41398314/