Skip to main content

Test Observability on TestNG

Quick start guide to integrate BrowserStack Test Observability with TestNG

Pre-requisites

  • You have an account with BrowserStack (even a free trial works) and can get the Username and Access Key from your account profile.
  • You have a TestNG test suite which may be unit tests or functional tests (it’s 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 an 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 as 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 using Build Runs.

Visit Test Observability

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). Use one of the following methods 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 following 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 that 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 following 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 as 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 using Build Runs.

Visit Test Observability

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 java agent <argLine> in your <build> plugin. This step invokes the BrowserStack 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 following 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 as Test Observability will automatically identify different build runs.

BrowserStack SDK is a very powerful tool that 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 the TestNG Plugin.

View results and insights on Test Observability

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

Visit Test Observability

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 following 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 as Test Observability will automatically identify different build runs.

BrowserStack SDK is a very powerful tool that 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 these steps, you can 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 Test Observability for detailed insights and deep debugging capabilities.

Visit Test Observability

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. Use one of the following methods 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 following 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 using Build Runs.

Visit Test Observability

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 the BrowserStack 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 following 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 the TestNG Plugin.

View results and insights on Test Observability dashboards

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

Visit Test Observability

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 following 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 these steps, you can run your test suite using BrowserStack.

View results and insights on Test Observability

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

Visit Test Observability

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