getgauge / taiko

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

Error The Browser instance was closed #1604

Closed Alenechka closed 3 years ago

Alenechka commented 3 years ago

Describe the bug In the end of every test run of single scenario or full spec I am facing the issue: Error: The Browser instance was closed either via closeBrowser() call, or it exited for reasons unknown to Taiko. You can try launching a fresh instance using openBrowser() or inspect the logs for details of the possible crash. So I am not able to get any report even if test is passed.

To Reproduce

  1. Run any spec or scenario using gauge( via VS code plugin or by terminl command gauge run --env default) For example my steps implementation consists of
beforeSuite(async () => {
        await openBrowser({
    beforeunload(async () => await accept())
});

afterSuite(async () => {
    await closeBrowser();
});

step("Click <text>", async (text) => {
    await click(text, { exactMatch: true });
});

step("Navigate to page <url>", async (url) => {
    await goto(url);
});

And spec is:

# for test

test

## test

* Navigate to page "https://www.google.com/"
* Click "Почта"

Logs

Error: The Browser instance was closed either via `closeBrowser()` call, or it exited for reasons unknown to Taiko. You can try launching a fresh instance using `openBrowser()` or inspect the logs for details of the possible crash.
at errorMessageForBrowserProcessCrash (gauge\node_modules\taiko\lib\browserLauncher.js:298:11)
at ChildProcess.browserExitEventHandler (gauge\node_modules\taiko\lib\browserLauncher.js:312:49)
at Object.onceWrapper (events.js:422:26)
at ChildProcess.emit (events.js:315:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Error ----------------------------------

[Gauge]
js runner quit unexpectedly. Check logs for more details.
ErrorMessage: transport is closing

Get Support ----------------------------
    Docs:          https://docs.gauge.org
    Bugs:          https://github.com/getgauge/gauge/issues
    Chat:          https://spectrum.chat/gauge

Your Environment Information -----------
    windows, 1.1.4, c982558
    html-report (4.0.12), java (0.7.10), js (2.3.13), screenshot (0.0.1), spectacle (0.1.4), xml-report (0.2.3)
Error: Tests failed.

Expected behavior Test passed or failed but report is generated sucessfully.

Versions:

 - Gauge version: v1.1.4
 - Taiko v1.0.23 using Chrome(not Chromium)
 - OS Windows(run from terminal or VisualCode plugin)
 - Node.js v12.18.4
While running on ubuntu same versions of everything, there is no such error.

output of "gauge -v": 

Gauge version: 1.1.4
Commit Hash: c982558

Plugins
-------
html-report (4.0.12)
java (0.7.10)
js (2.3.13)
screenshot (0.0.1)
spectacle (0.1.4)
xml-report (0.2.3)

Additional context What I have tried: runner_connection_timeout = 25000 runner_request_timeout = 25000 waitFor(5000) in the last step waitFor(5000) in afterSuite setTimeout(5000) in afterSuite

Only WA that helps is for example add waitFor without declaration(so i am having am error in afterSuite section in logs and report but everything else works fine). But it's a hack! I am not able to run my test without errors and with a report in the same time.

I am pretty new to gauge and taiko and first 2-3 weeks everything worked fine both on my windows laptop and linux VM, but now this issue reproduces avary time I run my tests locally.

Please assist with this issue.

NivedhaSenthil commented 3 years ago

can you please verify if closeBrowser() called else where in your tests ?

Alenechka commented 3 years ago

Yes, using VScode search just in one place in

afterSuite(async () => {
    await closeBrowser();
});
Alenechka commented 3 years ago

Any updates on this issue?

zabil commented 3 years ago

It's passing for me with the sample provided on this issue

Screenshot 2020-10-21 at 16 06 28

I noticed that you mentioned that you are using Chrome instead of the Chromium that is bundled with Taiko. While it should work there may be issues with versions. Please check if the tests pass with the version of Chromium that comes bundled with Taiko.

Alenechka commented 3 years ago

The same issue with Chromium. But when I set headless_chrome = true everything works perfectly fine even with Chrome. That's why I don't have this issue on my linux VM I guess. My Chrome version is 86.0.4240.75.

zabil commented 3 years ago

Ok, things are different in headless mode and non headless mode.

Screenshot 2020-10-21 at 16 27 29

Google pops up an additional modal window in headless mode and this is not accounted for in the tests. The only way to get around this is handling this condition in the test as the site behaves differently. You could pass an environment variable to add additional checks.

Screenshot 2020-10-21 at 16 28 35
Alenechka commented 3 years ago

I dont have this modal window on my browser, see screenshot in debug mode: image But on your first screenshot in last comment I see initial issue with closed browser even after failed test. I am having the same error after passed and failed tests, for example see screenshot: image

zabil commented 3 years ago

Thanks for sharing the screenshots

The The Browser instance was closed either via closeBrowser() error is because something else failed in this case "Element with text fake not found".

Taiko should have reported this correctly without saying it was a problem with closeBrowser. Will check why that is happening and try to fix that.

Alenechka commented 3 years ago

Thanks a lot, @zabil ! Will wait for the update.

NivedhaSenthil commented 3 years ago

@Alenechka seems the issue does not exists with latest versions of node, gauge, taiko and gauge-js. Can you please verify again updating the versions ?

PS: I have created a PR that addresses closeBrowser warning if browser is closed already instead of erring #1664

Alenechka commented 3 years ago

@NivedhaSenthil Could you please specify versions that you used? I still have this problem on

node v15.1.0

Gauge version: 1.1.5
Commit Hash: f455126

Plugins
-------
html-report (4.0.12)
java (0.7.10)
js (2.3.14)
screenshot (0.0.1)
spectacle (0.1.4)
xml-report (0.2.3)

taiko 1.0.26
NivedhaSenthil commented 3 years ago

I am on

Gauge version: 1.1.5
Commit Hash: f455126

Plugins
-------
html-report (4.0.12)
java (0.7.13)
js (2.3.13)
screenshot (0.0.1)

taiko 1.0.26
node v14.15.0

Can you please attach the sample project that you are running...I did try replicating from above comments but no luck

Alenechka commented 3 years ago

There is part of my project which you can run to reproduce issue. Also I didn't delete logs so you can see that I am able to reproduce this issue every time.

taiko_issue.zip

NivedhaSenthil commented 3 years ago

Thanks for the sample.. I could now replicate it with a simple taiko script below. Seems to be happening because of waiting for beforeUnload event to happen, only on headful mode and in windows. Trying to debug the cause.

(async () => { 
    try {
        await openBrowser({headless:false});
        await beforeunload(async () => await accept());
        await goto("google.com");
    } catch (error) {
        console.error(error);
    } finally {
        await closeBrowser();
    }
})();
NivedhaSenthil commented 3 years ago

After some debugging found that this is happening because of a difference in behavior in Chromium...page.close which is done in closeBrowser closes only the page in other platforms and in windows headless mode. But in headful mode in windows the browser itself is being closed if it is the last page in the browser. Have filled an upstream issue https://bugs.chromium.org/p/chromium/issues/detail?id=1147809, meanwhile will look at handling it in a better way in Taiko.

PS: gauge-js should have not been terminated because of unhandled exception in user code, will take that up as a separate issue