0

I have a test scenario where the web application checks for the user's leave intent i.e., mouse hovering from the page to the browser close and then a frame gets triggered. Is there any way to do it?

Edit: So the dev implementation is that when the user is moving to the top of the document frame gets triggered and it is not browser close but moving to corner of the document.

0

The browser close button cannot be hovered with WebDriver. You could try to close the current window with driver.close() and see if the close is blocked and the message is shown.

I would sit with the developers and see how you can make this testable as simple as possible. For example by implementing window.onbeforeunload to prevent the window from closing without confirmation, which is testable by using driver.close().

  • I do not think he wants to close the browser, what he is asking for is a way to check if user wants to close the browser/tab by pressing the "X" button and if so, display some pop up. – Moro Oct 21 at 10:04
  • @Moro Agreed, I answered that with AutoIt and SikuliX, but I think the implementation of detecting that "wants" of a user is hard and even harder to test. So let the user click on the close button and just cancel the close in the onbeforeunload, which is default browser behaviour and thus cross-platform. I dont think we should blindly follow requirements, but suggest better implementations that are testable and future proof. – Niels van Reijmersdal Oct 21 at 10:34
  • @niels I just edited and added some more context. – Adithya Ram Oct 21 at 10:45
  • @AdithyaRam Added a link to move the mouse to a position. That is really weird behaviour you are describing. Certainly does not fit my mental model of how websites should behave. – Niels van Reijmersdal Oct 21 at 10:48
  • @niels I have used the following code Actions actions = new Actions(driver); actions.moveToElement(element).click() .moveByOffset(10,25).click() .keyUp(Keys.CONTROL).build().perform(); where element is top most element in the page . But it didnot work even though i changed the offset values – Adithya Ram Oct 21 at 11:45
0

I did it using Sikuli:

//imports
import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;

//Code Snippets
Screen s = new Screen();
Pattern browserCloseButton = new Pattern(filepath + "CloseButton.PNG");

WebDriver driver = new ChromeDriver();
driver.get(<url>);

s.hover(browserCloseButton);

For more reference read up:
https://www.guru99.com/sikuli-tutorial.html
http://doc.sikuli.org/region.html

0

Ok, so apparently what you need to do is capture some WebElement on top of the page and then move mouse by offset using Actions class. Using Java it would be something like this:

    WebElement topElement = driver.findElement(By.SOME_SELECTOR);
    Actions action=new Actions(driver);
    action.moveToElement(topElement).moveByOffset(0, -100).perform();

It does not have to be "-100" just enough to move outside the viewport and trigger the desired frame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.