Lambda Hooks For Appium Automation
This document will help you provide lambdahooks which can be used to improve your test scripts to easily debug your test cases for App Automation on Real Devices on LambdaTest Cloud.
Adding custom status & remark
To add custom status & remark, just add the code snippet using the JavascriptExecutor
.
JavascriptExecutor
accepts two arguments as shown below:
Arguments | Example |
---|---|
status | failed OR passed |
remark | Any remark can be added here limited to 255 characters. |
((JavascriptExecutor) driver).executeScript("lambda-hook: {\"action\": \"setTestStatus\",\"arguments\": {\"status\":\"failed\", \"remark\":\"This is a sample remark for failed test \"}} ");
Here is a sample automation script in Java for the sample status & remark. Ensure to update the app_url
, username
& accesskey
in the below code.
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.MalformedURLException;
import java.net.URL;
public class vanilla_android {
private static AppiumDriver driver;
public static void main(String args[]) throws MalformedURLException, InterruptedException {
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Galaxy S20");
capabilities.setCapability("platformVersion", "11");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("isRealMobile", true);
capabilities.setCapability("app", "APP_ID"); //Enter your app url
capabilities.setCapability("build", "Java Vanilla - Android");
capabilities.setCapability("name", "Sample Test Java");
//Enter your Username & Accesskey here:
driver = new AppiumDriver(new URL("https://" +userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), capabilities);
MobileElement color = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color"));
color.click();
//Javascript Executor for marking the status and custom remark.
((JavascriptExecutor) driver).executeScript("lambda-hook: {\"action\": \"setTestStatus\",\"arguments\": {\"status\":\"failed\", \"remark\":\"This is a sample remark for failed test \"}} ");
}
// The driver.quit statement is required, otherwise the test continues to execute, leading to a timeout.
driver.quit();
}
}
Once you have added the code snippet, the status and remark will be visible on the LambdaTest App Automation Dashboard as shown below:
Update Test Name
To update the name of the test, just add the code snippet using the JavascriptExecutor
.
Arguments | Example |
---|---|
lambda-name | For changing the Test Name. |
((JavascriptExecutor) driver).executeScript("lambda-name=TestName");
Differentiating Test Cases in Single Session
LambdaTest has introduced a LambdaHook to help automation engineers differentiate between multiple test cases within a single Appium session. This feature aims to improve debugging capabilities, making it easier to identify which test cases may be causing errors or taking longer to execute.
Adding LambdaHooks
You can use LambdaHooks to start and end a test case within a single Appium session.
Test Case Start
To start a test case, use the lambda-testCase-start
hook:
// To start a test case
((JavascriptExecutor) driver).executeScript("lambda-testCase-start=find Name");
Test Case End
To end a test case, use the lambda-testCase-end
hook:
// To end a test case
((JavascriptExecutor) driver).executeScript("lambda-testCase-end=find Name");
Labeling and Filtering Command Logs
Any command logs executed between lambda-testCase-start
and lambda-testCase-end
will be labeled with the name you provide. The name should not exceed 255
characters.
You can also filter the command logs based on these labels.A screenshot has been provided below, demonstrating the use of labels and how to filter command logs based on them.