testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

TestCafe intermittently throws "Cannot read property '0' of null"

Open kacy-weakley opened this issue 4 years ago • 10 comments

What is your Scenario?

When we use TestCafe version 1.14.2, our test suites pass consistently. When we attempt to upgrade to a newer version, even TestCafe 1.18.6, our tests intermittently fail. We would like to be able to upgrade to the latest version of TestCafe.

What is the Current behavior?

When we try to update to versions of TestCafe greater than 1.14.2, many different scenarios in our test suite trigger the "Cannot read property '0' of null" error.

When using page objects, the stack is usually unhelpful:

 ✖ User has ability to insert a Creative Assistant block into their email campaigns (screenshots:
 /Volumes/casesensitive/git/mc_testcafe/reports/2022-05-05_09-09-26/1/errors/1.png)

   1) TypeError: Cannot read property '0' of null

      Browser: Chrome 100.0.4896.127 / macOS 10.15.7
      Screenshot: /Volumes/casesensitive/git/mc_testcafe/reports/2022-05-05_09-09-26/1/errors/1.png

         270 |        this._handlePlainObject(val);
         271 |};
         272 |
         273 |DecodingTransformer.prototype.transform = function () {
         274 |    this.visitedRefs[0] = true;
       > 275 |    this._handleValue(this.references[0], this.references, 0);
         276 |
         277 |    return this.references[0];
         278 |};
         279 |
         280 |

         at DecodingTransformer.transform (/Volumes/casesensitive/git/mc_testcafe/node_modules/replicator/index.js:275:38)
         at module.exports.Replicator.decode (/Volumes/casesensitive/git/mc_testcafe/node_modules/replicator/index.js:577:24)



 1/1 failed (2m 47s)

It seems that the error becomes slightly more helpful when not creating any abstractions, but the error still unexpected:

 Running tests in:
 - Chrome 100.0.4896.127 / macOS 10.15.7

 Using the Creative Assistant in the Nuni email editor
 ✖ TestCafe Demo Test (screenshots: /Volumes/casesensitive/git/mc_testcafe/reports/2022-05-05_09-49-25/1/errors/1.png)

   1) TypeError: Cannot read property '0' of null

      Browser: Chrome 100.0.4896.127 / macOS 10.15.7
      Screenshot: /Volumes/casesensitive/git/mc_testcafe/reports/2022-05-05_09-49-25/1/errors/1.png

         27 |      .expect(loadingFrame.classNames)
         28 |      .notMatch(/active/, "container loading frame active", {timeout: 60000})
         29 |      .switchToIframe(Selector("#fallback:not([title *='Loading'])").with({visibilityCheck: true, timeout: 30000}));
         30 |  }
         31 |  await t
       > 32 |    .expect(Selector("[data-dojo-attach-point='itemContent'] img").with({ visibilityCheck: true }).exists).ok({timeout: 20000})
         33 |    .click(Selector("button").withText("Design Email"))
         34 |    .click(Selector("button").withAttribute("data-dojo-attach-point", "selectInlineEditorButton"))
         35 |});
         36 |

         at <anonymous> (/Volumes/casesensitive/git/mc_testcafe/browser_tests/campaigns/email/nuni/TestCafeDemoTests.js:32:13)
         at asyncGeneratorStep (/Volumes/casesensitive/git/mc_testcafe/browser_tests/campaigns/email/nuni/TestCafeDemoTests.js:1:230)
         at _next (/Volumes/casesensitive/git/mc_testcafe/browser_tests/campaigns/email/nuni/TestCafeDemoTests.js:1:568)



 1/1 failed (1m 34s)

What is the Expected behavior?

Tests should consistently pass with TestCafe 1.18.6 just as they do with TestCafe 1.14.2.

What is your public website URL? (or attach your complete example)

https://mailchimp.com/login

What is your TestCafe test code?

import {Selector} from "testcafe";

fixture`TestCafe Demo Test`
  .beforeEach(async t => {
    await t
    .maximizeWindow()
    .navigateTo("https://mailchimp.com/login")
      .expect(Selector("div").withAttribute("data-mc-el", "loginAnnouncementAnimation")
        .with({ visibilityCheck: true }).exists).ok()
      .typeText(Selector("#username"), "abc123") // Enter your username here
      .typeText(Selector("#password"), "abc123") // Enter your password here
      .click(Selector("button[value='log in']"));
  })

test('Create email campaign', async t => {
  await t.click(Selector("li a").withAttribute("href", "#/create-campaign"))
    .click(Selector("div[role = 'listitem']").withText("Email"))
    .click(Selector("a span").withExactText("Regular"))
    .typeText(Selector("input").withAttribute("name", "textValue"), "Test Campaign")
    .click(Selector("button").withText("Begin"))
    .switchToMainWindow();

  const loadingFrame = Selector("[class *= 'frame'] [class *= 'loading']");
  await loadingFrame();
  if (await loadingFrame.exists) {
    await t
      .expect(loadingFrame.classNames)
      .notMatch(/active/, "container loading frame active", {timeout: 60000})
      .switchToIframe(Selector("#fallback:not([title *='Loading'])").with({visibilityCheck: true, timeout: 30000}));
  }
  await t
    .expect(Selector("[data-dojo-attach-point='itemContent'] img").with({ visibilityCheck: true }).exists).ok({timeout: 20000})
    .click(Selector("button").withText("Design Email"))
    .click(Selector("button").withAttribute("data-dojo-attach-point", "selectInlineEditorButton"))
});

