Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Webdriverio check content from every page

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
    },
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!