Integrate BrowserStack App-Automate with Azure Pipelines
Integrate your Appium test suite with Azure Pipeline AKA Visual Studio Team Services (VSTS) and BrowserStack device cloud using our Azure Pipelines extension.
Azure Pipelines is a continuous integration tool used to integrate your test suites. It enables continuous testing, build, and deployment of iterative code changes. CI/CD tools help catch failures ahead of the production stage and mitigate them as they occur.
The information in this section applies to using the BrowserStack plugin with Azure Pipelines as part of the Azure DevOps Services (cloud) offering only.
In this guide, you’ll learn how to:
- Install the BrowserStack Azure DevOps Extension
- Configure the App Uploader
- Configuring BrowserStack Local
- Generating test reports
Prerequisites
Before you can start integration, ensure that:
- You’ve hosted your project on any of these source repositories supported by Azure.
- You are a maintainer or owner of the project.
- You are an administrator of your Azure DevOps organization.
- You’ve created a pipeline for the project’s repository. If you are yet to create a pipeline, check out how to create an Azure Pipeline.
- You have access to the BrowserStack account credentials, namely Access Key and Username.
Install the BrowserStack Azure DevOps Extension
The BrowserStack Azure DevOps Extension eases the process of configuring Azure Pipelines to run tests on BrowserStack. To install the extension follow these steps:
- In the Visual Studio Marketplace, click Azure DevOps.
- Search for BrowserStack Azure DevOps Extension.
- In the BrowserStack Azure DevOps Extension page, click Get it Free.
- The Sign in page opens to sign in to your Azure account. After you sign-in, click Select an Azure DevOps organization and select your organization.
- Click Install to add the extension.
BrowserStack’s extension is now installed in your Azure DevOps organization. This installs the BrowserStack Config
, BrowserStackResults
, and BrowserStackStopLocal
tasks to the list of available tasks for you to use them in your pipeline.
Configure BrowserStack in Azure Pipelines
For your tests to run on BrowserStack, the Azure Pipeline needs additional information, such as BrowserStack credentials.
You can create a pipeline using either a YAML editor or a classic editor. Depending on the editor you used to create the pipeline, refer to the steps in the following tabs to integrate BrowserStack in your pipeline.
-
Open the Azure portal page and click My Azure DevOps Organizations.
-
In the Azure DevOps Organizations page, click the project where you’ve created a pipeline for your project’s repostory from the list of projects that appear.
-
Click Project settings located at the bottom-left corner of your project’s page.
-
In the Project details page, click Service connections > Create service connection.
-
In the New service connection section, select BrowserStack from the given list, and click Next.
-
In the New BrowserStack service connection section, enter your BrowserStack Username in the Username field, and then enter Access key in the AccessKey field.
-
Click Verify to verify your BrowserStack credentials.
-
After verification succeeds, enter a service connection name in the Service connection name field, such as
browserstack-connection
, and then click Verify and save. The service connection gets added and you’re redirected to the Service connections page. -
Click the (Pipelines) icon.
-
In the Pipelines page, select your pipeline.
-
Click Edit to edit the pipeline.
-
In the pipeline editor, from the Tasks pane, search for the BrowserStack Config task, and then select it.
-
In the BrowserStack Config section, select the connection, created in Step 8, from BrowserStack service end point
-
Click Add.
-
In the pipeline editor, from the Tasks pane, search for the BrowserStack Results task, and then select it.
-
In the BrowserStack Results section, enter
automate
in the Enter the product in use field, and then click Add.
The following image shows the azure-pipelines.yml
file with all the BrowserStack tasks configured to run your test on BrowserStack.
Note: Ensure to set the build
capability in your test script using the environment variable BROWSERSTACK_BUILD_NAME
. The extension will fail to embed test reports in your pipeline if this capability is missing. Check out Edit your test script to call environment variables to learn more.
-
Open the Azure portal page and click My Azure DevOps Organizations.
-
In the Azure DevOps Organizations page, select the project from the given list.
-
In the project’s page, click the Pipelines option.
-
In the Pipelines page, click to select your pipeline.
-
In the pipeline’s page, click Edit to edit your pipeline.
-
In the Tasks tab, click the Add (+) icon next to the Agent Job 1 card.
-
In the Add tasks pane, select the BrowserStack Config task from the tasks list, and click Add.
-
Click the BrowserStack configuration setup card and click + New.
-
Create a new service connection using the following steps in the New service connection screen:
a. Enter your BrowserStack Username.
b. Enter your BrowserStack Access key.
c. Click Verify.
d. After verification succeeds, enter a name for service connection.
e. Click Verify and save.
-
In the Tasks tab, click + on the Agent job 1 card to add the BrowserStack Results task.
-
In the Add tasks panel, from the tasks list, select the BrowserStack Results task and click Add.
-
Click the BrowserStack Results card and enter
automate
in the Enter the product in use field. -
Click Save & queue and select Save to save the changes.
The following image shows all the BrowserStack tasks configured in the pipeline to run your test on BrowserStack.
Note: Ensure to set the build
capability in your test script using the environment variable BROWSERSTACK_BUILD_NAME
. The extension will fail to embed test reports in your pipeline if this capability is missing. Check out Edit your test script to call environment variables to learn more.
Your build pipeline is successfully configured to connect with the BrowserStack cloud for your project.
Configuring App Uploader
BrowserStack Azure Pipelines extension allows you to upload your app to the BrowserStack servers.
Select the BrowserStack App Uploader task from the right task pane in the YAML edit window. This will set the BROWSERSTACK_APP_ID environment variable with the App Id returned as a response after the app upload.
If you would like to set a custom identifier for your uploaded app, set the ‘App custom id’ value. In this case the BROWSERSTACK_APP_ID environment variable will be set to the custom id you provided. Custom Id is optional.
Follow the below steps to upload app from your local machine to the BrowserStack servers.
-
Select BrowserStack App Uploader and update the App path to point the app location on your local machine. This will set the
BROWSERSTACK_APP_ID
environment variable with the App Id returned as a response after the app upload. -
If you would like to set a custom identifier for your uploaded app, set the ‘App custom id’ value. In this case the
BROWSERSTACK_APP_ID
environment variable will be set to the custom id you provided. Custom Id is optional.
Configuring BrowserStack Local
BrowserStack Local Testing allows you to test apps that retrieve data from servers on your local machine, CI/CD machines/nodes, and other private network configurations.
Starting BrowserStack Local
To enable BrowserStack Local follow these steps:
-
Under BrowserStack configuration step, click on the checkmark next to BrowserStackLocal.
-
Use BrowserStack Local Options to set any additional configuration options when running the binary.
For example to enable verbose logging and to force local, in the BrowserStack Local Options, pass:
{"verbose": true, "forceLocal": true}
The full list of options available in local testing modifiers.
Please use camel case in local modifier options, for example, use
logFile
instead of--log-file
Stopping BrowserStack Local
Please note that stopping BrowserStack Local is only required if you enabled Local in the above step.
To stop BrowserStack Local follow these steps:
-
Select Agent job 1 and click on the + icon. Type browserstack in the search box.
-
Hover on BrowserStack Stop Local and click on the Add button.
- This task will stop the BrowserStack Local.
- Stop Local should only be called after the script which runs the test cases.
Run Tests
The BrowserStack Azure Pipelines extension sets the following environment variables:
BROWSERSTACK_USERNAME
BROWSERSTACK_ACCESS_KEY
BROWSERSTACK_LOCAL
BROWSERSTACK_LOCAL_IDENTIFIER
BROWSERSTACK_APP_ID
Use these environment variables to set the DesiredCapabilities in your tests. For example:
String userName = System.getenv("BROWSERSTACK_USERNAME");
String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY");
String browserstackLocal = System.getenv("BROWSERSTACK_LOCAL");
String browserstackLocalIdentifier = System.getenv("BROWSERSTACK_LOCAL_IDENTIFIER");
String app = System.getenv("BROWSERSTACK_APP_ID");
public static void main(String args[]) throws MalformedURLException, InterruptedException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("device", "Samsung Galaxy S8");
caps.setCapability("app", app);
caps.setCapability("browserstack.local", browserstackLocal);
caps.setCapability("browserstack.localIdentifier", browserstackLocalIdentifier);
}
driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub", caps);
userName = process.env.BROWSERSTACK_USERNAME
accessKey = process.env.BROWSERSTACK_ACCESS_KEY
browserstackLocal = process.env.BROWSERSTACK_LOCAL
browserstackLocalIdentifier = process.env.BROWSERSTACK_LOCAL_IDENTIFIER
app = process.env.BROWSERSTACK_APP_ID
var capabilities = {
"browserstack.user" : userName,
"browserstack.key" : accessKey,
"app" : app,
"device" : "Samsung Galaxy S8",
"browserstack.local" : browserstackLocal,
"browserstack.localIdentifier" : browserstackLocalIdentifier
}
driver = wd.promiseRemote("https://hub-cloud.browserstack.com/wd/hub");
driver
.init(capabilities)
//Write your code here
.fin(function() { return driver.quit(); })
.done();
userName = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
accessKey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
browserstackLocal = Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL");
browserstackLocalIdentifier = Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL_IDENTIFIER");
app = Environment.GetEnvironmentVariable("BROWSERSTACK_APP_ID");
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("browserstack.user", userName);
caps.SetCapability("browserstack.key", accessKey);
caps.SetCapability("app", app);
caps.SetCapability("device", "Samsung Galaxy S8");
caps.SetCapability("browserstack.local", browserstackLocal);
caps.SetCapability("browserstack.localIdentifier", browserstackLocalIdentifier);
AndroidDriver driver = new AndroidDriver(new Uri("https://hub-cloud.browserstack.com/wd/hub"), caps);
user_name = os.getenv("BROWSERSTACK_USERNAME")
access_key = os.getenv("BROWSERSTACK_ACCESS_KEY")
browserstack_local = os.getenv("BROWSERSTACK_LOCAL")
browserstack_local_identifier = os.getenv("BROWSERSTACK_LOCAL_IDENTIFIER")
app = os.getenv("BROWSERSTACK_APP_ID")
desired_cap = {
'browserstack.user': user_name,
'browserstack.key': access_key,
'device': 'Samsung Galaxy S8',
'app': app,
'browserstack.local': browserstack_local,
'browserstack.localIdentifier': browserstack_local_identifier
}
driver = webdriver.Remote("https://" + user_name + ":" + access_key + "@hub-cloud.browserstack.com/wd/hub", desired_cap)
user_name = os.getenv("BROWSERSTACK_USERNAME")
access_key = os.getenv("BROWSERSTACK_ACCESS_KEY")
browserstack_local = os.getenv("BROWSERSTACK_LOCAL")
browserstack_local_identifier = os.getenv("BROWSERSTACK_LOCAL_IDENTIFIER")
app = os.getenv("BROWSERSTACK_APP_ID")
desired_cap = {
'app': app,
'device': 'Samsung Galaxy S8',
'browserstack.local': browserstack_local,
'browserstack.localIdentifier': browserstack_local_identifier
}
driver = webdriver.Remote("https://"+user_name+":"+access_key+"@hub-cloud.browserstack.com/wd/hub", desired_cap)
user_name = ENV["BROWSERSTACK_USERNAME"]
access_key = ENV["BROWSERSTACK_ACCESS_KEY"]
browserstack_local = ENV["BROWSERSTACK_LOCAL"]
browserstack_local_identifier = ENV["BROWSERSTACK_LOCAL_IDENTIFIER"]
app = ENV["BROWSERSTACK_APP_ID"]
desired_caps = {
'device': 'Samsung Galaxy S8',
'app': app,
'browserstack.local': browserstack_local,
'browserstack.localIdentifier': browserstack_local_identifier
}
appium_driver = Appium::Driver.new({
'caps' => desired_caps,
'appium_lib' => {
:server_url => "https://#{user_name}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
}}, true)
Note: You must pass browserstack.local
and browserstack.localIdentifier
capabilities to test on your local development servers.
Generating test reports
The BrowserStack Azure Pipelines extension enables you to embed the test results from BrowserStack into Azure Pipelines. We currently support viewing test reports in Azure Pipelines with a select set of languages and frameworks, which are Java with JUnit/TestNG, and Node with Protractor and WebdriverIO. The sections below describe how to configure your project to generate BrowserStack test reports.
Java - TestNG and JUnit
Follow the below steps to generate test reports.
A prerequisite for embedding test reports is that the Java project must be built with Maven and use either TestNG or JUnit for testing.
To configure your project:
- Add the following dependencies to your
pom.xml
file:
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>automate-testassist</artifactId>
<version>1.1.0</version>
</dependency>
- Add the following repositories to your
pom.xml
file:
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</pluginRepository>
</pluginRepositories>
- Add the following plugins to your
pom.xml
file:
<build>
<plugins>
<plugin>
<groupId>com.browserstack</groupId>
<artifactId>automate-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<source>${jdk.source.version}</source>
<target>${jdk.target.version}</target>
<complianceLevel>${jdk.source.version}</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
You must define the Maven properties, jdk.source.version and jdk.target.version to match the Java versions of your project.
To configure WebdriverIO project, add wdio-browserstack-reporter
as a dependency in your package.json
file.
{
"dependencies": {
"wdio-browserstack-reporter": "~0.1.1"
}
Add browserstack
as a reporter in your conf
file.
// wdio.conf.js
module.exports = {
// ...
reporters: ['browserstack'],
reporterOptions: {
browserstack: {
outputDir: './'
}
},
// ...
};
outputDir(optional): Defines a directory location for storing browserstack report files. See the GitHub respository link for more details.
Embedding test reports
Once you have completed the above steps, you can configure your Azure Pipelines setup to embed all the BrowserStack Appium reports and logs.
-
Select Agent job 1 and click on the + icon. Type browserstack in the search box.
-
Hover on BrowserStack Results and click on the Add button. Click on Control Options and enable Continue on error.
With this integration, you can now view the results of your Appium tests within Azure Pipelines. This is how the test results look in Azure Pipelines:
Conclusion
By following the steps outlined in this guide, you should have a seamless integration between your existing automation in Azure Pipelines, your Appium tests and the BrowserStack Appium grid. This will help you leverage all the benefits of test automation and the scale and coverage offered by BrowserStack.
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!