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.
Setting up CrossBrowserTesting with Bitbucket pipelines is quite simple, we'll be up and running in a few quick steps!
Start by creating a new repository for your project.
Clone this repository:
Enable Bitbucket pipelines in your newly cloned repository. Go to: Settings > Pipelines Settings > Enable Pipelines.
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.
Now every time you you push a commit the test will automatically start under the Pipelines tab.
- 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).
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.