Skip to main content

Test Observability on TestNG

Quick start guide to integrate BrowserStack Test Observability with TestNG

Test Observability is currently in private-alpha. If you do not yet have access to the product, you can reach out to us requesting early access.

Pre-requisites

  • You have an account with BrowserStack (even free trial works) and cen get the username and access key from Settings.
  • You have a TestNG test suite which may be unit tests or functional tests (its okay even if you do not run your tests on BrowserStack infrastructure)

Integrate with Test Observability

You can use BrowserStack Test Observability both when you’re using BrowserStack’s devices and browsers to run your functional end-to-end tests and also if you’re running tests locally on your laptop/CI system or even when you’re using some other cloud provider.

Not only that, Test Observability is agnostic to the type of testing and hence you could also integrate it with your unit or integration test suite written using TestNG.

Please select your setup below to get started with awesome debugging experience with Test Observability:

Verify your pom.xml entries

Since, you’re an existing browserstack-java-sdk user, you must already have the following entry in your pom.xml file of your project. Please verify that the following exists:

pom.xml
Copy icon Copy snippet

Install the latest SDK version

The previous step outlines that your pom.xml must have the LATEST tag against the browserstack-java-sdk. Now, run the below command to ensure that the latest version is installed:

Terminal
Copy icon Copy snippet

Verify your browserStack.yml config file

Since you’re an existing browserstack-java-sdk user, you must already be having a browserstack.yml config file at the root level of your project.

Test Observability mandatorily needs the following four configurations in the file. You need not change anything but you have to ensure that the values of the buildName and projectName variables are not changing across different build runs.

browserstack.yml
Copy icon Copy snippet

The projectName and buildName config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack Automate or App Automate since Test Observability will automatically identify different build runs.

Run your test suite with Test Observability

Run the following command from the project’s root directory to run your test suite with BrowserStack.

Copy icon Copy snippet

Post build run completion, you will see the build URL of Test Observability. Alternatively, you can also navigate to your build run through the Test Observability dashboard.

Visit Test Observability Dashboard

To start using BrowserStack Test Observability with your existing setup of TestNG tests running on BrowserStack Automate or App Automate, you’d need to integrate with the browserstack-java-sdk (if not already done). Follow one of the methods below to integrate the SDK and start using Test Observability:

If you’re an existing browserstack-java-sdk user, you can skip the steps below. All you’d need to ensure is that you’ve specified static names (names should not change across build runs) for projectName and buildName in the browserstack.yml file in your project.

Set BrowserStack credentials

Saving your BrowserStack credentials as environment variables makes it easier to run your test suite from your local or CI environment.

Copy icon Copy snippet
Copy icon Copy snippet

Install BrowserStack SDK using Maven Archetype

Maven Archetype provides a template to quickly configure your project. Copy & run the below command on your terminal/command prompt to add browserstack-java-sdk dependency in your pom.xml and browserstack.yml config file in your project.

Copy icon Copy snippet
Copy icon Copy snippet

Make changes in your browserstack.yml config file

Once you have installed the SDK, a browserstack.yml config file will be created at the root level of your project. This file holds all the required capabilities to run tests on BrowserStack.

BrowserStack SDK is a very powerful tool which you can use to set the different browser/device combinations and parallelization. For more details, check out the Automate Integration guide.

Make sure you copy the contents of the below config file and set it in your project’s browserstack.yml file:

browserstack.yml
Copy icon Copy snippet

The projectName and buildName config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack Automate or App Automate since Test Observability will automatically identify different build runs.

Run your test suite with Test Observability

Run the following command from the project’s root directory to run your test suite with BrowserStack.

Copy icon Copy snippet

Post build run completion, you will see the build URL of Test Observability. Alternatively, you can also navigate to your build run through the Test Observability dashboard.

Visit Test Observability Dashboard

Set BrowserStack credentials as environment variables

Saving your BrowserStack credentials as environment variables makes it easier to run your test suite from your local or CI environment.

Copy icon Copy snippet
Copy icon Copy snippet

Add BrowserStack SDK dependency in pom.xml

Add browserstack-java-sdk as a maven dependency in your pom.xml file. Refresh the project.

pom.xml
Copy icon Copy snippet

Modify your build plugins

Add the following build plugin

