rosshinkley / nightmare-inline-download

36 stars 8 forks source link

Throw an exception Nightmare runner error: Object has been destroyed after download done #1

Closed mario8x closed 8 years ago

mario8x commented 8 years ago

Hi, Currently, i got an issue when download a file from apple site This is my script:

const downloadInfo = await nightmare .goto(appleUI.url) .wait(appleUI.header) .insert(appleUI.userNameTxt) .insert(appleUI.userNameTxt, appleAccount.user) .insert(appleUI.passWordTxt, appleAccount.password) .click(appleUI.signInBtn) .wait(global.objectTimeout) .wait(appleUI.certificateLnk) .click(appleUI.certificateLnk) .wait(global.objectTimeout) .wait(appleUI.allProvisionFilesLnk) .click(appleUI.allProvisionFilesLnk) .wait(#grid-table td[title="${provisionName}"]) .click(#grid-table td[title="${provisionName}"]) .wait(global.objectTimeout) .wait(appleUI.downloadLnk) .click(appleUI.downloadLnk) .download()

. It throw an exception as below:

Nightmare runner error: Error: Object has been destroyed at Error (native) at wait [as _onTimeout](eval at %28/Users/quangxn/Kobiton/04. SourceCode/tests-add_udid_auto/node_modules/nightmare/lib/runner.js:358:14%29, :53:26) at Timer.listOnTimeout (timers.js:92:15) nighmare_download.txt

But the file is still download successfully. Please help me review it. I attached log file. nighmare_download.txt

mario8x commented 8 years ago

I created a nightmare as below:

const nightmare = createNightmare({ show: global.headless, waitTimeout: global.waitTimeout, // in ms maxDownloadRequestWait: 30000, paths: { downloads: downloadPath } })

rosshinkley commented 8 years ago

@mario8x Thanks for the repro steps, I'll take a look at this and see what I can do.

rosshinkley commented 8 years ago

The one thing that jumps out at me in the log is the did-fail-load. I'd be curious what failed to load. If you perform the steps in your script by hand in Chrome, what does the development console say? What's failing to load on that last page? It looks like it's a hard network abort (error code -3).

I don't know if that's the whole cause, but it's certainly not helping.

If you'd like, I could prep a release that has more verbose logging and better error handling. What do you think?

mario8x commented 8 years ago

Thanks for your feedback @rosshinkley . If you perform the steps in your script by hand in Chrome, what does the development console say?

I tried to use nightmare-download-manager and it work well. I guess the root cause is timeout configuration. My new script is as below: const nightmare = createNightmare({ show: config.show, waitTimeout: 240000, downloadResponseWait: 10000, paths: { downloads: path.dirname(filePath) } }) try { nightmare.on('download', function (state, downloadItem) { if (state == 'started') { nightmare.emit('download', filePath, downloadItem) } }) await nightmare .use(this._login({username: this._username, password: this._password})) .use(this._downloadProvisionFile(provisionName)) } finally { await nightmare.end() }

_downloadProvisionFile(provisionName) { return (nightmare) => { nightmare .downloadManager() .wait(config.objectTimeout) .wait(elements.allProvisionFilesLnk) .click(elements.allProvisionFilesLnk) .wait(#grid-table td[title="${provisionName}"]) .click(#grid-table td[title="${provisionName}"]) .wait(config.objectTimeout) .wait(elements.editBtn) .click(elements.editBtn) .wait(elements.selectAllDeviceCheck) .check(elements.selectAllDeviceCheck) .wait(elements.generateBtn) .click(elements.generateBtn) .wait(elements.downloadBtn) .click(elements.downloadBtn) .waitDownloadsComplete() }