jeudi 17 septembre 2020

Puppeteer times out with 30000ms and fails test suite even when I have set a methods timeout to 200ms

I have a method which looks if an element is visible in the DOM, and if not it'll send a response saying it's not available and then move on to the next method but is not supposed to fail by timing out the whole testing suite.

async checkIfGroupClickableWrapperExistsAndClickID
  ( askId ) {
    const selector = `[test-id="${askId}"]`;
    let visible = true;
    
    /* This is the part that matters for this question */
    await this.page
      .waitForSelector(selector, { visible: true,  timeout: 200 })
      .catch(() => {
        visible = false;
    });

    console.log('Visible value is ', visible);

    if (visible) {
            console.log( 'Selector Exists!' );
            return Promise.resolve( 'exists' );
    } else {
      console.log( 'Selector Does Not Exists!' );
      return Promise.resolve( 'does not exist' );
    }
    // return Promise.reject( Error( 'Selector not found' ));
  }

The await this.page.waitForSelector is supposed to wait for this element to appear for only 200ms and then catch the error.

But, when I run the test, it seems like it waits for the whole 30000ms and then times out, failing the entire test case.

Error message 👇

● TEMP JENKINS TEST 00001 › TEST CASE TJT0003 - Clear all tasks

    TimeoutError: waiting for selector "[test-id="QUE_DRAFTS_GRP"]" failed: timeout 30000ms exceeded

      204 |     const selector = `[test-id="${askId}"]`;
      205 | 
    > 206 |     await this.page.waitForSelector(selector);
          |                     ^
      207 | 
      208 |     await this.page.click(selector);
      209 |   }

Any help would be highly appreciated.

Aucun commentaire:

Enregistrer un commentaire