Add maven-dependency-plugin as a plugin under your <build> plugin to resolve dependencies.

Add BrowserStack SDK as an argline property

Add the following java agent <argLine> in your <build> plugin. This step invokes our SDK when your build is triggered.

-javaagent:${com.browserstack:browserstack-java-sdk:jar}

pom.xml
Copy icon Copy snippet

Create browserstack.yml file

Create browserstack.yml file in the root folder of your test suite and add the below code to it.

browserstack.yml
Copy icon Copy snippet

The projectName and buildName config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack Automate or App Automate since Test Observability will automatically identify different build runs.

BrowserStack SDK is a very powerful tool which you can use to set the different browser/device combinations and parallelization. For more details, check out the Automate Integration guide.

Run your test suite

Right-click your pom.xml file and click Run AsMaven Test:
Eclipse IDE Configuration

Facing issues with TestNG Plugin?

If you encounter the following error, use these steps to resolve the issue: TestNG Runner Error

  1. Get .m2 repository path for browserstack-java-sdk jar .m2 repository path
  2. Pass the .m2 repository path in argline of maven-surefire-plugin in your pom.xml Modify argline
  3. Now you can run tests using TestNG Plugin

View results and insights on Test Observability dashboards

Post build completion or even during the build is running, visit the Test Observability dashboard for detailed insights and deep debugging capabilities.

Visit Test Observability Dashboard

Set BrowserStack credentials as environment variables

Saving your BrowserStack credentials as environment variables makes it easier to run your test suite from your local or CI environment.

Copy icon Copy snippet
Copy icon Copy snippet

Add BrowserStack SDK dependency in your pom.xml

Add browserstack-java-sdk as a maven dependency in your pom.xml file. Refresh the project.

pom.xml
Copy icon Copy snippet

Create browserstack.yml file

Create browserstack.yml file in the root folder of your test suite and add the adjacent code to it

browserstack.yml
Copy icon Copy snippet

The projectName and buildName config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack Automate or App Automate since Test Observability will automatically identify different build runs.

BrowserStack SDK is a very powerful tool which you can use to set the different browser/device combinations and parallelization. For more details, check out the Automate Integration guide.

Run your test suite with Test Observability

Get browserstack-java-sdk .m2 repository path

Search for the browserstack-java-sdk jar in External Libraries. Right-click the .jar file, select Copy Path/References, and then copy the absolute path:
Intellij IDEA Configuration

Example Paths:

Mac or Linux: /Users/User_Name/.m2/repository/com/browserstack/browserstack-java-sdk/1.0.9/browserstack-java-sdk-1.0.9.jar

Windows: C:\Users\User_Name\.m2\repository\com\browserstack\browserstack-java-sdk\1.0.9\browserstack-java-sdk-1.0.9.jar

Add browserstack-java-sdk .m2 repository path in VM arguments

In your TestNG Runner file, click the run icon & select Modify Run Configurations:

Intellij IDEA Configuration

Add .m2 repo path from previous step in VM options field. Click Apply and then click OK:

Intellij IDEA Configuration

After successful completion of the above steps, you can now run your test suite using BrowserStack.

View results and insights on Test Observability dashboards

Post build completion or even during the build is running, visit the Test Observability dashboard for detailed insights and deep debugging capabilities.

Visit Test Observability Dashboard

To start using BrowserStack Test Observability with your existing setup of TestNG tests running on your local laptop or CI or even on any other cloud provider, you’d need to integrate the browserstack-java-sdk. Follow one of the methods below to integrate the SDK and start using Test Observability:

BrowserStack Test Observability works with any kind of automation tests. Use it with your unit or integration test suites and also your end-to-end functional test suite.

Set BrowserStack credentials

Saving your BrowserStack credentials as environment variables makes it easier to run your test suite from your local or CI environment.

Copy icon Copy snippet
Copy icon Copy snippet

Install BrowserStack SDK using Maven Archetype

Maven Archetype provides a template to quickly configure your project. Copy & run the below command on your terminal/command prompt to add browserstack-java-sdk dependency in your pom.xml and browserstack.yml config file in your project along with the required variables.

Copy icon Copy snippet
Copy icon Copy snippet

Make changes in your browserstack.yml config file

