puppeteer error "Cannot find context with specified id undefined"
See original GitHub issueWhat are you trying to achieve?
- open a page
- click a link by
click
see
text from new page
What do you get instead?
Got this error and test failed.
Account - basic flow: login, navigation to pages --
test
• I am on page "https://github.com/"
• I click "About"
• I see "is how people build software"
✖ FAILED in 3314ms
-- FAILURES:
1) Account - basic flow: login, navigation to pages
test :
Protocol error (Runtime.callFunctionOn): Cannot find context with specified id undefined
Scenario Steps:
- I.see("is how people build software") at Test.Scenario (account-basic_test.js:10:5)
- I.click("About") at Test.Scenario (account-basic_test.js:9:5)
- I.amOnPage("https://github.com/") at Test.Scenario (account-basic_test.js:8:5)
Run with --verbose flag to see NodeJS stacktrace```
But the captured failed screenshot is correct.
> Provide test source code if related
```js
Scenario('test ', (I) => {
I.amOnPage('https://github.com/');
I.click('About');
I.see('is how people build software');
});
Details
- CodeceptJS version: 1.14
- NodeJS Version: 9.4
- Operating System: macOS
- puppeteer
- Configuration file:
{
"tests": "./*_test.js",
"timeout": 10000,
"output": "./output",
"helpers": {
"puppeteer": {
"disableScreenshots": true,
"waitForAction": 200,
"show": true
}
},
"include": {
"I": "./steps_file.js"
},
"bootstrap": false,
"mocha": {},
"name": "web-test-runner"
}
PS. It related to the value of waitForAction
. If change it to larger. error will not happen.
More Information
This issue is related to GoogleChrome/puppeteer#1325.
And I think latest comment is correct. The problem is because the click promise resolved when click triggered. But at that moment, navigation is not complete. No context is ready for new action.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
When would an error "Cannot find context with specified id ...
I am getting the following error: Error: Protocol error (Runtime.callFunctionOn): Cannot find context with specified id undefined at Session ...
Read more >cannot find context with specified id undefined - Stack Overflow
My test was completing but I was getting this error when attempting to await browser.close(); Adding the wait after searching for my final ......
Read more >When would an error "Cannot find context with specified id ...
I am getting the following error: Error: Protocol error (Runtime.callFunctionOn): Cannot find context with specified id undefined at Session ...
Read more >Aaron Lee on Twitter: "Error: Protocol error (Runtime.callFunctionOn ...
Error: Protocol error (Runtime.callFunctionOn): Cannot find context with specified id undefined. 6:23 AM · May 23, 2018 ·Twitter Web Client.
Read more >Puppeteer documentation - DevDocs
If Puppeteer doesn't find them in the environment during the installation step, ... For certain types of errors Puppeteer uses specific error classes....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve just spent a bit of time looking into this and it is slightly more complex than I thought. Though I found some useful information on the puppeter repo.
It looks like that you have to call the
.click
andpage.waitForNavigation
at the same time like so:The reason that it needs to be called at the same time is that apparently .waitForFunction needs to see the new page trigger and the load events occur. So just seeing the page load event is not enough.
So our problem is that we don’t know which links will cause a new page to load. And if the above code is used and the link does not change the url, then it will throw a timeout error.
Now we could check the button if it is link like, however that does not cater for the scenario if there are event handlers on it which cause a redirect somewhere. So here are some options.
Option 1: Auto detect url changes and wait if one is detected (a little bit hacky)
However I have been playing around with the idea with using the
targetchanged
andload
events, and recording theurl has changed and loaded
state information. So the scenario would play out like this:targetchanged
event to trigger).targetchanged
event triggers, and sets a urlChanged flagload
event triggers, reset the urlChanged flag.Option 2: Split the I.click function into navigation and non-navigation functions
Option 3: The user must wait for the page to load themselves
Maybe using
I.waitInUrl
or something similar to that…Thoughts?
There is a
page.waitForNavigation
method mentioned in GoogleChrome/puppeteer#1325 , I didn’t tested yet. And it will have another problem, some click didn’t trigger navigation. Or maybe codecept can expose it to outside.