Created
July 28, 2018 08:51
-
-
Save virenv/6a24b4fb882e47540d148c4581e6e5ea to your computer and use it in GitHub Desktop.
A small change to apply retry when a pop up appears
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ElementProxy implements InvocationHandler { | |
private final WebElement element; | |
public ElementProxy(WebElement element) { | |
this.element = element; | |
} | |
@Override | |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | |
for(int i = 0; i < 10 /*limit that can be set programatically*/ ; i++) | |
{ | |
try | |
{ | |
//before invoking actual method check for the popup | |
this.checkForPopupAndKill(); | |
//at this point, popup would have been closed if it had appeared. element action can be called safely now. | |
return method.invoke(element, args); | |
} | |
catch(exception exp) | |
{ | |
// Just remain in the loop | |
} | |
} | |
} | |
private void checkForPopupAndKill() { | |
if (popup.isDisplayed()) { | |
System.out.println("You damn popup, you appearded again!!?? I am gonna kill you now!!"); | |
popup.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment