diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/MobileOsChecker.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/MobileOsChecker.java index e407109..d1a90d2 100644 --- a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/MobileOsChecker.java +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/driver/MobileOsChecker.java @@ -43,25 +43,12 @@ public class MobileOsChecker implements AppiumCapabilityHelper { public Platform getPlatform(WebDriverRequest webDriverRequest) { - Capabilities capabilities = webDriverRequest.getCapabilities(); - - if (webDriverRequest.getBrowser().equals(Browsers.mobile_chrome) - || "Espresso".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) - || "UiAutomator2".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) - || "UiAutomator".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) - || capabilities.getCapability(getAppiumCap(AndroidMobileCapabilityType.APP_PACKAGE)) != null - || capabilities.getCapability(getAppiumCap(AndroidMobileCapabilityType.APP_ACTIVITY)) != null - ) { + if (Browsers.mobile_chrome.equals(webDriverRequest.getBrowser()) || isAppTest(webDriverRequest, Platform.ANDROID)) { return Platform.ANDROID; } - if (webDriverRequest.getBrowser().equals(Browsers.mobile_safari) - || "XCUITest".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) - || "UIAutomation".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) - || capabilities.getCapability(getAppiumCap(IOSMobileCapabilityType.BUNDLE_ID)) != null - ) { + if (Browsers.mobile_safari.equals(webDriverRequest.getBrowser()) || isAppTest(webDriverRequest, Platform.IOS)) { return Platform.IOS; } - return Platform.ANY; } @@ -75,4 +62,23 @@ public Platform getPlatform(WebDriver driver) { } } + // Returns true if WebDriverRequest contains typical app capabilities + public boolean isAppTest(WebDriverRequest webDriverRequest, Platform platform) { + Capabilities capabilities = webDriverRequest.getCapabilities(); + switch (platform) { + case ANDROID: + return "Espresso".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) + || "UiAutomator2".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) + || "UiAutomator".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) + || capabilities.getCapability(getAppiumCap(AndroidMobileCapabilityType.APP_PACKAGE)) != null + || capabilities.getCapability(getAppiumCap(AndroidMobileCapabilityType.APP_ACTIVITY)) != null; + case IOS: + return "XCUITest".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) + || "UIAutomation".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME))) + || capabilities.getCapability(getAppiumCap(IOSMobileCapabilityType.BUNDLE_ID)) != null; + default: + return false; + } + } + } diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/guielement/AppiumUiElementHighlighter.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/guielement/AppiumUiElementHighlighter.java index 1aadac6..eb2481b 100644 --- a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/guielement/AppiumUiElementHighlighter.java +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/guielement/AppiumUiElementHighlighter.java @@ -21,9 +21,10 @@ package eu.tsystems.mms.tic.testframework.mobile.guielement; import eu.tsystems.mms.tic.testframework.common.Testerra; +import eu.tsystems.mms.tic.testframework.mobile.driver.MobileOsChecker; import eu.tsystems.mms.tic.testframework.pageobjects.DefaultUiElementHighlighter; import eu.tsystems.mms.tic.testframework.report.utils.IExecutionContextController; -import org.apache.commons.lang3.StringUtils; +import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -41,8 +42,9 @@ public void highlight(WebDriver driver, WebElement webElement, Color color) { IExecutionContextController instance = Testerra.getInjector().getInstance(IExecutionContextController.class); instance.getCurrentSessionContext().ifPresent(sessionContext -> { // Highlighting is only working in browsers but not in apps - String browser = sessionContext.getWebDriverRequest().getBrowser(); - if (StringUtils.isNotEmpty(browser)) { + MobileOsChecker mobileOsChecker = new MobileOsChecker(); + Platform platform = mobileOsChecker.getPlatform(driver); + if (!mobileOsChecker.isAppTest(sessionContext.getWebDriverRequest(), platform)) { super.highlight(driver, webElement, color); } });