lefthandedgoat / canopy

f# web automation and testing library, built on top of Selenium (friendly to c# also)
http://lefthandedgoat.github.io/canopy/
MIT License
505 stars 117 forks source link

Closing tabs lead to errors even after switching tabs #485

Closed Pwntheon closed 4 years ago

Pwntheon commented 4 years ago

I click a link that opens in a new tab - do some testing in that tab, then switch back and close the newly opened tab.

When the testing continues in the original tab, i get the following error:

target window already closedfrom unknown errorweb view not found(Session infochrome=77.0.3865.120) ved OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) ved OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) ved OpenQA.Selenium.Remote.RemoteWebDriver.set_Url(String value) ved OpenQA.Selenium.Remote.RemoteNavigator.GoToUrl(String url) ved canopy.parallell.functions.url@984.Invoke(IWebDriver browser) ved canopy.classic.op_BangHat(String u)

Pwntheon commented 4 years ago

It seems that if i just switch back to the original tab, the testing proceeds as expected. It is only when i close the second tab that errors start occuring.

Here is an example test:

"Kartverket link works as expected" &&&& fun _ ->
        GetPseudoElementContent KartverketLink ":after" === Icons.ExternalLink
        click KartverketLink
        switchToTab 2
        on expectedKartverketUrl
        switchToTab 1
        AssertOnPath (Pages.Eiendom + EiendomIDs.StorEiendom)
        closeTab 2
lefthandedgoat commented 4 years ago

Sorry, for some reason I don't get all new issues as email notifications. Just noticed this. I am working on something else but I suspect if you closeTab 2 prior to switchToTab 1 it will work. If this does not work please let me know and I will reproduce this and give you better help.

"Kartverket link works as expected" &&&& fun _ ->
        GetPseudoElementContent KartverketLink ":after" === Icons.ExternalLink
        click KartverketLink
        switchToTab 2
        on expectedKartverketUrl
        closeTab 2
        switchToTab 1
        AssertOnPath (Pages.Eiendom + EiendomIDs.StorEiendom)
Pwntheon commented 4 years ago

I tried doing it in both orders: Closing tab 2 before or after switching back to 1 (and without switching)

Doing it in the order you suggested gives this error:

target window already closedfrom unknown errorweb view not found(Session infochrome=77.0.3865.120) ved OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) ved OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) ved OpenQA.Selenium.Remote.RemoteWebDriver.get_Url() ved canopy.parallell.functions.on(String u, IWebDriver browser) ved canopy.classic.on(String u) ved Common.Helpers.AssertOnPath(String path) i C:\code\gui-testing\MinSideGuiTesting\MinSideGuiTesting\Common\Helpers.fs:linje 115 ved GuiTests.Services.Eiendom.LinkTests.Run@16-49.Invoke(Unit _arg1) i C:\code\gui-testing\MinSideGuiTesting\MinSideGuiTesting\GuiTests\Services\Eiendom\LinkTests.fs:linje 23 ved canopy.runner.classic.tryTest[a,b](a test, b suite, FSharpFunc2 func)

lefthandedgoat commented 4 years ago

Ok I will dig into it

Pwntheon commented 4 years ago

I tried making a simple, isolated test now and somehow this works fine

    "Test new tab" &&&& fun _ ->
        url "https://stackoverflow.com"
        click "Cookie Policy"
        switchToTab 2
        displayed "Stack Exchange, Inc. Cookie Policy"
        closeTab 2
        switchToTab 1
        on "https://stackoverflow.com"
        displayed "For developers, by developers"

I'm not sure why it fails in our test and not this simple one. I will look more into it.

This test still fails with the close\switch swapped though

Pwntheon commented 4 years ago

It must have been something else causing the issue, because as i played some more with it, this now works.

Sorry for wasting your time.

It still feels unintuitive that the order has to be this way though. It makes little sense to switch to tab 1 when you only have 1 tab open after closing tab 2.

lefthandedgoat commented 4 years ago

No problem!