Skip to content

Commit

Permalink
Update capability handling with 'appium:' prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
martingrossmann committed Jun 11, 2024
1 parent 19cf733 commit 7a0e5cf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package eu.tsystems.mms.tic.testframework.appium;

/**
* Created on 2024-06-11
*
* The Appium client convert all Appium specific capabilities and adds the prefix 'appium:'.
* This should help to read a capability.
*/
public interface AppiumCapabilityHelper {

default String getAppiumCap(final String capabilityName) {
return "appium:" + capabilityName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package eu.tsystems.mms.tic.testframework.mobile.driver;

import eu.tsystems.mms.tic.testframework.appium.AppiumCapabilityHelper;
import eu.tsystems.mms.tic.testframework.appium.Browsers;
import eu.tsystems.mms.tic.testframework.common.Testerra;
import eu.tsystems.mms.tic.testframework.report.model.context.SessionContext;
Expand All @@ -39,24 +40,24 @@
*
* @author mgn
*/
public class MobileOsChecker {
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(MobileCapabilityType.AUTOMATION_NAME))
|| "UiAutomator2".equals(capabilities.getCapability(MobileCapabilityType.AUTOMATION_NAME))
|| "UiAutomator".equals(capabilities.getCapability(MobileCapabilityType.AUTOMATION_NAME))
|| capabilities.getCapability(AndroidMobileCapabilityType.APP_PACKAGE) != null
|| capabilities.getCapability(AndroidMobileCapabilityType.APP_ACTIVITY) != null
|| "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
) {
return Platform.ANDROID;
}
if (webDriverRequest.getBrowser().equals(Browsers.mobile_safari)
|| "XCUITest".equals(capabilities.getCapability(MobileCapabilityType.AUTOMATION_NAME))
|| "UIAutomation".equals(capabilities.getCapability(MobileCapabilityType.AUTOMATION_NAME))
|| capabilities.getCapability(IOSMobileCapabilityType.BUNDLE_ID) != null
|| "XCUITest".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME)))
|| "UIAutomation".equals(capabilities.getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME)))
|| capabilities.getCapability(getAppiumCap(IOSMobileCapabilityType.BUNDLE_ID)) != null
) {
return Platform.IOS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package eu.tsystems.mms.tic.testframework.webdrivermanager;

import eu.tsystems.mms.tic.testframework.appium.AppiumCapabilityHelper;
import eu.tsystems.mms.tic.testframework.appium.Browsers;
import eu.tsystems.mms.tic.testframework.utils.AppiumProperties;
import io.appium.java_client.remote.MobileCapabilityType;
Expand All @@ -30,7 +31,7 @@
import java.net.URL;
import java.util.Optional;

public class AppiumDriverRequest extends SeleniumWebDriverRequest {
public class AppiumDriverRequest extends SeleniumWebDriverRequest implements AppiumCapabilityHelper {

public static final String DEVICE_QUERY = "deviceQuery";
public static final String ACCESS_KEY = "accessKey";
Expand Down Expand Up @@ -72,30 +73,30 @@ public void setAppiumEngine(String engine) {
}

public String getAppiumEngine() {
return this.getMutableCapabilities().getCapability(MobileCapabilityType.AUTOMATION_NAME).toString();
return this.getMutableCapabilities().getCapability(getAppiumCap(MobileCapabilityType.AUTOMATION_NAME)).toString();
}

public void setDeviceName(String deviceName) {
this.getMutableCapabilities().setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
}

public String getDeviceName() {
return this.getMutableCapabilities().getCapability(MobileCapabilityType.DEVICE_NAME).toString();
return this.getMutableCapabilities().getCapability(getAppiumCap(MobileCapabilityType.DEVICE_NAME)).toString();
}

public void setPlatformVersion(String platformVersion) {
this.getMutableCapabilities().setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
}

public String getPlatformVersion() {
return this.getMutableCapabilities().getCapability(MobileCapabilityType.PLATFORM_VERSION).toString();
return this.getMutableCapabilities().getCapability(getAppiumCap(MobileCapabilityType.PLATFORM_VERSION)).toString();
}

public void setDeviceId(String id) {
this.getMutableCapabilities().setCapability(MobileCapabilityType.UDID, id);
}

public String getDeviceId() {
return this.getMutableCapabilities().getCapability(MobileCapabilityType.UDID).toString();
return this.getMutableCapabilities().getCapability(getAppiumCap(MobileCapabilityType.UDID)).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void testT03_startRequestSession() {
final String device = "Apple iPhone X";
request.setBrowser(Browsers.mobile_safari);
request.setDeviceQuery(String.format("contains(@name, '%s')", device));
request.getMutableCapabilities().setCapability("appium:appiumVersion", "2.2.2");
request.getMutableCapabilities().setCapability("appiumVersion", "2.2.2");

final WebDriver driver = WEB_DRIVER_MANAGER.getWebDriver(request);

Expand Down
2 changes: 1 addition & 1 deletion appium/src/test/resources/test.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#tt.browser=mobile_chrome
tt.browser=mobile_chrome
#tt.browser=mobile_safari

#tt.baseurl=https://the-internet.herokuapp.com/
Expand Down

0 comments on commit 7a0e5cf

Please sign in to comment.