Bitbucket
  • 11 Oct 2023
  • 3 Minutes to read
  • Dark
    Light

Bitbucket

  • Dark
    Light

Article summary

Overview

Bitbucket Pipelines is a service integrated into Bitbucket Cloud that enables the automatic building, testing, and deployment of code through a configuration file in a repository. This service generates containers in the cloud where you can execute commands, customized and configured to meet your requirements, as you would on a local machine. The bitbucket-pipelines.yml file, located at the root of your repository, defines a pipeline.

Integrating pCloudy with Bitbucket Pipelines allows you to conduct testing of web and native applications on 5000 device-browser combinations through an Appium server located on pCloudy cloud servers. To achieve this, you only need to establish a connection between your pCloudy account and Bitbucket Pipelines, which enables you to initiate tests on pCloudy from Bitbucket Pipelines.

Prerequisites

In order to conduct Mocha tests using pCloudy, you must have the following prerequisites in place:

Global Dependencies

  • A bitbucket repository
    You must first download and install node.js and node package manager or npm. For installation of node.js using homebrew, execute the given command in your terminal:
    $ brew install node 
    
    In case you already have npm installed, it is advisable to update it to the most recent version. You can do this by running the following command in your terminal:
    $ npm install npm@latest -g
    

Integrating pCloudy With Bitbucket

Steps

  1. Sign up for a Bitbucket account.
  2. Upload the Mocha-Test-code to your repository in Bitbucket.
  3. Create a new bitbucket-pipelines.yml file in the root directory of your repository to set up a build for your project.
  4. Add the script to run the build for the Mocha-Test-code.
# This script is a template for building NodeJS code. It contains a workflow that       validates the code by running tests and code linting on the default branch.
# The image used is node:20.0.0, which is the version of NodeJS used for   the build.

image: node:20.0.0

pipelines:
  	default:
   	 - parallel:
       	 - step:
# The pCloudy step runs tests and code linting in parallel with any other steps defined in the pipeline.
            name: pCloudy
            caches:
              - node
            script:
              - npm install # Install any required NodeJS modules for the build.
              - npm run android # Run the build for the Android platform.
  1. With every commit, Bitbucket will execute the build (#bitbucket-pipelines.yml), while simultaneously running the test on pCloudy My Active Sessions.

Note that these steps are essential for setting up the integration between pCloudy and Bitbucket Pipeline. By following these steps, you can leverage the benefits of pCloudy's cloud-based testing infrastructure and run your Mocha-Test-code on multiple device-browser combinations. This can help you identify issues early in the development process and improve the overall quality of your code.

The given code shows the desired capabilities needed to execute the Sample-test.

    capabilities = {
            "browserName": "",
            "pCloudy_Username": "Enter-Email",
            "pCloudy_ApiKey": "Enter API-Key",
            "pCloudy_ApplicationName": "pCloudyAppiumDemo.apk",
            "pCloudy_DurationInMinutes": "10",
            "pCloudy_DeviceFullName":  
            "GOOGLE_Pixel2XL_Android_11.0.0_d22ac",
            "platformName": "Android",
            "automationName": "uiautomator2",
            "newCommandTimeout": "600",
            "launchTimeout": "90000",
            "appPackage": "com.pcloudy.appiumdemo",
            "appActivity": "com.ba.mobile.LaunchActivity",
            "pCloudy_EnableVideo" : "true", # optional
        };

The "pCloudy_Username" and "pCloudy_ApiKey" fields can be customized as per the user's credentials.

Parallel Test

To enable parallel testing, you need to upload the parallel-Test-code to your Bitbucket repository. Once you have done this, you will need to specify the desired capabilities required to execute the Sample-test.

commonCapabilities: {
              browserName: "",
              pCloudy_Username:"Enter-Email",
              pCloudy_ApiKey: "Enter API KEY",
              pCloudy_ApplicationName: "pCloudyAppiumDemo.apk",
              pCloudy_DurationInMinutes: "10",
              platformName: "Android",
              automationName: "uiautomator2",
              newCommandTimeout: "600",
              launchTimeout : "90000",
              appPackage: "com.pcloudy.appiumdemo",
              appActivity: "com.ba.mobile.LaunchActivity",
              pCloudy_EnableVideo : "true",
        },
        multiCapabilities: [
          {
              "pCloudy_DeviceFullName": "GOOGLE_Pixel7Pro_Android_13.0.0_dbf82",
          },
          {
              "pCloudy_DeviceFullName": "MOTOROLA_Edge30Ultra_Android_12.0.0_15b11",
          }

The commonCapabilities field contains properties such as browserName, pCloudy_Username, and pCloudy_ApiKey, which need to be customized as per your credentials. In the multiCapabilities field, you can add as many devices as you require by specifying the pCloudy_DeviceFullName property for each device. This will enable you to execute the Sample-test on multiple device-browser combinations in parallel, leveraging the benefits of pCloudy's cloud-based testing infrastructure.


Was this article helpful?

What's Next