android.AndroidElementHelper Maven / Gradle / Ivy
package android;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
/**
* Created by Ismail on 6/4/2018.
*/
public class AndroidElementHelper {
/*************** Class Variables Section ***************/
// This variable to save old AndroidElement border color
private static String elementOldBorderColor = "white";
// This variable to save old AndroidElement border width
private static String elementOldBorderWidth = "1px";
// This variable to save old AndroidElement border style
private static String elementOldBorderStyle = "solid";
/*************** Class Methods Section ***************/
// This method to color AndroidElement with red border to set focus when start action
protected static void coloringAndroidElement(AndroidDriver androidDriver, AndroidElement androidElement) {
try {
// Save current AndroidElement border style
elementOldBorderColor = androidElement.getCssValue("border-bottom-color");
elementOldBorderWidth = androidElement.getCssValue("border-width");
elementOldBorderStyle = androidElement.getCssValue("border-style");
// Highlight the AndroidElement with red border
androidDriver.executeScript("arguments[0].setAttribute('style','border: solid 2px red');", androidElement);
} catch (Throwable throwable) {
// Do nothing
}
}
// This method to remove AndroidElement color when applied while starting action after finish the action
protected static void removeColoringAndroidElement(AndroidDriver androidDriver, AndroidElement androidElement) {
try {
// Check if element isn't null
if (androidElement != null && androidDriver != null)
// Remove red border color
androidDriver.executeScript("arguments[0].setAttribute('style','border: " + elementOldBorderWidth + " " + elementOldBorderStyle + " " + elementOldBorderColor + "');", androidElement);
} catch (Throwable throwable) {
// Do nothing
}
}
}