Integrate your Appium test suite with Jenkins and BrowserStack device cloud for testing native and hybrid apps using our Jenkins plugin.
Jenkins is an open-source Continuous Integration (CI) server, which automates the build and deploy process of your applications. By running your Appium test suite in Jenkins, you also automate testing as part of the build process. Add BrowserStack to the mix, and your apps can be tested across 2000+ real devices. BrowserStack allows you to integrate your Appium tests with Jenkins using a plugin that connects your Jenkins CI server to BrowserStack.
Use BrowserStack Jenkins plugin to:
You need the following set up before you begin
To run your Appium tests with Jenkins on BrowserStack, you will first need to download our Jenkins plugin. Before installing the plugin, ensure you have the necessary privileges to administer your Jenkins installation. We recommend doing this when there are no active build jobs running on Jenkins.
Choose BrowserStack from the list of available plugins.
Once you’ve installed the plugin, you will need to configure your BrowserStack credentials to complete the integration between Jenkins and your Appium tests. Follow these steps to configure BrowserStack inside Jenkins:
Enter your BrowserStack Username and Access Key which you can find on your BrowserStack Account Settings page.
Next, you will need to upload your app to BrowserStack servers and for that, you will need to configure the app upload build step. Follow these steps to configure a build step to upload your app to BrowserStack servers:
Select Upload App to BrowserStack
Enter the path to your app file on the local Jenkins server and click Save.
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. The BrowserStack Jenkins plugin is responsible for:
Under the Build Environment section check the box next to BrowserStack Local
Once you’ve integrated BrowserStack Local through the Jenkins plugin, you can test mobile apps that access resources hosted in development or testing environments during automated test execution.
The BrowserStack Jenkins plugin sets the following environment variables:
BROWSERSTACK_USERNAME
BROWSERSTACK_ACCESS_KEY
BROWSERSTACK_APP_ID
BROWSERSTACK_BUILD_NAME
BROWSERSTACK_LOCAL
BROWSERSTACK_LOCAL_IDENTIFIER
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 buildName = System.getenv("BROWSERSTACK_BUILD_NAME");
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("app", app);
caps.setCapability("device", "Samsung Galaxy S8");
caps.setCapability("build", buildName);
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
buildName = process.env.BROWSERSTACK_BUILD_NAME;
browserstackLocalIdentifier = process.env.BROWSERSTACK_LOCAL_IDENTIFIER
app = process.env.BROWSERSTACK_APP_ID
var capabilities = {
"browserstack.user" : userName,
"browserstack.key" : accessKey,
"app" : app,
"build" : buildName,
"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");
buildName = Environment.GetEnvironmentVariable("BROWSERSTACK_BUILD_NAME");
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("build", buildName);
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 = getenv("BROWSERSTACK_USERNAME")
$access_key = getenv("BROWSERSTACK_ACCESS_KEY")
$browserstack_local = getenv("BROWSERSTACK_LOCAL")
$buildName = getenv("BROWSERSTACK_BUILD_NAME")
$browserstack_local_identifier = getenv("BROWSERSTACK_LOCAL_IDENTIFIER")
$app = getenv("BROWSERSTACK_APP_ID")
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("app", app);
$capabilities->setCapability("device", 'Samsung Galaxy S8');
$capabilities->setCapability("build", buildName);
$capabilities->setCapability("browserstack.local", browserstack_local);
$capabilities->setCapability("browserstack.localIdentifier", browserstack_local_identifier);
$driver = RemoteWebDriver::create("https://"+user_name+":"+access_key+"@hub-cloud.browserstack.com/wd/hub", $capabilities);
user_name = os.getenv("BROWSERSTACK_USERNAME")
access_key = os.getenv("BROWSERSTACK_ACCESS_KEY")
browserstack_local = os.getenv("BROWSERSTACK_LOCAL")
build_name = os.getenv("BROWSERSTACK_BUILD_NAME")
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,
'build': build_name,
'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"]
build_name = ENV["BROWSERSTACK_BUILD_NAME"]
browserstack_local_identifier = ENV["BROWSERSTACK_LOCAL_IDENTIFIER"]
app = ENV["BROWSERSTACK_APP_ID"]
desired_caps = {
'app': app,
'device': 'Samsung Galaxy S8',
'build': build_name,
'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)
browserstack.local
and browserstack.localIdentifier
capabilities to test on your local development servers.
BrowserStack Jenkins plugin enables you to embed the test results from BrowserStack App Automate into Jenkins. It shows summary of the build, and a grid of all the sessions in any given build. The plugin helps you to debug faster by highlighting failed tests and linking tests to the App Automate dashboard.
BROWSERSTACK_BUILD_NAME
environment variable to set build name in your test code. If you don’t use BROWSERSTACK_BUILD_NAME
the plugin will not be able to embed reports in Jenkins. Refer Using Environment variables section on how to use environment variables.
Enabling reporting is a simple process and doesn’t require any code change, follow the below steps:
With this integration, you can now view the results of your Appium tests within Jenkins. You can know the summary of a build:
You can view the list of session of a build by clicking on View Full BrowserStack Report or by clicking on BrowserStack Test Report link in the sidebar.
Selecting any session from this table will take you to the App Automate dashboard where you can refer to video logs, text logs, screenshots, and other debugging options for a session.
By following the steps outlined in this guide, you should have a seamless integration between your existing automation in Jenkins, your Appium tests and BrowserStack device cloud. This will help you leverage all the benefits of test automation and the scale and coverage offered by BrowserStack
Contact our Support team for immediate help while we work on improving our docs.
Contact our Support team for immediate help while we work on improving our docs.