It’s amazing how little professional documentation there is available for Selenium integration, especially Selenium IDE.
I’m going to assume that you already have experience with Selenium IDE, TestNG, BrowserStack and Jenkins.
Selenium IDE is a Firefox plugin. There’s also Selenium Builder, which will probably be used in the future. I’m still using Selenium IDE for the moment.
Open up Selenium IDE in Firefox and do the following:
Exporting to TestNG with Selenium IDE
TestNG is a Java-based test framework. It seemed a pretty sensible one, so I just picked it.
Maven is a build manager for Java projects. Jenkins has built-in support for Maven jobs, and it’s less complex than an Ant script.
This blog post explains it quite well, so follow that first.
If it’s down, here’s a mirror: Mirror.
The files generated by Selenium IDE assume a local Selenium instance, but we want to test with BrowserStack.
In each test, you’ll want to add the following import statements:
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
In the setUp()
method, you will want to replace the lines
driver = new FirefoxDriver();
baseUrl = "YOUR_URL";
with
DesiredCapabilities capability = new DesiredCapabilities();
capability.setPlatform(Platform.WINDOWS);
capability.setCapability("build", "TestNG - Sample");
driver = new RemoteWebDriver(
new URL("http://BROWSERSTACK_USERNAME:BROWSERSTACK_PASSWORD@hub.browserstack.com/wd/hub"),
capability
);
baseUrl = "YOUR_URL";
In the runner method (usually named the same as your class), you’ll want to add
driver.get(baseUrl);
in the appropriate location (at the start, after any String
declarations).
The aforementioned blog post also covers this.
You’ll need the HTML Publisher Plugin for this. After installing it, go to your job configuration page and add it as a post-build action:
Selecting “Publish HTML reports” as a post-build action.
Click the “Add” button to add a report. You’ll see the following fields:
The available fields for publishing a report.
surefire-reports
as the reporter. To find out this directory, I SSHed to the Jenkins server and rummaged around until I found it:
Index page[s]: The page that will be served as the index.
Report title: The title of the report as it will be shown in Jenkins.
To view the checkboxes, you need to press the “Publishing options…” button (not visible in the screenshot).
Keep past HTML reports: You will definitely want this. Otherwise, only the latest report will always be kept.
Always link to last build: There’s also a link to a build on the job level. I think this just redirects that link to the latest build.
Allow missing report: Leaving this unchecked makes the build fail if the publishing process fails.
When a build finishes, you’ll now get a link to the report on the left-hand side:
The newly-available report.
Really, the only special bit here is that we’re now running everything via BrowserStack. BrowerStack currently doesn’t have a complete tutorial for proper Jenkins integration, so I thought I’d write this down to get a starting document going.