CrossBrowserTesting to BitBar Migration

On June 21st 2022, SmartBear launched web application testing on our unified cloud testing solution that will include both browser and device testing on the BitBar platform! We have listened to our customers and having one product for both web and device testing will better meet your needs.

BitBar is a scalable, highly reliable and performant platform with multiple datacenters. On it, you will have access to the latest browsers and devices with additional deployment options to meet your needs, including private cloud and dedicated devices.

With this change, we have also announced that we will be sunsetting the CrossBrowserTesting cloud in July 2023, as this new product will replace CrossBrowserTesting. We know that you have loved CrossBrowserTesting, but BitBar has been designed to meet your modern‑day testing needs. We are confident that you’ll enjoy this new product as much as we do.

For more frequently asked questions about the launch of web app testing on BitBar, visit our FAQ.

If you are a live tester, you can immediately start testing in BitBar. Click here to see the documentation on BitBar Live Testing.

Selenium and Appium testers, choose your language for a step-by-step guide with our best practices to set you up for migration success. You can also click here to view the BitBar web app testing documentation.

  • Python

  • C#

  • Java

In general, here are a few main considerations to consider as you migrate you automation scripts from CrossBrowserTesting to BitBar:

  • Update the authorization method. Obtain the BitBar API key as described here.

  • Update the Selenium hub. With BitBar you have four options depending on location and/or device applicable to you –

    • US_WEST:DESKTOP: https://us-west-desktop-hub.bitbar.com/wd/hub

    • EU:DESKTOP: https://eu-desktop-hub.bitbar.com/wd/hub

    • US_WEST:MOBILE: https://us-west-mobile-hub.bitbar.com/wd/hub

    • EU:MOBILE: https://eu-mobile-hub.bitbar.com/wd/hub

  • Update the Selenium capabilities. New capabilities can be found here.

If you have additional questions or need additional support, please submit a support case from this page.

Setting Test Result Score in BitBar

By following these steps, you can set up your test results and see them in the BitBar UI. If you run many tests, it's simpler to find them on the test results page. It saves you time scrolling through all the test run logs. This way you can find the tests that failed and analyze them much faster. To set your test result score in BitBar, log in to your BitBar account and check the POST request that you need to implement in your code. To do that, you need:

  • webdriver session_id (also used in CBT sample scripts), which you can obtain, for example, with the driver.getSessionId() command.

  • deviceSessionId, which, due to older BitBar versions, is also called deviceRunId. The simplest way to acquire it during your session is with the GET request:

    curl GET -u {myAPIkey}: https://appium.bitbar.com/sessions/{session_id} | jq | grep deviceRunId

    Note

    For US, use the following hub:https://appium-us.bitbar.com/sessions/{session_id}.

  • UserID, for which we advise replacing users/{userId} with me:

    /api/v2/users/{userId}/device-sessions/{deviceSessionId} /api/v2/me/device-sessions/{deviceSessionId}

Here are the steps to follow:

  1. Log in to your BitBar account and check the POST request.

  2. Get webdriver session_id(driver.getSessionId, as in CBT example scripts).

  3. Send GET request with the proper session_id (the same you're using in CBT).

  4. Strip the response to obtain deviceRunId.

  5. Send POST request with this deviceSessionID (deviceRunId) and the desired state.

You can set your test result score with a simple curl command, or with Swagger Inspector, or write it in your code (see Python example).

Note

If you are a Java user, you can find dependency for BitBar Cloud API Client here

To see your test results in the BitBar UI, open your test run and click the panel on the upper right corner. It opens a panel giving Device Execution Status. There are numerous possible statuses. You can edit your script to use more than Succeeded and Failed status if you want to. You make those API calls the same way they’re made in the script, just change the test result variable.

Bitbar UI
Device Status

Python Script

To make your CrossBrowserTesting script work in BitBar you’ll have to change the following:

  1. Add your apikey - you can find it in BitBar account settings as described here.

    This is a new method to authenticate the user and to make api calls.

  2. Change capabilities (you can use capabilities creator on BitBar website and just paste them into your code), please note that BitBar is using variable name capabilities instead of cap, so for your convenience you can change the variable name you assign to desired capabilities in remote webdriver starting command.

    You can set project name capability to view your test run results under a single project.

  3. When starting remote webdriver remember that we now connect to the BitBar hub, so the address we’re pointing to will have to change as well.

    # start the remote browser on our server
            self.driver = webdriver.Remote
                desired_capabilities=capabilities
                command_executor="https://appium.bitbar.com/wd/hub"
            )
    
    
    
  4. Still, you put your test commands inside the try block

  5. self.test_result in try block and when catching exceptions is changed to SUCCEEDED or FAILED (necessary to pass in api call to set test result later) self.test_result = 'SUCCEEDED'

  6. In tearDown function we completely change the way how we set test result, as BitBar uses different API so it’s best to just copy what’s written there. If you want to dive deeper into BitBar API here is the link:

    https://cloud.bitbar.com/cloud/swagger-ui.html#/

                #get all necessary IDs of current session
                response = requests.get('https://appium.bitbar.com/sessions/' + self.driver.session_id, auth=(self.apiKey, '')).json()
                deviceRunID = str(response["deviceRunId"])
                projectID = str(response["projectId"])
                RunId = str(response["testRunId"])
    
                # Here we make the api call to set the test's score
                requests.post('https://cloud.bitbar.com/api/v2/me/projects/' + projectID + '/runs/' +
                RunId + '/device-sessions/' + deviceRunID, params={'state': self.test_result},
                auth=(self.apiKey, ''))
    
  7. Most of the changes made are described in code comments, besides those described above, delete all old references to CrossBrowserTesting.

