Selenium tests

Selenium is a set of tools for browser testing automation. With Buddy dedicated service you can run Selenium tests directly in Buddy.

Pipeline configuration

First, you need to add a project and a Git repository that you want to test. You can synchronize Buddy with GitHub, Bitbucket or GitLab, or attach any Git repository of your choice. Adding a new Buddy project

The next step is to add a pipeline and define 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. Adding a new pipeline

To learn more about pipeline configuration, check out this article.

Now it’s time to add a build action which will run your tests. As the environment, select one of the predefined build actions. Buddy supports all popular languages, frameworks and build tools, from PHP to Node, Python, Rails, Gulp and more: Buddy build actions

In each build action you can customize the environment for your app and define the commands to run: Default Gulp build commands

Selenium is available as an attachable microservice in the 'Services' tab. You can choose either the Chrome or the Firefox driver: Adding test service

After adding the service, copy its hostname and paste it to the Selenium configuration file in your repository: Selenium service configuration

Here's an example for the 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. Configuration is very easy and requires adding a couple of environment variables in Buddy:

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: IE
SELENIUM_VERSION: 11

Creating variables

Once you add the variables, you can use them in the config file your tests. The example below shows how to do it for 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

See also