Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/main/java/util/driver/MobileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Set;

public class MobileHelper {
private final static Logger LOG = LoggerFactory.getLogger(MobileHelper.class);
Expand Down Expand Up @@ -129,4 +130,40 @@ public static MobileElement clearField(AndroidDriver driver, MobileElement eleme

return element;
}

public static String getWebContextName(AppiumDriver driver) {
return getContext(driver, "WEB");
}

public static String getNativeContextName(AppiumDriver driver) {
return getContext(driver, "NATIVE");
}

private static String getContext(AppiumDriver driver, String context) {
String contextName = "";
Set contexts = driver.getContextHandles();

while (contexts.size() < 2) {
if (contexts.size() > 1) {
break;
} else {
try {
DriverHelper.wait(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
contexts = driver.getContextHandles();
}
}

for (Object c: contexts){
if (((String)c).contains(context)){
contextName = (String) c;
break;
}
}

return contextName;
}

}
42 changes: 31 additions & 11 deletions src/main/java/util/general/SystemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,55 @@
import java.awt.*;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;

import static environment.EnvironmentFactory.*;
import static util.validator.Constants.TARGET_AUTOMOTION_JSON;

public class SystemHelper {

public final static String[] iOS_RETINA_DEVICES = {
"iPhone 4", "iPhone 4s",
"iPhone 5", "iPhone 5s",
"iPhone 6", "iPhone 6s",
"iPad Mini 2",
"iPad Mini 4",
"iPad Air 2",
"iPad Pro"
};

/**
* Verify is display is retina
*
* @return
*/
public static boolean isRetinaDisplay() {
boolean isRetina = false;
try {
GraphicsDevice graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

if (isMobile()) {
if (isIOS()) {
if (Arrays.asList(iOS_RETINA_DEVICES).contains(getDevice())) {
isRetina = true;
}
}
} else {
try {
Field field = graphicsDevice.getClass().getDeclaredField("scale");
if (field != null) {
field.setAccessible(true);
Object scale = field.get(graphicsDevice);
if (scale instanceof Integer && (Integer) scale == 2) {
isRetina = true;
GraphicsDevice graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

try {
Field field = graphicsDevice.getClass().getDeclaredField("scale");
if (field != null) {
field.setAccessible(true);
Object scale = field.get(graphicsDevice);
if (scale instanceof Integer && (Integer) scale == 2) {
isRetina = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return isRetina;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/util/validator/ResponsiveUIValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static util.validator.ResponsiveUIValidator.Units.PX;

public class ResponsiveUIValidator {

static final int MIN_OFFSET = -10000;
private final static Logger LOG = Logger.getLogger(ResponsiveUIValidator.class);
protected static WebDriver driver;
Expand Down