Additionally, go to BitBar test creator and click on ‘Show full sample script’ checkbox for the desired language to see working sample code. It doesn’t have API calls to set test results, but you can use methods from the script below.

FULL SCRIPT:

# Please visit http://selenium-python.readthedocs.io/ for detailed installation and instructions# Getting started: http://docs.seleniumhq.org/docs/03_webdriver.jsp# API details: https://github.com/SeleniumHQ/selenium#selenium# Requests is the easiest way to make RESTful API calls in Python. You can install it by following the instructions here:# http://docs.python-requests.org/en/master/user/install/import unittest
from selenium import webdriver
import requests


class BasicTest(unittest.TestCase):
    def setUp(self):

        #get rid of the old way of doing auth with just an API key
        
        self.apiKey = '<insert your BitBar API key here>'

        self.api_session = requests.Session()

        self.test_result = None
        
        #old platformName has been split into platformName and osVersion
        capabilities = {
            'platformName': 'Linux',
            'browserName': 'firefox',
            'browserVersion': '96',
            'bitbar:options': {
                'apiKey': '<insert your BitBar API key here>',
                'resolution': '2560x1920',
                'osVersion': '18.04'
                }
            }


        # start the remote browser on our server
        self.driver = webdriver.Remote(
            desired_capabilities=capabilities,
            #the hub is changed, also not sending the user and pass through the hub anymore
            #US hub url: https://appium-us.bitbar.com/wd/hub
            command_executor="https://appium.bitbar.com/wd/hub" #EU hub url
        )

        self.driver.implicitly_wait(20)

    def test_CBT(self):
        # We wrap this all in a try/except so we can set pass/fail at the end
        try:
            # load the page url
            print('Loading Url')
            self.driver.get('http://crossbrowsertesting.github.io/selenium_example_page.html')

            # maximize the window - DESKTOPS ONLY
            #print('Maximizing window')
            #self.driver.maximize_window()
            
            #check the title
            print('Checking title')
            self.assertEqual("Selenium Test Example Page", self.driver.title)

            # change pass to SUCCEEDED
            self.test_result = 'SUCCEEDED'

        except AssertionError as e:

            # delete cbt api calls
  
            # change fail to FAILED
            self.test_result = 'FAILED'
            raise

    def tearDown(self):
        print("Done with session %s" % self.driver.session_id)
        if self.test_result is not None:
            #get all necessary IDs of current session
            response = requests.get('https://appium.bitbar.com/sessions/' + self.driver.session_id, auth=(self.apiKey, '')).json()
            deviceRunID = str(response["deviceRunId"])
            projectID = str(response["projectId"])
            RunId = str(response["testRunId"])

            # Here we make the api call to set the test's score
            requests.post('https://cloud.bitbar.com/api/v2/me/projects/' + projectID + '/runs/' +
            RunId + '/device-sessions/' + deviceRunID, params={'state': self.test_result},
            auth=(self.apiKey, ''))
            
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

C# Changes

To make your CrossBrowserTesting script work in BitBar you’ll have to change the following:

  1. Delete references to CrossBrowserTesting API.

  2. Update hub url and capabilities (but used OpenQA.Selenium.RemoteSessionSettings to set them just like in cbt script. Bitbar suggests using DesiredCapabilities but it throws errors).

  3. Update CrossBrowserTesting API calls to set test results into simple print functions.