Once you have installed the SDK, a browserstack.yml config file will be created at the root level of your project. This file holds all the required capabilities to run tests on BrowserStack.

Make sure you copy the contents of the below config file and set it in your project’s browserstack.yml file:

browserstack.yml
Copy icon Copy snippet

The projectName and buildName config must be static and not change across different runs of the same build. Different runs of the same build/job would be automatically identified by Test Observability

Run your test suite with Test Observability

Run the following command from the project’s root directory to run your test suite with BrowserStack.

Copy icon Copy snippet

Post build run completion, you will see the build URL of Test Observability. Alternatively, you can also navigate to your build run through the Test Observability dashboard.

Visit Test Observability Dashboard

Set BrowserStack credentials as environment variables

Saving your BrowserStack credentials as environment variables makes it easier to run your test suite from your local or CI environment.

Copy icon Copy snippet
Copy icon Copy snippet

Add BrowserStack SDK dependency in pom.xml

Add browserstack-java-sdk as a maven dependency in your pom.xml file. Refresh the project.

pom.xml
Copy icon Copy snippet

Modify your build plugins

Add the following build plugin

Add maven-dependency-plugin as a plugin under your <build> plugin to resolve dependencies.

Add BrowserStack SDK as an argline property

Add the following java agent <argLine> in your <build> plugin. This step invokes our SDK when your build is triggered.

-javaagent:${com.browserstack:browserstack-java-sdk:jar}

pom.xml
Copy icon Copy snippet

Create browserstack.yml file

Create browserstack.yml file in the root folder of your test suite and add the below code to it.

browserstack.yml
Copy icon Copy snippet

The projectName and buildName config must be static and not change across different runs of the same build. Different runs of the same build/job would be automatically identified by Test Observability

Run your test suite

Right-click your pom.xml file and click Run AsMaven Test:
Eclipse IDE Configuration

Facing issues with TestNG Plugin?

If you encounter the following error, use these steps to resolve the issue: TestNG Runner Error

  1. Get .m2 repository path for browserstack-java-sdk jar .m2 repository path
  2. Pass the .m2 repository path in argline of maven-surefire-plugin in your pom.xml Modify argline
  3. Now you can run tests using TestNG Plugin

View results and insights on Test Observability dashboards

Post build completion or even during the build is running, visit the Test Observability dashboard for detailed insights and deep debugging capabilities.

Visit Test Observability Dashboard

Set BrowserStack credentials as environment variables

Saving your BrowserStack credentials as environment variables makes it easier to run your test suite from your local or CI environment.

Copy icon Copy snippet
Copy icon Copy snippet

Add BrowserStack SDK dependency in pom.xml

Add browserstack-java-sdk as a maven dependency in your pom.xml file. Refresh the project.

pom.xml
Copy icon Copy snippet

Create browserstack.yml file

Create browserstack.yml file in the root folder of your test suite and add the adjacent code to it.

browserstack.yml
Copy icon Copy snippet

The projectName and buildName config must be static and not change across different runs of the same build. Different runs of the same build/job would be automatically identified by Test Observability

Run your test suite with Test Observability

Get browserstack-java-sdk .m2 repository path

Search for the browserstack-java-sdk jar in External Libraries. Right-click the .jar file, select Copy Path/References, and then copy the absolute path:
Intellij IDEA Configuration

Example Paths:

Mac or Linux: /Users/User_Name/.m2/repository/com/browserstack/browserstack-java-sdk/1.0.9/browserstack-java-sdk-1.0.9.jar

Windows: C:\Users\User_Name\.m2\repository\com\browserstack\browserstack-java-sdk\1.0.9\browserstack-java-sdk-1.0.9.jar

Add browserstack-java-sdk .m2 repository path in VM arguments

In your TestNG Runner file, click the run icon & select Modify Run Configurations:

Intellij IDEA Configuration

Add .m2 repo path from previous step in VM options field. Click Apply and then click OK:

Intellij IDEA Configuration

After successful completion of the above steps, you can now run your test suite using BrowserStack.

View results and insights on Test Observability dashboards

Post build completion or even during the build is running, visit the Test Observability dashboard for detailed insights and deep debugging capabilities.

Visit Test Observability Dashboard

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

Is this page helping you?

Yes
No

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!

Talk to an Expert
Download Copy