添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account Window.document.body.scrollHeight retrieved with ClientFunction is not resetting between test runs #3648 Window.document.body.scrollHeight retrieved with ClientFunction is not resetting between test runs #3648 byrne-greg opened this issue Apr 5, 2019 · 2 comments

I asked the question at StackOverflow and couldn't find an example of this explained in the docs or other issues, but the more I thought of it, the more I thought it could be a bug (just need to verify from a maintainer).

Rehasing the question asked on StackOverflow , I have tests where I need to recognise the scrollHeight of each page. The scrollHeight will differ wildly between pages, depending on the page content.

Using the ClientFunction , I can retrieve the window.document.body.scrollHeight successfully and correctly within a test. However the weirdness starts when I test with multiple tests.

smallpageTest.js

fixture`smallpage`
test('smallpageTest', async t => {
  //...
  const getBodyHeight = ClientFunction(() => window.document.body.scrollHeight); 
  console.log(`${test} body.scrollHeight`, await getBodyHeight()); // 800px
 // ...

longpageTest.js

fixture`longpage`
test('longpageTest', async t => {
  //...
  const getBodyHeight = ClientFunction(() => window.document.body.scrollHeight); 
  console.log(`${test} body.scrollHeight`, await getBodyHeight()); // 1200px
  //...

When run in that order, it's fine.

smallpageTest body.scrollHeight 800px
longpageTest body.scrollHeight 1200px

However when ran in reverse order (big to small), it seems the scrollHeight is set to the long side all the time

longpageTest body.scrollHeight 1200px
smallpageTest body.scrollHeight 1200px

My gut is that the test runner is holding onto the state at a global level. I call the tests using an npm test call (testcafe -firefox:headless *Test.js) rather than setting up any specific testcafe runner.
Adding -c for concurrency and passing 2 (as there are two tests) also solves this issue, but theorising only because each of the two tests are executed separately.

Any ideas how I can have the correct sizing independent of the order? Or perhaps a way to reset the scrollHeight between tests?