Search⌘ K
AI Features

Create the BROWSER environment variable

Understand how to configure the BROWSER environment variable within Azure DevOps pipelines to specify the browser for Selenium tests. This lesson helps you update pipeline scripts to run automated tests by setting environment variables, committing changes, and analyzing test results in the pipeline dashboard.

Our pipeline only cleans the artifacts and compiles the code for now.

To run the tests, we need to provide the browser name as an environment variable so the driver can be created in the setUp() method of the test class:

Java
@BeforeMethod
public void setUp()
{
String browserName = System.getenv("BROWSER");
this.driver = DriverFactory.getDriver(browserName);
}

Add the environment variable

The environment variable is added to the pipeline code with a Bash task:

YAML
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: export BROWSER='chrome'
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'clean test'

Lines 8–11 create the Bash task that sets the BROWSER environment variable with the chrome ...