Appium2 Environment Values
Environment values can be accessed in test code through the TestiniumEnvironment class.
import com.testinium.util.TestiniumEnvironment;Usage
After the driver is created, environment values can be accessed directly:
String sessionId = TestiniumEnvironment.sessionId;
String appiumVersion = TestiniumEnvironment.appiumVersion;
String udid = TestiniumEnvironment.udid;
String app = TestiniumEnvironment.app;
String hubUrl = TestiniumEnvironment.hubUrl;Android values
Use appPackage and appActivity in Android tests:
String appPackage = TestiniumEnvironment.appPackage;
String appActivity = TestiniumEnvironment.appActivity;Example:
if ("com.example.shopping".equals(TestiniumEnvironment.appPackage)) {
// Android application-specific test steps
}iOS value
Use bundleId in iOS tests:
String bundleId = TestiniumEnvironment.bundleId;Example
if ("com.example.shopping".equals(TestiniumEnvironment.bundleId)) {
// iOS application-specific test steps
}Platform check
The recommended way to check whether the platform is Android is:
if (TestiniumEnvironment.isPlatformAndroid()) {
// Android test steps
} else {
// Test steps for non-Android platforms
}The platform field can also be accessed directly. However, its value is read and assigned when isPlatformAndroid() is called:
TestiniumEnvironment.isPlatformAndroid();
String platform = TestiniumEnvironment.platform;Therefore, use isPlatformAndroid() directly when you only need to check the platform.
Other available values
String profile = TestiniumEnvironment.profile;
String takeScreenshot = TestiniumEnvironment.takeScreenshot;
String isSigned = TestiniumEnvironment.isSigned;
String uninstallApp = TestiniumEnvironment.uninstallApp;
String clearAppData = TestiniumEnvironment.clearAppData;All accessible fields:
Field | Description |
|---|---|
TestiniumEnvironment.profile | Active profile |
TestiniumEnvironment.platform | ANDROID or IOS |
TestiniumEnvironment.sessionId | Testinium session ID |
TestiniumEnvironment.appiumVersion | Appium version |
TestiniumEnvironment.udid | Device ID |
TestiniumEnvironment.app | Application path or reference |
TestiniumEnvironment.appPackage | Android application package |
TestiniumEnvironment.appActivity | Android launch activity |
TestiniumEnvironment.bundleId | iOS bundle ID |
TestiniumEnvironment.hubUrl | Appium hub URL |
TestiniumEnvironment.isSigned | Whether the iOS application is signed |
TestiniumEnvironment.uninstallApp | Whether the application should be uninstalled |
TestiniumEnvironment.clearAppData | Whether the application data should be cleared |
TestiniumEnvironment.takeScreenshot | Screenshot setting |
Important note
Environment values are loaded automatically when the driver is initialized. Therefore, access them after creating the driver:
AndroidDriver driver = new TestiniumAndroidDriver(url, capabilities);
String appPackage = TestiniumEnvironment.appPackage;
String udid = TestiniumEnvironment.udid;