javascript - Reuse the same page object inside the same test suite across test cases -
so, using pageobjects nightwatch.js test application. here basic test single page.
module.exports = { before: function (browser) { browser.windowmaximize('current') }, 'login': function (browser) { //dp login stuff , navigation desired page }, 'test elements on page': function (browser) { var pageobject = browser.page.list(); pageobject .expect.section('@filterbar').to.be.visible; // list page has 2 sections var filtersection = pageobject.section.filterbar; var listsection = pageobject.section.list; //filtersection has 2 child sections within var combobox1section = filtersection.section.combobox1; var combobox2section = filtersection.section.combobox2; //test items in filter section //1. toggle button filtersection .expect.element('@togglebtn').to.be.visible; filtersection .click('@togglebtn'); filtersection .click('@togglebtn'); //2. combobox1 filtersection .expect.section('@combobox1').to.be.visible; combobox1section .click('@combobox1dropdownarrow'); //3. combobox2 filtersection.expect.section('@combobox1section').to.be.visible; combobox2section.click('@combobox1sectiondropdownarrow'); //4. go button filtersection.expect.element('@gobtn').to.be.visible; filtersection.click('@gobtn'); //test items in list section listsection .expect.element('@title').to.be.visible listsection .expect.element('@sortbtn').to.be.visible; }, 'filter items line number': function (browser) { var samepageobject = browser.page.list(); var filtersection= samepageobject.section.filterbar; var listsection = samepageobject.section.list; filtersection.expect.element('@linenumber').to.be.visible; filtersection .setvalue('@linenumber', 145) .click('@gobtn'); listsection .expect.element('@listitem').to.be.visible listsection .expect.element('@listitem').text.to.equal(145); } }
for each test case inside test, seem recreating page object again , again.
i see answer seems address global variables across test suites.
how can reuse variables throughout multiple test cases inside test suite may depend on them?
var samepageobject = browser.page.list(); var filtersection= samepageobject.section.filterbar; var listsection = samepageobject.section.list;
Comments
Post a Comment