Your complete configuration file

{ "reporter": [ { "name": "spec" }, { "name": "html", "output": "reports/myreports.html" }, { "name": "json", "output": "reports/report.json" } ], "skipJsErrors": true, "screenshots": { "path": "reports/", "fullPage": true, "pathPattern": "${DATE}_${TIME}/${TEST_INDEX}/${FILE_INDEX}.png", "takeOnFails": true }, "src": "browser_tests/", "browsers": ["chrome"], "concurrency": 4, "allowMultipleWindows":true, "videoPath": "reports/videos", "videoOptions" : { "singleFile": true, "failedOnly": true, "pathPattern": "${TEST_INDEX}/${USERAGENT}/${FILE_INDEX}.mp4" }, "color": true, "clientScripts":[ {"module":"axe-core/axe.min.js"}, {"content": "window.addEventListener('error', function (e) {console.error(e.message);});"} ] }

Your complete test report

I tried attaching the html report, but Github gave me an error when I tried to create the issue, stating that the body is too long. Please letm know what additional content from the html report would be helpful.

Screenshots

1

Steps to Reproduce

  1. Log in (I'm unable to provide you with an account, but you all have created free accounts to help us previously)
  2. Click "Create"
  3. Select "Email"
  4. Select "Regular"
  5. Enter campaign title
  6. Select "Begin"
  7. Select "Design Email"
  8. Select "New Editor"

TestCafe version

1.18.6

Node.js version

14.17.2

Command-line arguments

testcafe -c 1 -T "TestCafe Demo Test"

Browser name(s) and version(s)

Chrome 100.0.4896.127

Platform(s) and version(s)

macOS 10.15.7

Other

The tests do not fail 100% of the time, so you may need to rerun the test demo script included in this issue several times before the error appears. Adjusting the timeouts for elements does not resolve the flakiness.

kacy-weakley avatar May 05 '22 14:05 kacy-weakley

Hi @kacy-weakley

I didn't reproduce the original issue due to another issue: there is a JavaScript error on the login page. image

Firstly, we will investigate this issue. As soon as we have any results, we will update this thread.

miherlosev avatar May 10 '22 08:05 miherlosev

Hi @kacy-weakley

I didn't reproduce the original issue due to another issue: there is a JavaScript error on the login page. image

Firstly, we will investigate this issue. As soon as we have any results, we will update this thread.

@miherlosev We have "skipJsErrors": true in our configuration file.

kacy-weakley avatar May 10 '22 13:05 kacy-weakley

I see that the macOS label was added so I thought it'd be helpful to add that these errors occur both locally on macOS and also in Jenkins running with docker.

kacy-weakley avatar May 12 '22 23:05 kacy-weakley

We have "skipJsErrors": true in our configuration file.

This option hides the TestCafe issue. The tested web doesn't have such an error. The described issue can be caused by this unhandled JavaScript error.

I see that the macOS label was added so I thought it'd be helpful to add that these errors occur both locally on macOS and also in Jenkins running with docker.

I removed this label.

miherlosev avatar May 13 '22 09:05 miherlosev

We have "skipJsErrors": true in our configuration file.

This option hides the TestCafe issue. The tested web doesn't have such an error. The described issue can be caused by this unhandled JavaScript error.

@miherlosev Ah, I see that in the error description now. Thank you for clarifying. In that case, what else do you need from me to move forward in resolving this first JavaScript error?

kacy-weakley avatar May 13 '22 13:05 kacy-weakley

No, we don't need an additional information. We will update this thread as soon as we have news.

miherlosev avatar May 16 '22 08:05 miherlosev

Any progress here?

I'm getting this error randomly:


      Browser: Chrome 112.0.0.0 / Windows 10

         270 |        this._handlePlainObject(val);
         271 |};
         272 |
         273 |DecodingTransformer.prototype.transform = function () {
         274 |    this.visitedRefs[0] = true;
       > 275 |    this._handleValue(this.references[0], this.references, 0);
         276 |
         277 |    return this.references[0];
         278 |};

NagRock avatar Apr 25 '23 11:04 NagRock

In my case it was:

Error thrown:

const mySelector = Selector('[data-testid=my-id]');
await mySelector();

Passed:

const mySelector = Selector('[data-testid=my-id]');
await t.expect(mySelector.exists).ok();

NagRock avatar Apr 25 '23 12:04 NagRock

No updates yet. Once we get any results, we will post them in this thread.

github-actions[bot] avatar Apr 26 '23 06:04 github-actions[bot]

Duplicate of https://github.com/DevExpress/testcafe/issues/7707

miherlosev avatar May 31 '23 06:05 miherlosev