Closed dennyjun closed 5 years ago
maybe you can send a pull request then?
Hi @dennyjun !
You should admit that ``ìnjectScript``` is an async function which waits a callback function in third parameter when the command finishes. Did you allready try as follow :
browser
.url('https://www.bing.com')
.waitForElementVisible('body', 15000)
.injectScript('https://cdnjs.cloudflare.com/ajax/libs/ramda/0.24.1/ramda.min.js', () => {
browser.execute(data => R.add(1, 2), [], (result) => assert.strictEqual(result.value, 3))
})
Hi @ridrum !
The callback function does not check to see if the script has been loaded. It will run after nighwatch runs its execute function inside of injectScript. Puppeteer's addScriptTag function waits until onload has fired and I have not had any issues with that so far. Even if the format you suggested worked, it would mean callback hell for multiple inject scripts. I will send in a PR to address the issue.
@dennyjun You're right ! Nice catch ! That would be a good improvement !
This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.
This error happens sometimes in Windows 10 PRO. I think that the script is being added to the DOM but it hasn't been loaded yet when I try to execute using code from the script after injectScript. I think the fix will need to change the injectScript method to use executeAsync instead of execute and use done in script.onload.
so...
will need to be something like
will need timeoutsAsyncScript or some way to wait for the script to actually load
Example Test:
Log - actual error
Logs
Spec