Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
martingrossmann committed Aug 1, 2024
1 parent 3e9a0de commit c87ad5d
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<WebDriverRequest> 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);
}
Expand Down

0 comments on commit c87ad5d

Please sign in to comment.