diff --git a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/guielement/CreateAppiumGuiElementAction.java b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/guielement/CreateAppiumGuiElementAction.java index 86a8e37..078b26c 100644 --- a/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/guielement/CreateAppiumGuiElementAction.java +++ b/appium/src/main/java/eu/tsystems/mms/tic/testframework/mobile/guielement/CreateAppiumGuiElementAction.java @@ -33,6 +33,8 @@ import eu.tsystems.mms.tic.testframework.testing.UiElementFinderFactoryProvider; import eu.tsystems.mms.tic.testframework.webdrivermanager.IWebDriverManager; import eu.tsystems.mms.tic.testframework.webdrivermanager.WebDriverRequest; +import io.appium.java_client.android.options.UiAutomator2Options; +import io.appium.java_client.ios.options.XCUITestOptions; import io.appium.java_client.pagefactory.DefaultElementByBuilder; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.By; @@ -82,13 +84,11 @@ protected void execute() { By mobileBy = byBuilder.buildBy(); try { - UiElementFinder uiElementFinder = UI_ELEMENT_FINDER_FACTORY.create(this.declaringPage.getWebDriver()); UiElement uiElement = uiElementFinder.find(mobileBy); if (uiElement instanceof NameableChild) { ((NameableChild) uiElement).setParent(this.declaringPage); } - field.set(this.declaringPage, uiElement); } catch (IllegalAccessException e) { throw new RuntimeException("Cannot create new " + mobilePlatform + " element", e); @@ -100,21 +100,20 @@ protected void after() { } private String getAutomationEngine(WebDriver driver, Platform platform) { - // TODO: Use platform specific options for iOS and Android --> automationName is part of it, see also AppiumDriverFactory - IWebDriverManager instance = Testerra.getInjector().getInstance(IWebDriverManager.class); Optional optional = instance.getSessionContext(driver).map(SessionContext::getWebDriverRequest); if (optional.isPresent()) { - Object automationEngine = optional.get().getCapabilities().getCapability(getAppiumCap("automationName")); + Object automationEngine = optional.get().getCapabilities().getCapability(getAppiumCap(APPIUM_AUTOMATION_NAME)); if (automationEngine != null && StringUtils.isNotBlank(automationEngine.toString())) { return automationEngine.toString(); } else { - // Use default values for automation engine + // Use default values for automation engine from option classes. + // getAutomationName() returns optional, but new created instances of options have always the correct value. switch (platform) { case ANDROID: - return "UiAutomator2"; + return new UiAutomator2Options().getAutomationName().get(); case IOS: - return "XCUITest"; + return new XCUITestOptions().getAutomationName().get(); default: throw new RuntimeException("Cannot get automation engine: Invalid platform " + platform); }