1

I'm using codeceptjs with puppeteer to test if endpoints of a single page app are up and have the correct content on them. I need to use something like codeceptjs w/ puppeteer since each of the endpoints have to render, because much of the content on the page is retrieved by AJAX requests that would not be triggered if using the regular PHP version of codeception.

I first retrieve a list of the endpoints that I'll be testing via a GET request. Then I loop through them and run some assertions to check if various elements are present. The problem I'm facing is that if some content from one of the endpoints is missing the test fails and immediately exits, so the remaining endpoints are not checked. I need a way to be able to continue checking the remaining endpoints.

Scenario('Test Endpoints From Sitemap', async (I) => {

    // get the sitemap
    var sitemap = await I.sendGetRequest("url/to/sitemap");
    sitemap = JSON.parse(sitemap.raw_body);

    for(i = 0; i < sitemap.length; i++){
        await I.amOnPage(sitemap[i].url); // load the endpoint
        I.seeElement(sitemap[i].element) // check for an element
    }

});

Is it possible to not exit a test case immediately with codeceptjs if a failed assertion is reached? If not, could someone please suggest another way to accomplish what I'm trying to do? Thanks

user10194756
  • 63
  • 1
  • 1
  • 8

2 Answers2

0

instead of I.seeElement(), use:

if (I.grabNumberOfVisibleElements(sitemap[i].element) == 0) {
  // element not found, use an action or logging
}
skilleo
  • 2,451
  • 1
  • 27
  • 34
-1

How about moving your sitemap retrival in the suites before hook, store the result and then launching single Scenarios out of each url? That way it will not cancel the suite run before all urls are checked

Paul Vincent Beigang
  • 2,972
  • 2
  • 16
  • 31
  • While this answer provides some insight into a "better" way to accomplish the end goal. It does not answer the question. – CodeMonkeyG Sep 27 '18 at 14:41