'Failed: object.method is not a function' 尝试将页面对象与量角器一起使用时出错
'Failed: object.method is not a function' error when trying to use Page Object with Protractor
我有一个:
TypeError: page.fillForm is not a function
每次我尝试 运行 我的测试。在我开始使用 PageObject 之前一切正常。
这是我的 spec 文件: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
是一个更好的名字风格,考虑改进它。
我有一个:
TypeError: page.fillForm is not a function
每次我尝试 运行 我的测试。在我开始使用 PageObject 之前一切正常。
这是我的 spec 文件: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
是一个更好的名字风格,考虑改进它。