Skip to content

Commit

Permalink
Fix AppiumUiElementHighlighter and added app check
Browse files Browse the repository at this point in the history
  • Loading branch information
martingrossmann committed Jun 11, 2024
1 parent 759104e commit 43e26d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
});
Expand Down

0 comments on commit 43e26d6

Please sign in to comment.