FULL SCRIPT:

using System;
using System.Collections.Generic;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
using NUnit.Framework;

namespace BasicTest
{
    class BasicTest
    {
        //deleted username and authkey, bitbar uses apikey in capabilities

        static void Main(string[] args)
        {
            //deleted CBTApi constructor

            var caps = new OpenQA.Selenium.RemoteSessionSettings();

            //setting capabilities the same way like in cbt script, but using bitbar ones (they differ a little)
            caps.AddMetadataSetting("platform", "Linux");
            caps.AddMetadataSetting("osVersion", "18.04");
            caps.AddMetadataSetting("browserName", "firefox");
            caps.AddMetadataSetting("version", "96");
            caps.AddMetadataSetting("resolution", "2560x1920");
            caps.AddMetadataSetting("bitbar_apiKey", "<insert your BitBar API key here>");

            //just change hub url in arguments, ure EU or US one, caps argument stays the same
            //US hub URL-https://appium-us.bitbar.com/wd/hub
            RemoteWebDriver driver = new RemoteWebDriver(new Uri("https://appium.bitbar.com/wd/hub"), caps, TimeSpan.FromSeconds(180));

            try
            {
                //write your code here

                driver.Navigate().GoToUrl("http://crossbrowsertesting.github.io/selenium_example_page.html");
                // Check the title
                Console.WriteLine(driver.Title);
                Assert.AreEqual(driver.Title, "Selenium Test Example Pageafkjhekfj");

                //deleted setScore CBTApi method, used temporary WriteLine function
                Console.WriteLine("pass");
            }
            catch (Exception ex)
            {
                //deleted takeSnapshot, setDescription and setScore CBTApi methods, used temporary WriteLine function
                Console.Error.WriteLine(ex.Message);
                Console.WriteLine("fail");
            }
            finally
            {
                driver.Quit();

            }
        }
    }
    //deleted CBTApi class
}

Java Changes

To make your CrossBrowserTesting script work in BitBar you’ll have to change the following:

  1. Delete all CrossBrowserTesting references.

  2. Update hub url and capabilites.

// Getting started: http://docs.seleniumhq.org/docs/03_webdriver.jsp
// API details: https://github.com/SeleniumHQ/selenium#selenium
// Unirest is the recommended way to interact with RESTful APIs in Java
// http://unirest.io/java.html
// runs test against http://crossbrowsertesting.github.io/selenium_example_page.html

import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

import static org.junit.Assert.*;

class BasicTest {

    // deleted username, authkey
    String testScore = "unset";
    
    public static void main(String[] args) throws Exception {
        
        BasicTest myTest = new BasicTest();
        // bitbar uses DesiredCapabilities as well, just copy them
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platform", "Linux");
        capabilities.setCapability("osVersion", "18.04");
        capabilities.setCapability("browserName", "firefox");
        capabilities.setCapability("version", "96");
        capabilities.setCapability("resolution", "2560x1920");
        capabilities.setCapability("bitbar_apiKey", ""); //<insert your BitBar API key here>
        
        // changed hub url, variable caps changed to capabilities
        // US hub - https://appium-us.bitbar.com/wd/hub
        RemoteWebDriver driver = new RemoteWebDriver(new URL("https://appium.bitbar.com/wd/hub"), capabilities);
        
        System.out.println(driver.getSessionId());
        
        // we wrap the test in a try catch loop so we can log assert failures in our system
        try {

            // load the page url
            System.out.println("Loading Url");
            driver.get("http://crossbrowsertesting.github.io/selenium_example_page.html");
            // maximize the window - DESKTOPS ONLY
            //System.out.println("Maximizing window");
            //driver.manage().window().maximize();
            // Check the page title (try changing to make the assertion fail!)
            System.out.println("Checking title");
            assertEquals(driver.getTitle(), "Selenium Test Example Page");
            
            // if we get to this point, then all the assertions have passed
            // that means that we can set the score to pass in our system
            myTest.testScore = "pass";
            }
        catch(AssertionError ae) {
            //deleted takeSnapshot call
            //deleted setDescription call
            // if we have an assertion error set the score to "fail"
            myTest.testScore = "fail";
            }
        finally {

            System.out.println("Test complete: " + myTest.testScore);
            // simple print function instead of api call to set the score - future bitbar api call
            System.out.println(myTest.testScore);
            
            // and quit the driver
            driver.quit();
            }
    }

    //deleted setScore, takeSnapshot and setDescription functions}

See Also

Publication date: