This file contains hidden or 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
import java.util.Optional; | |
import java.util.function.Function; | |
import java.util.function.Supplier; | |
public class RetryUtil { | |
private static final int TRY_MULTIPLE_TIMES_DEFAULT_SLEEP = 100; | |
public static class Backoff { |
This file contains hidden or 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 Point convertWebviewLocationToTouchCoordinates(WebElement webViewElement) { | |
//Find the center point of element on webview | |
Point webviewLocation = webViewElement.getLocation(); | |
Dimension size = webViewElement.getSize(); | |
int elementWebviewCenterX = webviewLocation.getX() + Math.round(size.getWidth() / 2); | |
int elementWebviewCenterY = webviewLocation.getY() + Math.round(size.getHeight() / 2); | |
System.out.println("Element WebView Location: ( " + elementWebviewCenterX + ", " + elementWebviewCenterY + ")"); |
This file contains hidden or 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 final class RuntimeAnnotations { | |
private static final Constructor<?> AnnotationInvocationHandler_constructor; | |
private static final Constructor<?> AnnotationData_constructor; | |
private static final Method Class_annotationData; | |
private static final Field Class_classRedefinedCount; | |
private static final Field AnnotationData_annotations; | |
private static final Field AnnotationData_declaredAnotations; | |
private static final Method Atomic_casAnnotationData; | |
private static final Class<?> Atomic_class; |
This file contains hidden or 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
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import java.util.concurrent.*; | |
/** | |
* Created by hehuan on 10/08/2016. | |
* | |
* This class uses a single thread to execute the task assigned to it and wait for the result. |
This file contains hidden or 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
private static void moveToElementJs(WebDriver driver, WebElement element) { | |
String javaScript = "var evObj = document.createEvent('MouseEvents');" + | |
"evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" + | |
"arguments[0].dispatchEvent(evObj);"; | |
((JavascriptExecutor)driver).executeScript(javaScript, element); | |
} |
This file contains hidden or 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
/** | |
* This method is a replacement to the inViewPort method from selenium webdriver API. | |
* It uses javascript to scroll. | |
* For parameter details, check the link below: | |
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView">Element.scrollIntoView()</a> | |
*/ | |
public void inViewPort(boolean alignToTop, WebElement element) { | |
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(" + alignToTop + ")", element); | |
} |
This file contains hidden or 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
// Running towards BrowserStack using remote webdriver | |
// decorator class on top of basic capability builder classes from different browsers | |
public class BrowserStackRemoteWebDriverCapabilityBuilder extends CapabilityConfigurator.CapabilityBuilderDecorator { | |
public BrowserStackRemoteWebDriverCapabilityBuilder(CapabilityConfigurator.CapabilityBuilder builder) { | |
super(builder); | |
} | |
@Override | |
public void buildDesiredCapabilities() { |
This file contains hidden or 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 void highlight(WebElement element, long highlightInterval) throws InterruptedException { | |
int flexibleWait = 5; | |
long pollingInterval = 500; | |
WebDriverWait wait = new WebDriverWait(ngDriver, flexibleWait); | |
wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS); | |
wait.until(ExpectedConditions.visibilityOf(element)); | |
executeScript("arguments[0].style.border='3px solid yellow'", element); | |
Thread.sleep(highlightInterval); | |
//executeScript("arguments[0].style.border=''", element); | |
} |
This file contains hidden or 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 static ExpectedCondition<Boolean> angularHasFinishedProcessing() { | |
return new ExpectedCondition<Boolean>() { | |
@Override | |
public Boolean apply(WebDriver driver) { | |
String returnValue = ((JavascriptExecutor) driver).executeScript( | |
"return (window.angular !== undefined) && (angular.element(document).injector() !== undefined) && " + | |
"(angular.element(document).injector().get('$http').pendingRequests.length === 0)").toString(); | |
return Boolean.valueOf(returnValue); | |
} |