Integrate BrowserStack App Automate with Bitrise
Integrate your Appium test suite with Bitrise and BrowserStack device cloud for native and hybrid apps.
Introduction
Bitrise is a Continuous Integration and Continuous Delivery (CI/CD) platform with the main focus on Mobile App Development. It is a collection of tools and services to help you with the development and automation of your software projects. It enables continuous testing, building, and deployment of iterative code changes. The use of CI/CD tools helps catch failures ahead of the production stage and mitigate them as they occur.
In the guide, you’ll learn how to:
- Configure Bitrise Pipeline
- Upload the app to BrowserStack and run your tests
- Integrate Existing TestCase
- Integrate test cases for privately hosted websites
Prerequisites
- A Bitrise account.
- Owner or maintainer access to the source repository that you want to integrate with Bitrise.
- BrowserStack account credentials, access key and username.
Configure Bitrise Pipeline
To create a pipeline in Bitrise and integrate with BrowserStack:
- Login to your Bitrise CI account.
- Click Add new app > Web UI to create a new Bitrise workflow. If you have an existing Bitrise workflow then skip to here.
- On the Create New App page, select the privacy type as Private or Public in Set privacy of the App and click Next.
- Select one of the source code provider either GitHub, BitBucket, GitLab, or Other/Manual.
- Search and select the repository from which you want to configure your app and provide the repository access in Setup repository access.
- Optionally you can configure SSH key when you add an app to Bitrise. Check out the Bitrise docs for more information.
- Choose the Branch of your application codebase and click Next to configure the app.
- Enter the Module name and click Confirm.
- Click Click here to check it out! to configure and complete the build.
Upload the app to BrowserStack and run your tests
Upload your app from Bitrise CI server to BrowserStack App Automate server to view your test results on BrowserStack App Automate dashboard:
- In Btirise, click Edit Workflow and then select the Primary or Deploy workflow option as required.
-
Click the Env Vars tab, click Add new to add the
BROWSERSTACK_USERNAME
andBROWSERSTACK_ACCESS_KEY
environment variables, and assign your BrowerStack username and access key, to access the BrowserStack App Automate dashboard, and then click Save.You can get your BrowserStack credentials from the account settings link.
-
Add the script workflow to add shell commands and required scripts to upload the app to BrowserStack: step a: Click the + (Add) icon in the Workflows tab.
step b: Enter and add the Script workflow.
step c: Provide the CURL command to generateapp_url
. Theapp_url
is generated using$BITRISE_APK_PATH
. Theapp_url
is then used to export theBROWSERSTACK_APP_URL
environment variable. This variable is used as your test suite app capability, in the Script content.Note: Use
$BITRISE_APK_PATH
environment variable in the CURL command as the app file location to upload the expected app file on the BrowserStack App Automate server.$BITRISE_APK_PATH
environment variable is automatically generated when you set the app source repository and holds the app location.appURL=$(curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ -X POST "https://api-cloud.browserstack.com/app-automate/upload" \ -F "file=@$BITRISE_APK_PATH") temp=$(appURL:12) BROWSERSTACK_APP_URL=$(temp%??) export BROWSERSTACK_APP_URL
step d: Additionally, you can add more shell commands that are required to execute your automation suite and click Save. - Navigate to the workflow, click Start/schedule build, select a Workflow, Pipeline drop-down, and click Start Build.
The test result is displayed on your BrowserStack App Automate dashboard page.
Integrate Existing TestCase
With existing test cases, integrating BrowserStack involves editing your test cases to add BrowserStack capabilities, credentials, and, remote URLs.
BrowserStack provides capabilities that help determine how tests are run. The following code snippet sets the Google Pixel 3 android device and the OS version to 10.0 , declares app URL, access key, and username as environment variables, and creates a remote driver connection.
Use the BROWSERSTACK_APP_URL
environment variable in your test script to pass the app capability in your test suite.
Using the default BITRISE_BUILD_NUMBER
or BITRISEIO_PIPELINE_TITLE
environment variables in the BrowserStack build name. It helps generate a unique build name for every test run. To learn more about this environment variable, check out the Bitrise Pipeline Environment Reference page.
Use these environment variables to set the desired capabilities in your tests:
String username = System.getenv("BROWSERSTACK_USERNAME");
String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY");
String appURL = System.getenv("BROWSERSTACK_APP_URL");
String buildID = System.getenv("BITRISE_BUILD_NUMBER");
String pipelineTitle = System.getenv("BITRISEIO_PIPELINE_TITLE");
MutableCapabilities capabilities = new MutableCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("buildName", "bitrise--" + buildID + "--" + pipelineTitle);
capabilities.setCapability("bstack:options", browserstackOptions);
capabilities.setCapability("platformName", "android");
capabilities.setCapability("platformVersion", "9.0");
capabilities.setCapability("deviceName", "Google Pixel 3 XL");
capabilities.setCapability("app", appURL);
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub"), capabilities);
userName = process.env.BROWSERSTACK_USERNAME
accessKey = process.env.BROWSERSTACK_ACCESS_KEY
appURL = process.env.BROWSERSTACK_APP_URL
buildID = process.env.BITRISE_BUILD_NUMBER
pipelineTitle = process.env.BITRISEIO_PIPELINE_TITLE
var capabilities = {
"platformName" : "android",
"platformVersion" : "9.0",
"deviceName" : "Google Pixel 3 XL",
"app" : appURL,
"browserName" : "chrome",
'bstack:options' : {
"userName" : userName,
"accessKey" : accessKey,
"buildName" : "bitrise--" + buildID + "--" + pipelineTitle
},
}
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");
appURL = Environment.GetEnvironmentVariable("BROWSERSTACK_APP_URL")
buildID = Environment.GetEnvironmentVariable("BITRISE_BUILD_NUMBER")
pipelineTitle = Environment.GetEnvironmentVariable("BITRISEIO_PIPELINE_TITLE")
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("userName", userName);
browserstackOptions.Add("accessKey", accessKey);
browserstackOptions.Add("buildName", "bitrise--" + buildID + "--" + pipelineTitle);
capabilities.AddAdditionalCapability("bstack:options", browserstackOptions);
capabilities.AddAdditionalCapability("platformName", "android");
capabilities.AddAdditionalCapability("platformVersion", "9.0");
capabilities.AddAdditionalCapability("appium:deviceName", "Google Pixel 3 XL");
capabilities.AddAdditionalCapability("appium:app", appURL);
AndroidDriver driver = new AndroidDriver(new Uri("https://hub-cloud.browserstack.com/wd/hub"), capabilities);
$user_name = getenv("BROWSERSTACK_USERNAME")
$access_key = getenv("BROWSERSTACK_ACCESS_KEY")
$appURL = getenv("BROWSERSTACK_APP_URL")
$buildID = getenv("BITRISE_BUILD_NUMBER")
$pipelineTitle = getenv("BITRISEIO_PIPELINE_TITLE")
$caps = array(
'bstack:options' => array(
"buildName" => "bitrise--".$buildID."--".$pipelineTitle,
),
"platformName" => "android",
"platformVersion" => "9.0",
"deviceName" => "Google Pixel 3 XL",
"app" => $appURL,
);
driver = webdriver.Remote("https://".$user_name.":".$access_key."@hub-cloud.browserstack.com/wd/hub", $caps)
user_name = os.getenv("BROWSERSTACK_USERNAME")
access_key = os.getenv("BROWSERSTACK_ACCESS_KEY")
appURL = os.getenv("BROWSERSTACK_APP_URL")
buildID = os.getenv("BITRISE_BUILD_NUMBER")
pipelineTitle = os.getenv("BITRISEIO_PIPELINE_TITLE")
desired_cap = {
"platformName" : "android",
"platformVersion" : "9.0",
"deviceName" : "Google Pixel 3 XL",
"app" : appURL,
'bstack:options': {
"buildName" : "bitrise--" + buildID + "--" + pipelineTitle,
},
}
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"]
appURL = ENV["BROWSERSTACK_APP_URL"]
buildID = ENV["BITRISE_BUILD_NUMBER"]
pipelineTitle = ENV["BITRISEIO_PIPELINE_TITLE"]
capabilities = {
"platformName" => "android",
"platformVersion" => "9.0",
"deviceName" => "Google Pixel 3",
"app" => appURL,
'bstack:options' => {
"buildName" => 'bitrise--' + buildID + '--' + pipelineTitle,
},
}
appium_driver = Appium::Driver.new({
'caps' => capabilities,
'appium_lib' => {
:server_url => "https://#{user_name}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
}}, true)
String username = System.getenv("BROWSERSTACK_USERNAME");
String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY");
String appURL = System.getenv("BROWSERSTACK_APP_URL");
String buildID = System.getenv("BITRISE_BUILD_NUMBER");
String pipelineTitle = System.getenv("BITRISEIO_PIPELINE_TITLE");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("os_version", "10.0");
capabilities.setCapability("device", "Google Pixel 3");
capabilities.setCapability("app", appURL);
capabilities.setCapability("build", "bitrise--" + buildID + "--" + pipelineTitle);
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub"), capabilities);
userName = process.env.BROWSERSTACK_USERNAME
accessKey = process.env.BROWSERSTACK_ACCESS_KEY
appURL = process.env.BROWSERSTACK_APP_URL
buildID = process.env.BITRISE_BUILD_NUMBER
pipelineTitle = process.env.BITRISEIO_PIPELINE_TITLE
var capabilities = {
"browserstack.user" : userName,
"browserstack.key" : accessKey,
"app" : appURL,
"device" : "Samsung Galaxy S8",
"build" : "bitrise--" + buildID + "--" + pipelineTitle
}
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");
appURL = Environment.GetEnvironmentVariable("BROWSERSTACK_APP_URL")
buildID = Environment.GetEnvironmentVariable("BITRISE_BUILD_NUMBER")
pipelineTitle = Environment.GetEnvironmentVariable("BITRISEIO_PIPELINE_TITLE")
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("browserstack.user", userName);
caps.SetCapability("browserstack.key", accessKey);
caps.SetCapability("app", appURL);
caps.SetCapability("device", "Samsung Galaxy S8");
caps.SetCapability("build", 'bitrise--' + buildID + '--' + pipelineTitle);
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")
$appURL = os.getenv("BROWSERSTACK_APP_URL")
$buildID = os.getenv("BITRISE_BUILD_NUMBER")
$pipelineTitle = os.getenv("BITRISEIO_PIPELINE_TITLE")
desired_cap = {
'browserstack.user': $user_name,
'browserstack.key': $access_key,
'device': 'Samsung Galaxy S8',
'app': $appURL,
'build': 'bitrise--'.$buildID.'--'.$pipelineTitle
}
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")
appURL = os.getenv("BROWSERSTACK_APP_URL")
buildID = os.getenv("BITRISE_BUILD_NUMBER")
pipelineTitle = os.getenv("BITRISEIO_PIPELINE_TITLE")
desired_cap = {
'app': appURL,
'device': 'Samsung Galaxy S8',
'build': 'bitrise--' + buildID + '--' + pipelineTitle
}
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"]
appURL = ENV["BROWSERSTACK_APP_URL"]
buildID = ENV["BITRISE_BUILD_NUMBER"]
pipelineTitle = ENV["BITRISEIO_PIPELINE_TITLE"]
desired_caps = {
'device': 'Samsung Galaxy S8',
'app': appURL,
'build': 'bitrise--' + buildID + '--' + pipelineTitle
}
appium_driver = Appium::Driver.new({
'caps' => desired_caps,
'appium_lib' => {
:server_url => "https://#{user_name}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
}}, true)
Integrate test cases for privately hosted websites
To test websites hosted locally as part of your testing or development environment, you need to configure your Bitrise pipeline to use the Local testing.
Using the Local testing feature of BrowserStack, remote browsers at the BrowserStack cloud can access websites hosted on your internal networks. To learn more about how Local testing works, check out the Local testing guide.
Enable Local Testing
You can enable Local testing using these ways:
Using the Local binary, the remote browsers in the BrowserStack cloud can access your private or locally-hosted website through the connection established between BrowserStack and the Local binary running on your machine.
Prerequisites
- Ensure all the steps mentioned in the Configure Bitirse Pipeline section are complete.
To create a Bitrise pipeline that uses BrowserStack Local:
- Under the Upload app to BrowserStack and run your tests section, along with the commands that your tests need to run, add the following commands based on your OS.
These commands use the--daemon start
and--daemon stop
flags to start and stop the Local binary respectively. To learn about additional flags used in running Local binary, check out the Binary parameter guide.# For Linux-based systems, add the following commands in the given console to download the binary, run it, and stop its execution after the test has been executed. $ wget "https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-x64.zip" $ unzip BrowserStackLocal-linux-x64.zip $ ./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --daemon start $ <your-test-command> $ ./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --daemon stop # For macOS-based systems, add the following commands in the given console to download the binary, run it, and stop its execution after the test has been executed. $ wget "https://www.browserstack.com/browserstack-local/BrowserStackLocal-darwin-x64.zip" $ unzip BrowserStackLocal-darwin-x64.zip $ ./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --daemon start $ <your-test-command> $ ./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --daemon stop # For Windows-based systems, add the following commands in the given console to download the binary, run it, and stop its execution after the test has been executed. $ wget "https://www.browserstack.com/browserstack-local/BrowserStackLocal-win32.zip" $ powershell.exe Expand-Archive BrowserStackLocal-win32.zip $ \BrowserStackLocal-win32\BrowserStackLocal.exe --key %BROWSERSTACK_ACCESS_KEY% --daemon start $ <your-test-command> $ .\BrowserStackLocal-win32\BrowserStackLocal.exe --key %BROWSERSTACK_ACCESS_KEY% --daemon stop
- Navigate to the workflow and click on Start/schedule build.
If you manage the Local connection through your test scripts, you can use the language bindings.
Check out the enabling Local testing using language bindings to edit your test scripts.
Note: Ensure the steps mentioned in the setup Bitrise pipeline section to create your Bitrise pipeline are completed.
Add local capability to test scripts
Add the local capability and set it to true
to the test scripts, BrowserStack resolves the request using the Local agent running in your network.
browserstackOptions.put("local", "true");
'bstack:options' : {
"local" : "true",
},
browserstackOptions.Add("local", "true");
'bstack:options' => array(
"local" => "true",
),
'bstack:options' : {
"local" : "true",
},
'bstack:options' => {
"local" => "true",
},
capabilities.setCapability("browserstack.local", "true");
"browserstack.local" : "true",
capability.AddAdditionalCapability("browserstack.local", "true", true);
"browserstack.local" => "true",
"browserstack.local" : "true",
caps["browserstack.local"] = "true",
You can verify if the test passed or failed on the Bitrise 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
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!