A step-by-step guide to help you integrate Drone with the BrowserStack device cloud for running all your Selenium tests on BrowserStack Automate.
Drone by Harness™ is a modern Continuous Integration platform that empowers busy teams to automate their build, test, and release workflows using a powerful, cloud-native pipeline engine.
On the Secrets page, click New organization secret to add your username as the BROWSERSTACK_USERNAME secret. Similarly, add your access key as the BROWSERSTACK_ACCESS_KEY secret.
After adding the credential details, the secrets page shows entries as follows:
Create a .drone.yml file in the root of your repository. Pipelines in Drone are configured using this yaml file.
Edit the .drone.yml file to add the type, platform, and steps details according to your Drone Runner setup and test execution commands.
In the steps section of the .drone.yml file, add the following details to provide your credential information from Secrets you added in step 5.
With existing test cases, integrating BrowserStack involves editing your test cases to add BrowserStack capabilities, credentials, and remote URL.
Though your existing test scripts include capabilities, BrowserStack also provides specific capabilities that help determine how tests are run. The following example code snippet sets the build name, declares Username and Access Key from environment variables, and creates a remote driver connection.
Using the default DRONE_REPO_NAME and DRONE_BUILD_NUMBER environment variables in the BrowserStack build name helps generate a unique build name for every test run. To learn more about these environment variables, check out the Drone Pipeline Environment Reference page.
Set capabilities using the following code snippet:
my$username=$ENV{"BROWSERSTACK_USERNAME"};my$accessKey=$ENV{"BROWSERSTACK_ACCESS_KEY"};my$repoName=$ENV{"DRONE_REPO_NAME"};my$buildNumber=$ENV{"DRONE_BUILD_NUMBER"};my$caps={"build"=>"drone-".$repoName."-".$buildNumber,"seleniumVersion"=>"4.0.0",};my$host="$username:$accessKey\@hub.browserstack.com";my$driver= new Selenium::Remote::Driver('remote_server_addr'=>$host,'port'=>'80','extra_capabilities'=>$caps);
my$username=$ENV{"BROWSERSTACK_USERNAME"};my$accessKey=$ENV{"BROWSERSTACK_ACCESS_KEY"};my$repoName=$ENV{"DRONE_REPO_NAME"};my$buildNumber=$ENV{"DRONE_BUILD_NUMBER"};my$caps={"build"=>"drone-".$repoName."-".$buildNumber,};my$host="$username:$accessKey\@hub.browserstack.com";my$driver= new Selenium::Remote::Driver('remote_server_addr'=>$host,'port'=>'80','extra_capabilities'=>$caps);
Integrate test cases for locally hosted websites
If you are testing websites hosted locally as part of your testing or development environment, you need to configure your Drone pipeline to use Local testing.
Using the Local testing feature of BrowserStack, remote browsers at the BrowserStack cloud can access websites hosted on your private or internal networks. To learn more about how Local testing works, check out the Local testing section.
Apart from setting up a Local connection, you must also add the browserstack.local capability in your test scripts.
Using Local binary, the remote browsers in the BrowserStack cloud are able to access your private or locally-hosted website through the connection established between BrowserStack and the Local binary running on your machine.
To create a Drone pipeline that uses BrowserStack Local, complete the following steps:
Under the commands 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 Local binary respectively. To learn about additional flags used in running Local binary, check out the binary parameter section.
a. For Linux-based operating systems:
Note: Ensure that you complete the steps mentioned in the set up Drone pipeline section to create your Drone pipeline.
Apart from these configurations, you can set other Local options, such as, testing behind a proxy, folder testing, or using multiple local instances. Check out Introduction to Local Testing for more information.
Add browserstack.local capability to test scripts
Add the browserstack.local capability to test scripts using the following code snippets. When you set this capability to true, BrowserStack resolves the request via the Local agent running in your network.