DevExpress / testcafe

A Node.js tool to automate end-to-end web testing.
https://testcafe.io
MIT License
9.82k stars 671 forks source link

Inspected target navigated or closed #8193

Closed vasilyevi closed 2 months ago

vasilyevi commented 4 months ago

What is your Scenario?

After upgrading to 3.6.0 the issue happens randomly, the same code might work multiple time, but 1-3 of of 10 run could be failed

What is the Current behavior?

Unhandled promise rejection:

ERROR 'Error: Inspected target navigated or closed at /home/runner/test/src/js/tests/node_modules/chrome-remote-interface/lib/chrome.js:94:35 at Chrome._handleMessage (/home/runner/test/src/js/tests/node_modules/chrome-remote-interface/lib/chrome.js:272:17) at WebSocket. (/home/runner/test/src/js/tests/node_modules/chrome-remote-interface/lib/chrome.js:240:22) at WebSocket.emit (node:events:517:28) at WebSocket.emit (node:domain:489:12) at Receiver.receiverOnMessage (/home/runner/test/src/js/tests/node_modules/ws/lib/websocket.js:1068:20) at Receiver.emit (node:events:517:28) at Receiver.emit (node:domain:489:12) at Receiver.dataMessage (/home/runner/test/src/js/tests/node_modules/ws/lib/receiver.js:517:14) at Receiver.getData (/home/runner/test/src/js/tests/node_modules/ws/lib/receiver.js:435:17)

What is the Expected behavior?

N/A

What is the public URL of the test page? (attach your complete example)

N/A

What is your TestCafe test code?

N/A

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

N/A

TestCafe version

3.6.0

Node.js version

v18.19.1

Command-line arguments

npx testcafe

Browser name(s) and version(s)

No response

Platform(s) and version(s)

No response

Other

No response

github-actions[bot] commented 4 months ago

Thank you for submitting a bug report. We would love to help you investigate the issue. Please share a simple code example that reliably reproduces the bug. For more information, read the following article: How To Create a Minimal Working Example When You Submit an Issue. We look forward to your response.

vasilyevi commented 4 months ago

As I wrote, unfortunately I do not have exact steps to be able to stable reproduce the issue, happens just randomly and not too often, so cannot provide exact sample. Maybe stacktrace might give you some ideas...

vasilyevi commented 4 months ago

few more things. As far as I can see it always happens as Unhandled promise rejection. Actually, everytime it happens the test itself is completed, so it performs all the steps from the beginning to the end. But on after step const hasErr = !!t.testRun.errs.length; returns true. Sometimes it happens in before hook, sometimes during the test itself, but always it completes all the steps and fail the test in after hook because it says that this is an error.

image

Do you have any testcafe logs or something which might give more details?

Bayheck commented 4 months ago

Hello,

Unfortunately, without a minimal working example, we cannot determine the cause of this issue.

vasilyevi commented 4 months ago

So, there is no any testcafe logs or somehting?

Bayheck commented 4 months ago

Hello,

You can try to enable TestCafe logs on your CI - set DEBUG=testcafe:*,hammerhead:*.

vasilyevi commented 4 months ago

Where to set? is it env var?

vasilyevi commented 4 months ago

Would that work with native automation?

Bayheck commented 4 months ago

Yes, it is an environment variable, and it works with native automation.

To enable the debug log, you can use the following way:

set DEBUG=testcafe:*,hammerhead:*
testcafe chrome index.js 2> testcafe.log

Before running TestCafe, you need to set the DEBUG environment variable like in the example above. Then, you need to run TestCafe and redirect the output to the file.

Please refer to the following help topic for details: https://testcafe.io/documentation/402636/faq/general-info#related-questions.

port-eighty commented 2 months ago

Yes, it is an environment variable, and it works with native automation.

To enable the debug log, you can use the following way:

set DEBUG=testcafe:*,hammerhead:*
testcafe chrome index.js 2> testcafe.log

Before running TestCafe, you need to set the DEBUG environment variable like in the example above. Then, you need to run TestCafe and redirect the output to the file.

Please refer to the following help topic for details: https://testcafe.io/documentation/402636/faq/general-info#related-questions.

I have a similar problem but for my case is weirder. Using the logs how would I debug it further? I managed to reproduce it more accurately by just navigating to the test's login page. This error is not present in version 3.4.0 and older. Testing.js

