I'm testing a web page with Canopy that has a popup window. Does anyone know if there is a way with Canopy to close the popup window?
Otherwise I guess it's a case of dipping into Selenium to handle this?
I'm testing a web page with Canopy that has a popup window. Does anyone know if there is a way with Canopy to close the popup window?
Otherwise I guess it's a case of dipping into Selenium to handle this?
This is not too difficult. The basic algorithm is:
In code:
let origWindow = browser.CurrentWindowHandle
// do something to open another window
// make the new window the focus of tests
let newWindow = browser.WindowHandles |> Seq.find (fun w -> w <> origWindow )
browser.SwitchTo().Window(newWindow) |> ignore
// optionally do asserts on the contents of the new window
// close the new window
browser.Close()
// switch back to the original window
browser.SwitchTo().Window(origWindow) |> ignore
Assuming this is something you might want to do more than once, you could refactor to the following library functions:
let switchToWindow window =
browser.SwitchTo().Window(window) |> ignore
let getOtherWindow currentWindow =
browser.WindowHandles |> Seq.find (fun w -> w <> currentWindow)
let switchToOtherWindow currentWindow =
switchToWindow (getOtherWindow currentWindow) |> ignore
let closeOtherWindow currentWindow =
switchToOtherWindow currentWindow
browser.Close()
The original example could be rewritten:
let origWindow = browser.CurrentWindowHandle
// do something to open another window
// make the new window the focus of tests
switchToOtherWindow origWindow
// optionally do asserts on the contents of the new window
// close the new window
closeOtherWindow origWindow
// switch back to the original window
switchToWindow origWindow