简体   繁体   English

处理应用程序中的常见弹出窗口Java WebDriver Testng

[英]Handling common pop ups across the application java webdriver testng

I have a common pop up in my application that is basically a prompt for "Unsaved Changes with "Yes" and "No" buttons". 我的应用程序中有一个常见的弹出窗口,基本上是提示“未保存的更改,带有”是”和”否”按钮的提示。

Problem is : I want to handle this from a common place in Automation Framework , I don want to handle this pop up in each and every test case. 问题是:我想从Automation Framework的一个普通地方处理这个问题,我不想处理每个测试用例中弹出的问题。 Is there a way so that I can write a custom listener which can trigger as soon as this pop up appear on UI. 有没有一种方法可以让我编写一个自定义侦听器,该侦听器会在此弹出窗口出现在UI上时立即触发。

If not what should be the best approach in a automation framework to handle such pop ups those are common across the Application and not very predictable where they will appear. 如果不是这样,那么在自动化框架中处理此类弹出窗口的最佳方法应该是什么,这些弹出窗口在整个应用程序中都很常见,并且很难预测它们的出现位置。

I am using java and TestNG along with WebDriver. 我正在使用Java和TestNG以及WebDriver。

Thanks. 谢谢。

Depending on what your popup would do you can register events with the following interface WebDriverEventListener referenced at http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/events/WebDriverEventListener.html 根据弹出窗口的显示方式,您可以使用以下interface WebDriverEventListener注册事件,该interface WebDriverEventListener位于http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/events/WebDriverEventListener.html

Personally I like the approach of directly handling this with a custom error handler and recursive function calls. 我个人喜欢使用自定义错误处理程序和递归函数调用直接处理此问题的方法。 It gives you more exact control...although it takes more programming to get it to work. 它可以为您提供更精确的控制...尽管需要更多的编程才能使其起作用。 Either way within your event/exception handling you can put your custom code to handle the popup with an driver.SwitchTo().Alert().accept() or driver.SwitchTo().Alert().dismiss() or custom code to interact with your custom popup elements. 在事件/异常处理中的任何一种方式中,都可以使用driver.SwitchTo().Alert().accept()driver.SwitchTo().Alert().dismiss()或自定义代码来放置自定义代码来处理弹出窗口与您的自定义弹出式元素进行交互。


That being said since you have two options in your popup you will want to ensure that you do have some tests that address this directly otherwise you won't be testing all cases. 话虽这么说,因为您的弹出窗口中有两个选项,所以您将要确保确实有一些可以直接解决此问题的测试,否则您将无法测试所有情况。 Maybe you could have a one line call to a function that handles the accept/reject of the popup and you just pass in a bool value whether it's accept or reject... 也许您可以对处理弹出窗口的接受/拒绝的函数进行一行调用,而您只是传递一个布尔值(无论它是接受还是拒绝)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM