Selenium tests

Selenium is a set of automated testing frameworks used for browser-based regression testing. In Buddy, the Selenium suite is available as an attachable service and supports Chrome and Mozilla browsers.

Pipeline configuration

Project setup

First, you need to add a project and synchronize the repository with the website that you want to test. You can hook up Buddy with GitHub, Bitbucket or GitLab, attach any Git repository of your choice, or use Buddy's own Git hosting:

Image loading...Project configurationProject configuration

Pipeline setup

The next step is adding a new pipeline and defining when and for which branches it should run. You can run your tests after every push to the repository, at a specific time of a day, or before the deployment to the server. Here is an example of a pipeline which triggers the tests every 30 minutes for the staging branch:

Image loading...Pipeline configuration detailsPipeline configuration details

Adding actions

Now it’s time to add the build action to which we'll attach Selenium. Select the action that matches the type of your website:

Image loading...Build actions in BuddyBuild actions in Buddy

Inside the action, you can define the commands to run. In this example, we run gulp in the Node.js environment:

Image loading...Node action with gulp commandNode action with gulp command

Configuring Selenium service

Success
In Buddy, builds are run in isolated containers launched from a Docker image holding the environment configuration. This type of architecture allows for attaching other services as containers – and so is the case with Selenium.

To add Selenium, go to the action's Services tab, click the + button, and look up Selenium on the list. You can choose either Chrome or Firefox driver:

Image loading...List of servicesList of services

During configuration, you select the version of the service, and define the hostname and port. There are also two additional options:

  • Skip cache and pull image on every run – turning this on and setting the image version to 'latest' ensures that you always use the newest version of the service.
  • Allow passing variables to this service – this option allows using variables generated by the preceding actions.

Image loading...Selenium service configurationSelenium service configuration

Adding the service will produce it on the list together with the access details:

Image loading...Services overviewServices overview

The last step is pasting the hostname to the Selenium configuration file in your repository. Here's an example for a WebdriverIO file:

  # Node.js + WebdriverIO example
          require('webdriverio').remote({
     desiredCapabilities: {
     browserName : 'chrome'
     },
     host: 'selenium-ch',
     port: 4444
 });

BrowserStack integration

If you want to run advanced Selenium tests in parallel on multiple browsers, we recommend to use BrowserStack. Here is an example of the config file for the Ruby's Cucumber framework:

require 'selenium/webdriver'

  url = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub-cloud.browserstack.com/wd/hub"

  capabilities = Selenium::WebDriver::Remote::Capabilities.new

  capabilities['project'] = ENV['BS_AUTOMATE_PROJECT'] if ENV['BS_AUTOMATE_PROJECT']
  capabilities['build'] = ENV['BS_AUTOMATE_BUILD'] if ENV['BS_AUTOMATE_BUILD']

  capabilities['platform'] = ENV['SELENIUM_PLATFORM'] || 'ANY'
  capabilities['browser'] = ENV['SELENIUM_BROWSER'] || 'chrome'
  capabilities['browser_version'] = ENV['SELENIUM_VERSION'] if ENV['SELENIUM_VERSION']

  browser = Selenium::WebDriver.for(:remote, :url => url, :desired_capabilities => capabilities)

  Before do |scenario|
  @browser = browser
  end

  at_exit do
  browser.quit
  end

The whole config is based on a series of environment variables:

        SELENIUM_HOST: hub.browserstack.com
        BS_AUTOMATE_PROJECT: "Buddy Tests"
        BS_AUTOMATE_BUILD: "build No. $BUDDY_EXECUTION_ID"
        SELENIUM_PLATFORM: WINDOWS
        BS_AUTOMATE_OS_VERSION: 10
        SELENIUM_BROWSER: Chrome
        SELENIUM_VERSION: 4.10.0

The variables can be set in the pipeline's Variables tab:

Image loading...Pipeline variables tabPipeline variables tab

Recommended
Last update:
Sep 26, 2024