getgauge / taiko

A node.js library for testing modern web applications
https://taiko.dev
MIT License
3.56k stars 452 forks source link

Tests do not start with Chrome and Edge with version 110 and above with --headless flag #2706

Open ankur-lt opened 1 year ago

ankur-lt commented 1 year ago

Describe the bug I am launching Chrome browser and passing its WS URL in the target. Refer the taiko plugin: https://www.npmjs.com/package/taiko-lambdatest When launching Chrome >= 110 with the ALI arg --headed, the chrome-remote-interface keeps on calling the /json/protocol API when though the response is 200. Command used:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --headless

I compared the response of the API GET /json/protocol for Chrome with headed and headless mode, but the response was the same. The library keeps on calling GET /json/protocol even though the response is valid and thus doesn't start the test.

To Reproduce Steps (or script) to reproduce the behavior in local:

  1. Start Chrome with command /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --headless on MacOS or on other OS with appropriate path.
  2. Add the WS URL of Chrome as the target in openBrowser() function.
  3. Run the test.
/* globals gauge*/
"use strict";
const path = require('path');
const { openBrowser, closeBrowser } = require('taiko');

beforeScenario(async() => {
    await openBrowser({
      target: "ws://127.0.0.1:9222/devtools/browser/acc40aca-0c93-44f9-aed8-8410aa9f645c"
    });
});

afterScenario(async (context) => {
  await closeBrowser();
});

Expected behavior The test should launch and get executed.

Versions:

gauge -v
Gauge version: 1.4.3
Commit Hash: f98dd40

Plugins
-------
html-report (4.1.2)
js (2.3.17)
screenshot (0.1.0)

Additional context I am trying to launch the browser with the provided CLI args and then pass the WS URL in the target. I add previously raised this PR: https://github.com/getgauge/taiko/pull/2380 to add support of running taiko tests on remote machines. The above code I have added is to reproduce the scenario in local. It works as expected with headed mode on all chrome versions. Its giving the above issue for chrome and edge >=110. When I tried setting TAIKO_BROWSER_PATH=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome start the test with the below openBrowser() function:

await openBrowser({
      headless: true
})

the test works as expected. Although, I am not being able to check the CLI args passed by taiko in this case as chrome://version isn't allowed in headless mode.

ankur-lt commented 1 year ago

The following WS message is received from browser in case of headless browser, which thus leads to a retry.

"{\"id\":1,\"result\":{\"targetInfos\":[]}}"
ankur-lt commented 1 year ago

@zabil , @saikrishna321 , can you check this?

ankur-lt commented 1 year ago

The first CDP command send to browser is:

{"id":1,"method":"Target.getTargets","params":{}}

Shouldn't we first create target using {"method":"Target.createTarget","params":{"url":"about:blank"},"id":5}, the way Puppeteer does it and then send the Target.getTargets message?

Although, as per I checked, the targets are already created for Chrome <110 without having to explicitly create targets.

NivedhaSenthil commented 1 year ago

Yes taiko tries to use the existing tab, may be the behaviour is changed now with the latest version of the browser. We will have to revisit this.