Selenium Java Overview

Introduction

Check out the Getting Started with Selenium Java guide for a quick introduction on how to run your test cases. Also check out our Selenium overview guide to better understand how Selenium tests run on Testable in general.

This document goes into further detail on the various options provided for running Selenium Java scenarios on Testable.

Creating a Scenario

There are two ways to create a scenario:

  1. Create a new Test Case (Create Test button on the dashboard or Test Cases -> New… on the left nav), select Selenium during step 2.
  2. Go to an existing test case and click on the Scenario tab. Click the New Scenario button and select Selenium as the scenario type.

Framework

Testable supports running a Java program via a main class (i.e. Framework = None) or running your tests using JUnit or TestNG.

Source

There are several ways to load your Selenium Java scenario into the Testable platform.

  1. Upload Jar(s)/Zip(s): Upload any jar/zip files needed to run your Selenium code and indicate the name of the main class. No compilation/build step occurs on Testable in this case.
  2. Create/Edit/Upload *.java File(s): Upload all *.java files that are required or create/edit them on our website. Note that no package structure is supported in this case. All code must be in the default package and will be compiled on the test runner at test execution time.
  3. Upload Project Source as Zip File: Upload a zip file with all source code and configuration. Code is unzipped then built and run using Maven or Gradle. See below for more details.
  4. Build Project from Version Control: Project is cloned from version control onto the test runner. Code is built and run using Maven or Gradle. See below for more details.

Integration API: testable-selenium-java

The WebDriver client instance must be instantiated to communicate with the local Selenium standalone server. Testable provides a simple library to help with this. The testable-selenium-java library can be found at Maven central:

<dependency>
  <groupId>io.testable</groupId>
  <artifactId>testable-selenium-java</artifactId>
  <version>0.0.19</version>
</dependency>

An example test that uses this library:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import io.testable.selenium.TestableSelenium;

public class TestableExample {

    public static void main(String[] args) throws Exception {
        ChromeOptions options = new ChromeOptions();
        // alternatively use WebDriver driver = new RemoteWebDriver(System.getenv("SELENIUM_REMOTE_URL")); to avoid needing Testable's jar
        WebDriver driver = TestableSelenium.newWebDriver(options);
        driver.get("https://www.google.com");
        // alternatively use the standard takeScreenshot() API
        TestableSelenium.takeScreenshot(driver, "HomePage.png");
        driver.close();
    }

}

See the testable-selenium-java README for more details.

Build Step

If you choose to link your Git repository or upload a source zip your code needs to be compiled and built on the test runner. We support both Gradle and Maven to do this.

Gradle Build

Testable will use Gradle to build and run your project if it detects a build.gradle file in the project root. You can specify which tasks each virtual user will run; the default is gradle clean test. All tests that execute will be captured assertions in the test results.

All scenario parameters will be available as system properties and environment variables at runtime.

Our example project is a good place to start.

build.gradle

group 'io.testable'
version '1.0-SNAPSHOT'

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile group:'io.testable', name: 'testable-selenium-java', version: '0.0.24'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

Maven Build

Testable will use Maven to build and run your project if it detects a pom.xml file in the project root. You can specify which tasks each virtual user will run; the default is maven test. All tests that execute will be captured assertions in the test results.

All scenario parameters will be available as system properties and environment variables at runtime.

Our example project is a good place to start.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>io.testable</groupId>
    <artifactId>selenium-java-example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>io.testable</groupId>
            <artifactId>testable-selenium-java</artifactId>
            <version>0.0.19</version>
        </dependency>
    </dependencies>
</project>

If you have a Maven settings.xml file, it can be automatically installed at ${user.home}/.m2/settings.xml on each test runner when it runs your tests by adding it via Org Management => Settings => Package Managers => Maven settings.xml File. It will apply to all tests run within your Organization.

If both a build.gradle and pom.xml file are detected in your project root folder, Gradle takes precedence.

Testable APIs: screenshots and more

The testable-selenium-java library provides Testable APIs for:

  1. Screenshots
  2. Custom metrics
  3. Logging
  4. Read from CSV

All these APIs will work when run locally as well. See the testable-selenium-java README for more details.