I am trying to do an automatic test to check if a search bar works properly. My problem is that after I search I get not one, but a lot of different pages and I need to check if every item for every page matches the criteria. The question is: how to iterate over each page to check them all?
See code below:
search.page.js
const Page = require('./page');
class SearchResultsPage extends Page {
get propertyLocation() {
return $$('[aria-label="Location"]');
}
get pages() {
return $$('[title*="Page"]');
}
get btnNextPage(){
return $('[title="Next"]');
}
open() {
return super.open('/for-sale/property/dubai/dubai-marina/');
}
open_page(page_index) {
return super.open('/for-sale/property/dubai/dubai-marina/page-' + str(page_index));
}
}
module.exports = new SearchResultsPage();
test.e2e.js
const pages = await SearchResultsPage.pages
console.log('here before');
console.log(pages)
pages.forEach(page => {
console.log("i am here");
page.click();
});
wdio.conf.js
exports.config = {
specs: [
'./test/specs/**/*.js'
],
// Patterns to exclude.
exclude: [
// 'path/to/excluded/files'
],
maxInstances: 10,
capabilities: [{
maxInstances: 5,
browserName: 'chrome',
acceptInsecureCerts: true
}],
logLevel: 'info',
bail: 0,
baseUrl: 'https://www.bayut.com/',
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: ['chromedriver'],
framework: 'mocha',
reporters: ['spec'],
mochaOpts: {
ui: 'bdd',
timeout: 60000
},
}
If I understand well, you want to loop between pages. You can do that with a while loop and store the information you want into an array. You can have a method hasNextButton() that returns a boolean if next btn is present.
For example:
while (searchPage.hasNextButton()) {
// do anything you want
list.push(item.getText());
searchPage.clickNextBtn();
}
or if you want a certain number of pages:
let pageNumber = 1;
while (pageNumber <= totalPages) {
// do anything you want
list.push(item.getText());
searchPage.clickNextBtn();
pageNumber++;
}
After you have the information stored, you can process it however you want.