Can't use page objects pattern with protractor
Hello,
I've asked about this in stackoverflow (http://goo.gl/nD4EU9) but nobody answered me.
Apparently there is a few ways to do it, and i don't know if there is a specific way to do it in non angular pages.
Do i have to instance page.js (my page object file)? Do i have to use module.export (and how is to correct way to use it)?
In this tutorial http://goo.gl/WjRyrj i havent found any more info.
Thanks!
Hi Andrepm06, I've modified your code which taken from Stack Overflow. And hope it will help you
/* *1. create a constructor function with browser as a parameter
- and save it as page.js file */ ---------------------------------------------------------//page.js file------
var PageObjects = function(browser) { var preenchePsafe = browser.driver.findElement(by.id('global-search'));
var opcaoPsafe = browser.driver.findElement(by.css('#search > ul > li:nth-child(1) > a'));
this.abrirUrl = function() {
browser.get('http://home.pp.psafe.com/');
};
this.pesquisarPsafe = function (pesquisa){
preenchePsafe.sendKeys(pesquisa);
opcaoPsafe.click();
};
}; /create method with browser as a parameter and it should return the object of constructor function or page.js and export it/
module.exports getPageObject=function(browser) { return new PageObjects(browser); }; ------------------------------------end------------------------------ /* 2.create sepc.js file and import page.js with help of require() method in nodejs/ -------------------sepc.js file--------------------------------------- var pageCode = require('./page.js');
describe('PSafe Home', function () { /call the method getPageObject by passing the browser as parameter/ var pageObject=pageCode.getPageObject(browser);
beforeEach(function (){
isAngularSite(false);
handlePromise = dvr.getAllWindowHandles();
});
it ('Pesquisar PSafe', function () {
browser.get('http://home.psafe.com/');
pageObject.pesquisarPsafe('PSafe');
})});
-----------------------------------------------end--------------------
Sorry, i couldnt follow you.
You mean like this?
this.getPageObject=function(browser) { return new PageObjects(browser); }
module.exports = getPageObject;
Please read the contributing guidelines; these types of questions are ill-suited for GitHub. Thanks!
I know you posted on SO, but you only posted earlier today! Please give people a little time to respond and continue the discussion there.