Bitbucket Integration

Applies to CrossBrowserTesting SaaS, last modified on April 14, 2021

This is an example of how you can use CrossBrowserTesting Automated Testing with Bitbucket pipelines to test a local development server. Python and Flask are used in this example but this can be done in a variety of languages and frameworks.

Bitbucket pipelines works by creating a Docker containers. Inside these containers you can run commands (like you might on a local machine) but with all the advantages of a fresh system, custom configured for your needs. To learn more about Docker containers you can go here: More about Docker Containers.

Requirements

  1. Bitbucket account.

  2. This repository.

  3. CrossBrowserTesting username and authkey which can be found here: CrossBrowserTesting Credentials.

Setup

Setting up CrossBrowserTesting with Bitbucket pipelines is quite simple, we'll be up and running in a few quick steps!

  1. Start by creating a new repository for your project.

  2. Clone this repository:

    git clone
    https://bitbucket.org/crossbrowsertesting/cbt_bitbucket.git

  3. Enable Bitbucket pipelines in your newly cloned repository. Go to: Settings > Pipelines Settings > Enable Pipelines.

  4. Add repository variables to your repo using your CrossBrowserTesting Credentials:

    • Go to: Settings > Pipelines Repository variable.

    • Add CrossBrowserTesting username: CBT_USERNAME | add_username_here.

    • Add CrossBrowserTesting authkey: CBT_AUTHKEY | add_authkey_here.

Repository variables input

Click the image to enlarge it.

Now every time you you push a commit the test will automatically start under the Pipelines tab.

Build configuration

image: python:3.7.3

pipelines:
  default:
    - step:
        script:
          - apt-get install unzip
          - pip install flask
          - pip install selenium
          - pip install requests
          - python app.py /dev/null & #Start up webserver in background
          - bash ./local_connection.bash #Get local connection package from CBT
          - ./cbt_tunnels-linux-x64 --username $CBT_USERNAME --authkey $CBT_AUTHKEY --kill flag.txt /dev/null & #Start local connection
          - python CBT_test.py #Run test to check webserver
          - bash ./kill_local_connection.bash #Kill local connection

Lets see what this is doing

  • We are creating a container with Python 3.7.3 installed.

  • Next we get the required packages that we need:

    • Unzip (Used to unzip local connection package from CrossBrowserTesting).

    • Flask (Simple webserver).

    • Selenium (Create webdriver for automation testing).

    • Requests (Send HTTP requests to CrossBrowserTesting).

  • We spin up a Flask server on port 5000.

  • We get the local connection package from CrossBrowserTesting and run it using our credentials. Local Connection Service.

  • We run a simple test to connect to the website and check the page title.

  • Finally we create the flag.txt file to then kill the local connection.

See Also

Integrations

Highlight search results