Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

Console message before driver.start() throws "Cannot read property 'getItem' of null" #1875

Closed
caseyWebb opened this issue Oct 12, 2017 · 4 comments
Labels
AREA: client !IMPORTANT! STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: bug The described behavior is considered as wrong (bug).
Milestone

Comments

@caseyWebb
Copy link
Contributor

Are you requesting a feature or reporting a bug?

Bug

What is the current behavior?

Event listeners in the driver which depend on contextStorage are registered before contextStorage is initialized, so if a JS error or console message is emitted before driver.start() is called, an error is thrown.

What is the expected behavior?

No errors.

How would you reproduce the current behavior (if this is a bug)?

Emit a console message on page load. IDK what/when driver.start() is called from just poking around, but as long as it's before that, it's reproducible.

Provide the test code and the tested page URL (if applicable)

Tested page URL: Can share privately, if necessary.

Test code

test(url, async (t) => {
  await t
    .useRole(DefaultRole)
    .navigateTo(url)
    .expect(Selector('#ToolBar').with({ timeout: 60000 }).exists).ok()
    .expect(Selector('div[data-test="404"]').exists).notOk()
    .expect(Selector('div[data-test=errors]').exists).notOk()
})

Specify your

  • operating system: any
  • testcafe version: v0.18
  • node.js version: 8.7.0

In my poking around to make sure that the error was in TestCafe and not my code, I was able to fix this w/ trivial changes — the context storage just needs to be initialized in the constructor, before the event listeners are registered. If I'm missing something that prevents the initialization in the constructor, the event listeners could alternatively be registered in the start method.

@AlexanderMoskovkin
Copy link
Contributor

AlexanderMoskovkin commented Oct 16, 2017

Hi @caseyWebb,

Thanks for your report and the PR!
Could you please clarify, do you reproduce the problem on the page with iframes?
I don't see a way how it can happen in the top window because the Driver constructor and the start function are called synchronously one after one (see client/test-run/index.js.mustache#L38). So any js-error or console.log calls can't appear between these calls.
But now I see that it can happen in iframes. The contextStorage in an iframeDriver is initialized anychronously (see client/driver/iframe-driver.js#L76). The top driver keep ids for every iframe on the page. When an iframe driver is initialized it requests its id from the top driver and then initializes its own contextStorage with this id. That's why we can't do it in the constructor.
Could you please share the link to your page with me via my email ([email protected])? It'll help us to find the best way to resolve the issue.

@caseyWebb
Copy link
Contributor Author

caseyWebb commented Oct 17, 2017

I was wondering that myself when taking a second look at the code to be honest. It's testing a part of our app that is way before my time and I'm unfamiliar with, but it does use iframes heavily. I'll email you the link + login to check it out yourself.

@AlexanderMoskovkin
Copy link
Contributor

Thanks, I've got your mail.

@lock
Copy link

lock bot commented Mar 28, 2019

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
kirovboris pushed a commit to kirovboris/testcafe-phoenix that referenced this issue Dec 18, 2019
…evExpress#1914)

* Test added

* Iframe driver fixes (closes DevExpress#1842, closes DevExpress#1875)

* Formatting

* Change child driver link default timeout

* Formatting

* Update test name
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AREA: client !IMPORTANT! STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

2 participants