JUnit-XML based Appium report
Using the terminal, you can create JUnit-XML based reports from Appium with Java and upload them to Test Management.
Executing a Test Case with Appium
You can initiate an Appium project with this git repository. Use this sample code to execute a Test Case.
package appium_bee;
import org.testng.annotations.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement ;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
// WORKING WITH LOCAL ENVIRONMENT FOR APP AUTOMATE
public class baseClass {
AndroidDriver driver;
@BeforeTest
public void setup() throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities() ;
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.0");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Device_B");
capabilities.setCapability(MobileCapabilityType.APP, "/Users/bhavyakarimikonda/git/./../WikipediaSample.apk" );
capabilities.setCapability("newCommandTimeout", 2000);
URL url = new URL("http://localhost:4723/wd/hub");
driver = new AndroidDriver(url, capabilities);
Thread.sleep(10000);
}
@Test
public void launchApp() {
WebElement searchSelector = driver.findElement(By.id("org.wikipedia.alpha:id/search_container"));
searchSelector.click();
}
@Test
public void searchBStack() throws InterruptedException {
WebElement searchSelector = driver.findElement(By.id("org.wikipedia.alpha:id/search_container"));
searchSelector.click();
Thread.sleep(200);
WebElement insertTextSelector = driver.findElement(By.id("org.wikipedia.alpha:id/search_src_text"));
insertTextSelector.sendKeys("BrowserStack");
Thread.sleep(1000);
List<WebElement> allProductsName = driver.findElements(By.className("android.widget.TextView"));
Assert.assertTrue(allProductsName.size() > 0);
}
@AfterTest
public void teardown(){
driver.quit();
}
}
Create JUnit-XML test report with Appium
test-output
folder.
Sample JUnit-XML report generated from Appium in the test-output
folder.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by org.testng.reporters.JUnitReportReporter -->
<testsuite hostname="<hostname>.local" failures="0" tests="2" name="appiumproject.baseClass" time="4.899" errors="0" timestamp="2023-06-29T19:12:38 IST" skipped="0">
<testcase classname="appiumproject.baseClass" name="testSearch" time="4.634"/>
<system-out/>
<testcase classname="appiumproject.baseClass" name="launchBrowser" time="0.265"/>
<system-out/>
</testsuite> <!-- appiumproject.baseClass -->
Steps to upload the JUnit-XML test report
Open the project directory in the Terminal and load the variables.
export TEST_MANAGEMENT_API_TOKEN="*************28a42"
export TEST_MANAGEMENT_PROJECT_NAME="<Project Name>"
export JUNIT_XML_FILE_PATH="<Report Path>"
export TEST_RUN_NAME="<Test Run Name"
TEST_MANAGEMENT_API_TOKEN
from the Active API Key section in the Settings of BrowserStack Test Management.
Upload the test report using curl
command.
curl -k -X POST https://test-management.browserstack.com/api/v1/import/results/xml/junit \
-u $TEST_MANAGEMENT_API_TOKEN \
-F project_name="$TEST_MANAGEMENT_PROJECT_NAME" \
-F "file_path=@$JUNIT_XML_FILE_PATH" \
-F test_run_name="$TEST_RUN_NAME"
cURL
command until you get the response back.
You can also upload JUnit-XML test report with Appium using CI/CD.
Access the test run report from the console generated URL
After your report is successfully uploaded, you see a message similar to the following in your terminal. This message also generates a URL with "url"
parameter that you can use to access your automated test run.
{"message":"File uploaded successfully.","url":"https://test-management.browserstack.com/projects/<project id>/test-runs/<test run id>","success":true}
View test run report in Test Management
- Log in to the BrowserStack Test Management dashboard.
- Select the relevant project that has the test report uploaded.
- Click Test Runs.
- Open the Test Run generated from automation test exectution.
- You will find all the test cases with their respective results here.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!