getgauge / taiko

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

The behavior of closeTab without parameters should be consistent in headless and non-headless modes. #175

Closed sswaroopgupta closed 5 years ago

sswaroopgupta commented 6 years ago

Expected behavior The behavior of closeTab without parameters should be consistent in headless and non-headless modes.

Actual behavior The tabs getting closed are different in both these cases

Steps to replicate

(async () => { try { await openBrowser({headless:false}); await goto("makemytrip.com/") await openTab("gauge.org/index.html") await closeTab() await closeTab() } catch (e) { console.error(e); } finally { closeBrowser(); } })();

> The output is 

[PASS] Browser opened [PASS] Navigated to url "http://makemytrip.com/" [PASS] Opened tab with url "http://gauge.org/index.html" [PASS] Closed tab with url "https://gauge.org/index.html" [PASS] Closed tab with url "https://www.makemytrip.com/" [PASS] Browser closed

Note: Makemytrip tab is getting closed

* Run the following script in headless mode

const { openBrowser, goto, inputField, into, write, toRightOf, comboBox, click, openTab,closeTab } = require('taiko');

(async () => { try { await openBrowser(); await goto("makemytrip.com/") await openTab("gauge.org/index.html") await closeTab() await closeTab() } catch (e) { console.error(e); } finally { closeBrowser(); } })();

> The output is

[PASS] Browser opened [PASS] Navigated to url "http://makemytrip.com/" [PASS] Opened tab with url "http://gauge.org/index.html" [PASS] Closed tab with url "https://gauge.org/index.html" [PASS] Closed tab with url "about:blank" [PASS] Browser closed

Note: The default "about:blank" is getting closed

**Version**

commit - 55e833232dc9d7c27b45db9801ca959639e62553



Blocks #157
Apoorva-GA commented 6 years ago

Note: This is because the order in which we connect to the next tab after closing the current tab is random for now and shouldn't be related to headless/headful mode.

Fix should be to connect to the previously opened tab, when the current tab is closed.

sswaroopgupta commented 6 years ago

Test case notes Close tab should retain order when application opens content in a separate tab. Not specified explicitly by the taiko script

const { openBrowser, goto, link, text, contains, click,
    openTab,closeTab } = require('taiko');

    (async () => {
        try {
            await openBrowser({headless:false});
            await goto("google.com",{timeout:20000});
            await openTab("https://www.thoughtworks.com/contact-us",{timeout:20000});
            await click(link("privacy policy",below(text(contains("I agree to share my information")))))
            await closeTab()
            await closeTab()
        } catch (e) {
            console.error(e);
        } finally {
            closeBrowser();
        }
     })();

Here the website opens the privacy policy in a separate tab. The script does not specify it explicitly.

sswaroopgupta commented 5 years ago

commit - 499249fb2a904ee4dc4eb83976d6d1905a3edd07 Mac it is working as expected. Windows it is having an issue

[PASS] Browser opened
[PASS] Navigated to url "http://google.com"
[PASS] Opened tab with url "https://www.thoughtworks.com/contact-us"
[PASS] Clicked link with text privacy policy  and Below Element with text "[object Object]"
[PASS] Closed tab with url "https://www.thoughtworks.com/privacy-policy"
[PASS] Closed tab with url "chrome://welcome-win10/"
[PASS] Browser closed
sriv commented 5 years ago

I can see this issue happen intermittently with https://github.com/getgauge/taiko/blob/5155b890d9e19d0573727cccf2830ecc45efcd36/examples/04-windows-tabs.js

I suspect that when launching chromium in headless mode, closing a tab does not always bring the previous tab back as active.

NivedhaSenthil commented 5 years ago

Seems to work fine after the fix for #589.

Debashis9012 commented 5 years ago

The below code has been testes with both headless and headful mode

const { openBrowser, goto, link, text, contains, click,
    openTab,closeTab } = require('taiko');

    (async () => {
        try {
            await openBrowser({headless:false});
            await goto("google.com",{timeout:20000});
            await openTab("https://www.thoughtworks.com/contact-us",{timeout:20000});
            await click(link("privacy policy",below(text(contains("I agree to share my information")))))
            await closeTab()
            await closeTab()
        } catch (e) {
            console.error(e);
        } finally {
            closeBrowser();
        }
     })();

Observation:

  1. close browser without parameter closes the tab with correct sequence .
  2. The behaviour of the close browser without any parameter are same in both headful and headless mode.
  3. This issue has been tested with both the os win and mac. The outputs are same. Based on the observations this issue has been verified and found fixed.

Commit version: 7493c6afa8565c8482f8f01ada43c32dd1185627