1

Steps to reproduce

  • git clone https://github.com/anikethsaha/docsify
  • git checkoute2e-test-puppeteer`
  • npm i
  • npm run test:e2e
  • check the tests for sideBar.spec.js

It will fail are running 31 tests out of 122 tests

Tell us about your environment:

What steps will reproduce the problem? npm run test:e2e

Please include code that reproduces the issue.

  1. https://github.com/anikethsaha/docsify/blob/e2e-test-puppeteer/e2e/tests/sideBar.spec.js 2. 3.

What is the expected result? It should run all the test cases 122

What happens instead? But instead, its running only 31 tests and the browser is closing after that and then remaining 91 tests are not running

Context

I am using live-server to run a server that will serve my files and it is being done in a custom jest environment. I have a sideBar.spec.js file which tests all the sidebar links by clicking them and then taking a snapshot using jest-image-snapshot. In this test, I am clicking every possible anchor links using the page.click method. it is not running the remaining 91 tests. I increased the timeout to 300 sec but still, it's stopping before that.

I saw a weird behavior that is, the sidebar comes with a toggle button. So by default that sidebar is open. But before exiting of closing the browser, IDK but it's toggling the sidebar to close it and then closing the browser. check the tests for sideBar.spec.js You can find the behavior of the test here https://travis-ci.org/docsifyjs/docsify/jobs/631003978?utm_medium=notification&utm_source=github_status

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Aniketh Saha
  • 843
  • 10
  • 22
  • I think it's the default timeout puppeteer has. I didn't check everything you provided but I'd start with that. It has a set timeout (I think after a minute) that you need to modify to keep it open as long as you want. how's [that](https://stackoverflow.com/questions/52163547/node-js-puppeteer-how-to-set-navigation-timeout)? – Jabberwocky Jan 08 '20 at 10:17
  • 1
    So should I increase the timeout ? as passing 0 is actually disabling right. – Aniketh Saha Jan 08 '20 at 10:35
  • I'm not sure setting it to 0 is disabling it. I don't have a legit answer but I remember googling and finding issues about setting it to 0 and not working. It's a little bit deeper, but it may be your solution – Jabberwocky Jan 15 '20 at 17:52

1 Answers1

0

browser is not closing before executing all the tests, that's not the case. in beforeAll hook add parameter browser = await puppeteer.launch({headless: false}), it always easier when you see whats happening.

I played for a while with ur code and checked in console if the selectors your are trying to click really exists, and it appears they do not. (also you can clearly see it in logs you provided: Node is either not visible or not an HTMLElement etc)

eg:

const cdnIds = [
 'latest-version',
 'specific-version',
 'compressed-file',
 'other-cdn'
]
cdnIds.forEach(id => {
 test('go to #cdn?id=' + id, async done => {
   await page.click(`a.section-link[href='#/cdn?id=${id}']`)
   const ss = await page.screenshot()
   expectThres(ss)
   done()
 })
})

there's no matching selector such as a.section-link[href='#/cdn?id=other-cdn'] or a.section-link[href^='#/cdn'] <-- 2nd one should match every each of cdnIds array. I guess you need to rewrite your tests. good luck

domlas
  • 173
  • 7
  • actually they are hidden. So their parent `a` needs to be clicked and then they will be visible. All the sidebar tags are like that only. first the `a` is clicked then its child (ul > li > a.section-link[...]) is visible. – Aniketh Saha Jan 09 '20 at 19:04
  • I am running them locally in headless: false only. if you are running locally, you can see a weird behavior that after some sidebar test, mostly in the `plugins` loop, before exiting the browser, puppeteer is closing (toggling) the sidebar – Aniketh Saha Jan 09 '20 at 19:07