vendredi 30 décembre 2016

'Failed: object.method is not a function' error when trying to use Page Object with Protractor

I've got a:

TypeError: page.fillForm is not a function

every time I try to run my tests. Before I started to use PageObject everything was ok.

Here is my spec file: contactBook_spec.js

describe("Contact book", function(){

    beforeEach(function(){
        browser.ignoreSynchronization = true;
        browser.get("http://ift.tt/2ilh821");
    });

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


});

And here is page object file: 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;

I can't figure out what's wrong. I'm running test on Protractor v. 4.0.14 and Node v. 6.9.2

Aucun commentaire:

Enregistrer un commentaire