Run tests with logs capturing
Below you can find information on how to run tests with automatic system or appium logs capturing
Prerequisites
- Existing native application with the Biometric authentication.
- The app is installed on a device.
- The tests are using Appium framework.
- Access key is generated.
Step 1: Add capability to the Appium session configuration
We have the specific capabilities for enable of the automatic log(s) capturing during an Appium test session.
You can use both of them simultaneously or individually.
Below you can find an example for the Java Appium lib.
System log:
private BaseOptions<? extends MutableCapabilities> generateOptionsForDevice(String platformName,String deviceSerial) {
BaseOptions<? extends MutableCapabilities> options = platformName.equalsIgnoreCase(MobilePlatform.ANDROID) ?
new UiAutomator2Options() : new XCUITestOptions();
options.setCapability("udid", udid);
options.setCapability("mobitru:collectDeviceLogs", true);
...
return options;
}
Appium log:
private BaseOptions<? extends MutableCapabilities> generateOptionsForDevice(String platformName,String deviceSerial) {
BaseOptions<? extends MutableCapabilities> options = platformName.equalsIgnoreCase(MobilePlatform.ANDROID) ?
new UiAutomator2Options() : new XCUITestOptions();
options.setCapability("udid", udid);
options.setCapability("mobitru:collectAppiumLogs", true);
...
return options;
}
Step 2: Run tests and store an Appium session ID
The Mobitru will start the logs capturing immediately after initiating a new Appium session.
However, you need to store the Appium session ID in order to download logs after finish of the tests execution.
Below you can find an example for the Java Appium lib.
public void startDriver(BaseOptions<? extends MutableCapabilities> options) {
url = new URL(format("https://%s:%s@app.mobitru.com/wd/hub", "<BILLING_UNIT>", "<ACCESS_KEY>"));
driver = new AppiumDriver(url, options)
String sessionId = driver.getSessionId().toString();
...
}
Step 3: Download logs after finish of the execution
You can download captured logs after finish of the tests execution.
In Mobitru we have specific APIs for that and you can find all details here.
Important note: once Appium session is finished it could take some time to prepare the log file for downloading.
Below you can find an example for a popular Java API framework:
public String downloadDeviceLog(String appiumSessionId) {
return RestAssured.
given().
baseUri("https://app.mobitru.com/billing/unit/"+
<TEAM_ACCOUNT_NAME>
+"/automation/api").
auth().oauth2(<ACCESS_KEY>).
when().
get("appium/{id}/device-log", appiumSessionId).
then().
statusCode(HTTP_OK).
extract().
body().asString();
}
public String downloadAppiumLog(String appiumSessionId) {
return RestAssured.
given().
baseUri("https://app.mobitru.com/billing/unit/"+
<TEAM_ACCOUNT_NAME>
+"/automation/api").
auth().oauth2(<ACCESS_KEY>).
when().
get("appium/{id}/appium-log", appiumSessionId).
then().
statusCode(HTTP_OK).
extract().
body().asString();
}