fixture(`Debugging`)
  .page('www.google.com')
  .beforeEach(async t => {
    await t.setNativeDialogHandler(null)
    await t.maximizeWindow()
    await t.navigateTo('<REDACTED>')
  })

test('simple test', async t => {
  await t.expect(true).ok()
})

Console output snippet

testcafe:native-automation:request-pipeline:other-request requestPaused 44020.58 interception-job-78.0 response https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2 +27ms
  testcafe:native-automation:request-pipeline:context disposed 44020.58 +28ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.11 interception-job-58.0 response https://<REDACTED>/main.fecf709b4025fa5e.js +25ms
  testcafe:native-automation:request-pipeline:context disposed 44020.11 +24ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.10 interception-job-61.0 response https://<REDACTED>/scripts.88b9b29f84a7d940.js +101ms
  testcafe:native-automation:request-pipeline:context disposed 44020.10 +102ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.12 interception-job-62.0 response https://<REDACTED>/assets/fullCalendar/fullcalendar.min.js +89ms
  testcafe:native-automation:request-pipeline:context disposed 44020.12 +88ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.13 interception-job-63.0 response https://<REDACTED>/assets/fullCalendar/scheduler.min.js +35ms
  testcafe:native-automation:request-pipeline:context disposed 44020.13 +37ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.14 interception-job-64.0 response https://<REDACTED>/assets/external-plugs/tooltip/tooltip.js +6ms
  testcafe:native-automation:request-pipeline:context disposed 44020.14 +5ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.15 interception-job-65.0 response https://<REDACTED>/assets/qTip/jquery.qtip.min.js +9ms
  testcafe:native-automation:request-pipeline:context disposed 44020.15 +9ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.16 interception-job-66.0 response https://<REDACTED>/assets/contextMenu/jquery.contextMenu.js +8ms
  testcafe:native-automation:request-pipeline:context disposed 44020.16 +8ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.17 interception-job-67.0 response https://<REDACTED>/assets/contextMenu/jquery.ui.position.min.js +17ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.18 interception-job-68.0 response https://<REDACTED>/assets/powertip/jquery.powertip.min.js +1ms
  testcafe:native-automation:request-pipeline:context disposed 44020.17 +19ms
  testcafe:native-automation:request-pipeline:context disposed 44020.18 +0ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.19 interception-job-69.0 response https://<REDACTED>/assets/npm-assets/fontawesome/css/all.min.css +2ms
  testcafe:native-automation:request-pipeline:context disposed 44020.19 +1ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.21 interception-job-70.0 response https://<REDACTED>/assets/theme/indigo/theme-light.css +31ms
  testcafe:native-automation:request-pipeline:context disposed 44020.21 +31ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.22 interception-job-71.0 response https://<REDACTED>/assets/layout/css/layout-light.css +35ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.89 interception-job-80.0 request https://<REDACTED>/assets/css/animation/animate.min.css +1ms
  testcafe:native-automation:request-pipeline:context initialized 44020.89 +35ms
  testcafe:native-automation:request-pipeline:context disposed 44020.22 +1ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.73 interception-job-73.0 response https://<REDACTED>/images/titan-logo-dark.png +26ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.24 interception-job-72.0 response https://<REDACTED>/styles.491c52beb1363393.css +1ms
  testcafe:native-automation:request-pipeline:context disposed 44020.73 +26ms
  testcafe:native-automation:request-pipeline:context disposed 44020.24 +0ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.74 interception-job-74.0 response https://<REDACTED>/images/body-loader.gif +601ms
  testcafe:native-automation:request-pipeline:other-request requestPaused 44020.89 interception-job-80.0 response https://<REDACTED>/assets/css/animation/animate.min.css +2ms
  testcafe:native-automation:request-pipeline Unhandled error ProtocolError: Inspected target navigated or closed
    at /Users<REDACTED>node_modules/chrome-remote-interface/lib/chrome.js:94:35
    at Chrome._handleMessage (/Users<REDACTED>node_modules/chrome-remote-interface/lib/chrome.js:272:17)
    at WebSocket.<anonymous> (/Users<REDACTED>node_modules/chrome-remote-interface/lib/chrome.js:240:22)
    at WebSocket.emit (node:events:518:28)
    at WebSocket.emit (node:domain:488:12)
    at Receiver.receiverOnMessage (/Users<REDACTED>node_modules/ws/lib/websocket.js:1068:20)
    at Receiver.emit (node:events:518:28)
    at Receiver.emit (node:domain:488:12)
    at Receiver.dataMessage (/Users<REDACTED>node_modules/ws/lib/receiver.js:517:14)
    at Receiver.getData (/Users<REDACTED>node_modules/ws/lib/receiver.js:435:17) {
  request: [Object],
  response: [Object]
} during processing {
  sessionId: '3F0E89B066DA52C0046ABAFAE019917D',
  targetInfo: [Object],
  waitingForDebugger: true
} +1s

