Appium Testing On HyperExecute - WebApp
This page outlines how to execute your Appium tests on HyperExecute for WebApps using TestNG with YAML 0.2
HyperExecute uses YAML 0.2 to perform the tests using Appium.
Prerequisites
To run the Tests on HyperExecute from your Local System, you are required:
- Your lambdatest Username and Access key
- HyperExecute CLI in order to initiate a test execution Job .
- Setup the Environmental Variable
- Ensure you have Appium’s Java client library installed.
- HyperExecute YAML file which contains all the necessary instructions.
Download HyperExecute CLI
The HyperExecute CLI is used for triggering tests on HyperExecute. It is recommend to download the HyperExecute CLI binary on the host system to perform the tests on HyperExecute. The CLI download site for various platforms is displayed below:
Platform | HyperExecute CLI download location |
---|---|
Windows | https://downloads.lambdatest.com/hyperexecute/windows/hyperexecute.exe |
macOS | https://downloads.lambdatest.com/hyperexecute/darwin/hyperexecute |
Linux | https://downloads.lambdatest.com/hyperexecute/linux/hyperexecute |
Setup Environment Variable
Export the environment variables LT_USERNAME and LT_ACCESS_KEY that are available in the LambdaTest Profile page. Run the below mentioned commands in the terminal to setup the CLI and the environment variables.
- Linux / MacOS
- Windows
export LT_USERNAME="undefined"
export LT_ACCESS_KEY="undefined"
set LT_USERNAME="undefined"
set LT_ACCESS_KEY="undefined"
Steps to Run Your Test
Step 1: Write your Automation Script in the client language of your choice from the ones supported by Appium. An automation script for the sample applications have been provided below.
Here is a sample automation script in Java. Ensure to update the username
and accesskey
in the below code.
- Android Web App
- iOS Web App
package com.lambdatest;
import io.appium.java_client.MobileBy;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class androidWeb {
String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Enter the Username here
: System.getenv("LT_USERNAME");
String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Enter the Access key here
: System.getenv("LT_ACCESS_KEY");
public static RemoteWebDriver driver = null;
public String gridURL = "@mobile-hub.lambdatest.com/wd/hub";
public String status = "passed";
@Before
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build", "HYP Web RD Demo");
capabilities.setCapability("name", "Java Android Web Test");
capabilities.setCapability("platformName", "android");
capabilities.setCapability("deviceName", "Galaxy. *,OnePlus. *,Pixel. *"); //Enter the name of the device here
capabilities.setCapability("isRealMobile", true);
capabilities.setCapability("region", "eu");
// capabilities.setCapability("platformVersion","9");
capabilities.setCapability("deviceOrientation", "portrait");
capabilities.setCapability("console",true);
capabilities.setCapability("network",true);
capabilities.setCapability("visual",true);
try
{
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + gridURL), capabilities);
}
catch (MalformedURLException e)
{
System.out.println("Invalid grid URL");
} catch (Exception e)
{
System.out.println(e.getMessage());
}
}
@Test
public void testSimple() throws Exception
{
try
{
driver.get("https://lambdatest.github.io/sample-todo-app/");
driver.findElement(By.name("li1")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li2")).click();
System.out.println("Checking Box");
driver.findElement(By.name("li3")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li4")).click();
driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 6");
driver.findElement(By.id("addbutton")).click();
driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 7");
driver.findElement(By.id("addbutton")).click();
driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8");
driver.findElement(By.id("addbutton")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li1")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li3")).click();
status="passed";
}
catch (Exception e)
{
System.out.println(e.getMessage());
status="failed";
}
}
@After
public void tearDown() throws Exception
{
if (driver != null)
{
driver.executeScript("lambda-status=" + status);
driver.quit();
}
}
}
package com.lambdatest;
import io.appium.java_client.MobileBy;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class iosWeb {
String username = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Enter the Username here
: System.getenv("LT_USERNAME");
String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Enter the Access key here
: System.getenv("LT_ACCESS_KEY");
public static RemoteWebDriver driver = null;
public String gridURL = "@hub.lambdatest.com/wd/hub";
public String status = "passed";
@Before
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build", "HYP Web RD Demo");
capabilities.setCapability("name", "Java JUnit iOS Web Test");
capabilities.setCapability("platformName", "ios");
capabilities.setCapability("deviceName", "iPhone.*");
capabilities.setCapability("isRealMobile", true);
// capabilities.setCapability("platformVersion","14");
capabilities.setCapability("deviceOrientation", "portrait");
capabilities.setCapability("console",true);
capabilities.setCapability("network",true);
capabilities.setCapability("visual",true);
try
{
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + gridURL), capabilities);
}
catch (MalformedURLException e)
{
System.out.println("Invalid grid URL");
} catch (Exception e)
{
System.out.println(e.getMessage());
}
}
@Test
public void testSimple() throws Exception
{
try
{
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
driver.get("https://lambdatest.github.io/sample-todo-app/");
driver.findElement(By.name("li1")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li2")).click();
System.out.println("Checking Box");
driver.findElement(By.name("li3")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li4")).click();
driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 6");
driver.findElement(By.id("addbutton")).click();
driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 7");
driver.findElement(By.id("addbutton")).click();
driver.findElement(By.id("sampletodotext")).sendKeys(" List Item 8");
driver.findElement(By.id("addbutton")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li1")).click();
System.out.println("Checking Another Box");
driver.findElement(By.name("li3")).click();
status="passed";
}
catch (Exception e)
{
System.out.println(e.getMessage());
status="failed";
}
}
@After
public void tearDown() throws Exception
{
if (driver != null)
{
driver.executeScript("lambda-status=" + status);
driver.quit();
}
}
}
Step 2: Execute Your Test Case. Debug and run your code.
Once you have run your tests, you can view the test execution along with logs. You will be able to see the test cases passing or failing. You can view the same at LambdaTest Automation.
Sample YAML 0.2
version: "0.1"
runson: win
autosplit: true
concurrency: 2
testDiscovery:
command: cat tests.txt
mode: static
type: raw
testRunnerCommand: mvn test -P $test
framework:
name: appium
The
region
parameter specifies the region or location where the Appium tests will be executed. Our platform supports the following three regions:
- ap (Asia-Pacific)
- us (United States)
- eu (European Union)
More About Desired Capabilities
Sample Capabilities for both android and iOS web app mentioned below -
- Android
- iOS
{
"deviceName": "Galaxy Tab S4",
"platformName": "android",
"platformVersion": "10",
"visual": True,
"console": True,
"deviceOrientation": "PORTRAIT",
"build": "new-12",
"isRealMobile": True,
}
{
"deviceName": "iPhone 12 Mini",
"platformName": "ios",
"platformVersion": "14",
"isRealMobile": True,
"visual": True,
"console": True,
"build": "lt-web-4",
"network": True,
}
Refer to the Automation Capabilities Generator to understand more about it.
Navigation in Automation Dashboard
Every test run on the HyperExecute has a unique jobId associated with it. Each jobId can in turn constitute single (or multiple) groupId(s). You can visit HyperExecute automation dashboard for checking the status of the test execution.
The snapshot below shows how to navigate to the respective testID for viewing the Selenium logs:
Conclusion
By following the instructions in this documentation, you can seamlessly execute the Appium tests on HyperExecute for WebApps, leveraging its secure cloud infrastructure, advanced features, and optimized test execution workflow.