From the snippet there are no other indicators of why that promise was rejected which in turn fails the test regardless if it passes or not.

Bayheck commented 2 months ago

Hello,

Thank you for the example. However, we couldn't reproduce the issue because you did not include the actual navigation link:

await t.navigateTo('')

Please update your example so that we can reproduce the issue on our end.

port-eighty commented 2 months ago

Hello,

Thank you for the example. However, we couldn't reproduce the issue because you did not include the actual navigation link:

await t.navigateTo('')

Please update your example so that we can reproduce the issue on our end.

Hi,

I am unable to provide internal link nor able to reproduce it on other websites so far. What other tools or what can I do to further debug it?

razvanvancea commented 2 months ago

I am facing the same thing

macos pro - silicon chip - sonoma 14.5 nodejs 18.17.0 chrome browser (only) - 126.0.0 - I had to run the tests on firefox/safari as workarounds "testcafe": "3.6.2"

2) Unhandled promise rejection:

  Error: Inspected target navigated or closed
  at /Users/razvan.vancea/Test/Test/test-automation/node_modules/chrome-remote-interface/lib/chrome.js:94:35
  at Chrome._handleMessage (/Users/razvan.vancea/Projects/Test/test-automation/node_modules/chrome-remote-interface/lib/chrome.js:272:17)
  at WebSocket.<anonymous> (/Users/razvan.vancea/Projects/Test/test-automation/node_modules/chrome-remote-interface/lib/chrome.js:240:22)
  at WebSocket.emit (node:events:514:28)
  at WebSocket.emit (node:domain:489:12)
  at Receiver.receiverOnMessage (/Users/razvan.vancea/Projects/Test/test-automation/node_modules/ws/lib/websocket.js:1070:20)
  at Receiver.emit (node:events:514:28)
  at Receiver.emit (node:domain:489:12)
  at Receiver.dataMessage (/Users/razvan.vancea/Projects/Test/test-automation/node_modules/ws/lib/receiver.js:517:14)
  at Receiver.getData (/Users/razvan.vancea/Projects/Test/test-automation/node_modules/ws/lib/receiver.js:435:17)

  Browser: Chrome 126.0.0.0 / Sonoma 14
razvanvancea commented 2 months ago

== page object == import { Selector } from 'testcafe';

class CommonPage { constructor() { this.acceptCookiesBtn = Selector('#cc-wrapper a').withText('Permite toate'); } }

export default new CommonPage();

== test == fixtureUser actions Test Suite.page${baseUrl}; test('create account test', async (t) => { await t .click(CommonPage.acceptCookiesBtn) .hover(HeaderPage.myAccountBtn) .click(HeaderPage.createAccountBtn); await RegisterPage.createAccount( chance.first(), 'TestCafe', test@test.com, 'test' );

await t
    .expect(
        Selector('main div').withText('Vă mulțumim că v-ați înregistrat la')
            .visible
    )
    .ok();

});

github-actions[bot] commented 2 months ago

This issue was automatically closed because there was no response to our request for more information from the original author. Currently, we don't have enough information to take action. Please reach out to us if you find the necessary information and are able to share it. We are also eager to know if you resolved the issue on your own and can share your findings with everyone.

port-eighty commented 1 month ago

In node_modules/testcafe/lib/native-automation/request-pipeline/index.js I have just opted to ignore that error entirely using:

try{
                        await this._client.Runtime.runIfWaitingForDebugger(event.sessionId);
                    } catch(error) {
                        console.error('Caught weird error in-attachedToTarget')
                        if(error.response) {
                            /* console.error(typeof error.response)
                            console.error(error.response) */
                            if(error.response.message) {
                                /* console.error(typeof error.response.message)
                                console.error(error.response.message)
                                console.error(error.response.message.includes("Inspected target navigated or closed")) */
                                const message = error.response.message
                                if(typeof message === 'string' && message.includes("Inspected target navigated or closed")) {
                                    return
                                }
                            }

                        }
                        //resolve other
                        console.error(error)
                    }

as my issue is only stemming from await this._client.Runtime.runIfWaitingForDebugger(event.sessionId); even though the test passes.