1 | Select a scripting language
With Selenium, Perfecto supports several scripting languages. To get started, do the following:
- Expand the language to work with.
- Review the prerequisites and perform any required steps.
- Download the project
.zip
file and extract it on your machine. You will modify the included test script in subsequent steps.
What language do you want to work with?

Prerequisites
Make sure you have installed the following items on your machine:
Download and extract the project
Perform the following steps to extract the project, download it to your machine, and navigate to the Java folder.
To download and extract the project:
-
Download the project.
-
Extract the project to your machine.
-
Inside the extracted project, navigate to Selenium > Java.
View the test script
The following code snippet shows the content of the included test script, Sample.java
.

package web;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Keys;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.perfecto.reportium.client.ReportiumClient;
import com.perfecto.reportium.client.ReportiumClientFactory;
import com.perfecto.reportium.model.Job;
import com.perfecto.reportium.model.PerfectoExecutionContext;
import com.perfecto.reportium.model.Project;
import com.perfecto.reportium.test.TestContext;
import com.perfecto.reportium.test.result.TestResultFactory;
import org.openqa.selenium.Point;
public class Sample {
public static void main(String[] args) throws Exception {
// System.setProperty("http.proxyHost", "127.0.0.1");
// System.setProperty("http.proxyPort", "8081");
// System.setProperty("https.proxyHost", "127.0.0.1");
// System.setProperty("https.proxyPort", "8081");
DesiredCapabilities capabilities = new DesiredCapabilities("", "", Platform.ANY);
// 1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com).
String cloudName = "<<cloud name>>";
// 2. Replace <<security token>> with your perfecto security token.
String securityToken = "<<security token>>";
capabilities.setCapability("securityToken", securityToken);
// 3. Set web capabilities.
capabilities.setCapability("platformName", "Windows");
capabilities.setCapability("platformVersion", "10");
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("browserVersion", "latest");
capabilities.setCapability("location", "US East");
capabilities.setCapability("resolution", "1024x768");
// Set other capabilities.
capabilities.setCapability("takesScreenshot", false);
capabilities.setCapability("screenshotOnError", true);
// Initialize the driver
RemoteWebDriver driver = new RemoteWebDriver(
new URL("https://" + cloudName.replace(".perfectomobile.com", "")
+ ".perfectomobile.com/nexperience/perfectomobile/wd/hub"),
capabilities);
// Setting implicit wait
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
PerfectoExecutionContext perfectoExecutionContext;
if (System.getProperty("jobName") != null) {
perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder()
.withProject(new Project("My Project", "1.0"))
.withJob(new Job(System.getProperty("jobName"),
Integer.parseInt(System.getProperty("jobNumber"))))
.withWebDriver(driver).build();
} else {
perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder()
.withProject(new Project("My Project", "1.0"))
.withWebDriver(driver).build();
}
ReportiumClient reportiumClient = new ReportiumClientFactory()
.createPerfectoReportiumClient(perfectoExecutionContext);
reportiumClient.testStart("Selenium Java Web Sample", new TestContext("selenium", "web"));
try {
WebDriverWait wait = new WebDriverWait(driver, 30);
String search = "perfectomobile";
reportiumClient.stepStart("Navigate to Google");
driver.get("https://www.google.com");
reportiumClient.stepEnd();
reportiumClient.stepStart("Search for " + search);
WebElement searchbox = wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//*[@name='q']"))));
searchbox.sendKeys(search);
searchbox.sendKeys(Keys.RETURN);
reportiumClient.stepEnd();
reportiumClient.stepStart("Verify Title");
String expectedText = "perfectomobile - Google Search";
// Adding assertions to the Execution Report. This method will not fail the test
reportiumClient.reportiumAssert(expectedText, driver.getTitle().contains(expectedText));
reportiumClient.stepEnd();
reportiumClient.testStop(TestResultFactory.createSuccess());
} catch (Exception e) {
reportiumClient.testStop(TestResultFactory.createFailure(e));
}
// Prints the Smart Reporting URL
String reportURL = reportiumClient.getReportUrl();
System.out.println("Report url - " + reportURL);
// Quits the driver
driver.quit();
}
}

Prerequisites
Make sure you have installed:
-
The latest version of Node.js 14.x appropriate for your platform
On Windows 7, the latest version of Node.js 12.x is required. Newer versions are not supported.
Download and extract the project
-
Download the project.
-
Extract the project to your machine.
-
Inside the extracted project, navigate to Selenium > Javascript > protractor.
Install node dependencies
Make sure you have installed node dependencies.
To install node dependencies:
-
Open a command line window and navigate to your protractor folder.
-
Run the following command:
Copynpm install
View the test script
The following code snippet shows the content of the included test script, sample.js
. This script includes the test steps. The configuration is located in a dedicated configuration file.

const { browser } = require("protractor");
describe('Selenium NodeJS', () => {
let EC = protractor.ExpectedConditions;
let timeout = 30000;
var search = "perfectomobile";
browser.waitForAngular();
it('Sample', function() {
browser.reportingClient.stepStart('Navigate to Google');
browser.driver.get('https://www.google.com');
browser.reportingClient.stepEnd();
browser.reportingClient.stepStart('Search for ' + search);
var q = element(by.name('q'));
browser.wait(EC.elementToBeClickable(q), timeout);
q.sendKeys(search);
browser.reportingClient.stepEnd();
browser.reportingClient.stepStart('Select ' + search);
browser.wait(EC.elementToBeClickable(q), timeout);
browser.executeScript("arguments[0].click()", q);
browser.sleep(3000);
browser.actions().sendKeys(protractor.Key.ENTER).perform();
browser.reportingClient.stepEnd();
browser.reportingClient.stepStart('Verify Title');
var expectedText = "perfectomobile - Google Search";
browser.getTitle().then(function(result) {
browser.reportingClient.reportiumAssert(expectedText.toLowerCase(), result.toLowerCase() == expectedText.toLowerCase());
});
browser.reportingClient.stepEnd();
});
//teardown on finish all
afterAll(() => {
browser.close();
});
});
View the test configuration file
For NodeJS, the configuration is available in a dedicated configuration file called web_conf.js
. The following code snippet shows the content of this file.

let perfectoReporting = require('perfecto-reporting');
var reportingClient;
exports.config = {
// 1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com).
seleniumAddress: 'https://<<cloud name>>.perfectomobile.com/nexperience/perfectomobile/wd/hub/fast',
specs: ['sample.js'],
multiCapabilities: [{
// 2. Replace <<security token>> with your perfecto security token.
securityToken: '<<security token>>',
// 3. Set web capabilities. More info: https://developers.perfectomobile.com/display/PD/Select+a+device+for+manual+testing#Selectadeviceformanualtesting-genCapGeneratecapabilities
platformName: 'Windows',
platformVersion: '10',
browserName: 'Chrome',
browserVersion: 'latest',
location: 'US East',
resolution: '1920x1080',
'goog:chromeOptions': {
w3c: false
}
}],
//default page loading timeout in ms
getPageTimeout: 10000,
//set perfecto reporter
onPrepare: async() => {
browser.ignoreSynchronization = true;
var perfectoExecutionContext;
if (process.env.jobName != null) {
perfectoExecutionContext = new perfectoReporting.Perfecto.PerfectoExecutionContext({
webdriver: browser.driver,
job: new perfectoReporting.Model.Job({
jobName: process.env.jobName,
buildNumber: parseInt(process.env.jobNumber)
}),
tags: ['jasmine', 'protractor']
});
} else {
perfectoExecutionContext = new perfectoReporting.Perfecto.PerfectoExecutionContext({
webdriver: browser.driver,
tags: ['jasmine', 'protractor']
});
}
reportingClient = await new perfectoReporting.Perfecto.PerfectoReportingClient(perfectoExecutionContext);
browser.reportingClient = reportingClient;
var perfectoReporter = {
jasmineStarted: function(suiteInfo) {
// put insome info on jasmine started
},
suiteStarted: (result) => {
// here you can add some custom code to execute when each suite is started
},
specStarted: (result) => {
// each spec will be a test in Perfecto Reporting
reportingClient.testStart(result.fullName);
},
specDone: (result) => {
// ending the test
// here we report about test end event
if (result.status === 'failed') {
// on a failure we report the failure message and stack trace
console.log('Test status is: ' + result.status);
const failure = result.failedExpectations[result.failedExpectations.length - 1];
reportingClient.testStop({
status: perfectoReporting.Constants.results.failed,
message: `${failure.message} ${failure.stack}`
});
} else {
// on success we report that the test has passed
console.log('Test status is: ' + result.status);
reportingClient.testStop({
status: perfectoReporting.Constants.results.passed
});
}
},
suiteDone: (result) => {
// when the suite is done we print in the console its description and status
console.log('Suite done: ' + result.description + ' was ' + result.status);
}
};
jasmine.getEnv().addReporter(perfectoReporter);
},
onComplete: function() {
// Output report URL
return reportingClient.getReportUrl().then(
function(url) {
console.log(`Report url - ${url}`);
}
);
},
//set jasmine options
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 1000000,
},
}

Prerequisites
Make sure you have installed the following items on your machine:
Download and extract the project
Perform the following steps to extract the project, download it to your machine, and navigate to the CSharp folder.
To download and extract the project:
-
Download the project.
-
Extract the project to your machine.
-
Inside the extracted project, navigate to Appium > Native > CSharp.
-
Launch Visual Studio.
-
In Visual Studio:
-
Click Open a project or solution.
-
Navigate to your project's
PerfectoCSharpWebSample.sln
file and open it. -
Right-click Dependencies and select Nuget.
-
Click Restore.
-
View the test script
The following code snippet shows the content of the included script, Sample.cs
.

using System;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
using Reportium.Client;
using Reportium.Model;
using Reportium.Test.Result;
namespace PerfectoCSharpWebSample
{
[TestClass]
public class Sample
{
[TestMethod]
public void WebTest()
{
DesiredCapabilities capabilities = new DesiredCapabilities();
// 1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com).
String cloudName = "<<cloud name>>";
// 2. Replace <<security token>> with your perfecto security token.
String securityToken = "<<security token>>";
capabilities.SetCapability("securityToken", securityToken);
// 3. Set web capabilities.
capabilities.SetCapability("platformName", "Windows");
capabilities.SetCapability("platformVersion", "10");
capabilities.SetCapability("browserName", "Chrome");
capabilities.SetCapability("browserVersion", "latest");
capabilities.SetCapability("location", "US East");
capabilities.SetCapability("resolution", "1024x768");
// Set other capabilities.
capabilities.SetCapability("takesScreenshot", false);
capabilities.SetCapability("screenshotOnError", true);
// Initialize the driver
RemoteWebDriver driver = new RemoteWebDriver(
new Uri("https://" + cloudName.Replace(".perfectomobile.com", "")
+ ".perfectomobile.com/nexperience/perfectomobile/wd/hub"),
capabilities);
// Setting implicit wait
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
PerfectoExecutionContext perfectoExecutionContext;
if (System.Environment.GetEnvironmentVariable("jobName") != null)
{
perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder()
.WithProject(new Project("My Project", "1.0"))
.WithJob(new Job(System.Environment.GetEnvironmentVariable("jobName"),
int.Parse(System.Environment.GetEnvironmentVariable("jobNumber"))))
.WithWebDriver(driver).Build();
}
else
{
perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder()
.WithProject(new Project("My Project", "1.0"))
.WithWebDriver(driver).Build();
}
ReportiumClient reportiumClient = PerfectoClientFactory.CreatePerfectoReportiumClient(perfectoExecutionContext);
reportiumClient.TestStart("Selenium C# Web Sample", new Reportium.Test.TestContext("selenium", "web"));
try
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
String search = "perfectomobile";
reportiumClient.StepStart("Navigate to Google");
driver.Url = "https://www.google.com";
reportiumClient.StepEnd();
reportiumClient.StepStart("Search for " + search);
IWebElement searchbox = wait.Until(ExpectedConditions.ElementToBeClickable(driver.FindElement(By.XPath("//*[@name='q']"))));
searchbox.SendKeys(search);
searchbox.SendKeys(Keys.Enter);
reportiumClient.StepEnd();
reportiumClient.StepStart("Verify Title");
String expectedText = "perfectomobile - Google Search";
// Adding assertions to the Execution Report. This method will not fail the test
reportiumClient.ReportiumAssert(expectedText, driver.Title.Contains(expectedText));
reportiumClient.StepEnd();
reportiumClient.TestStop(TestResultFactory.CreateSuccess());
}
catch (Exception e)
{
reportiumClient.TestStop(TestResultFactory.CreateFailure(e));
}
// Prints the Smart Reporting URL
String reportURL = reportiumClient.GetReportUrl();
Console.WriteLine("Report url - " + reportURL);
// Quits the driver
driver.Quit();
}
}
}

Prerequisites
Make sure you have installed the following items on your machine:
-
Python 3+:
-
On Windows: Download and install the latest Python 3.9.x version appropriate for your platform from here.
-
On Mac/Linux: Install the latest Python version from here.
On Windows 7, Python 3.8.x is required. Newer versions are not supported.
-
-
Pip package manager: Follow the official documentation to install pip.
-
Project dependencies: Run the following command from a command line window to install the project dependencies:
-
HTTPS protocol: On Mac only, run the following command from a command line window to allow Python to connect via HTTPS protocol:
where
<<Python major version>>
corresponds to the major Python version, for example 3.8.
Download and extract the project
-
Download the project.
-
Extract the project to your machine.
-
Inside the extracted project, navigate to Selenium > Python.
View the test script
The following code snippet shows the content of the test script included in the web
folder, sample.py
.

from appium.webdriver.common.mobileby import MobileBy
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
# 1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com).
cloudName = "<<cloud name>>"
capabilities = {
# 2. Replace <<security token>> with your perfecto security token.
"securityToken": "<<security token>>",
# 3. Set web capabilities. More info: https://developers.perfectomobile.com/display/PD/Select+a+device+for+manual+testing#Selectadeviceformanualtesting-genCapGeneratecapabilities
"platformName": "Windows",
"platformVersion": "10",
"browserName": "Chrome",
"browserVersion": "latest",
"location": "US East",
"resolution": "1024x768",
"takesScreenshot": False,
"screenshotOnError": True
}
# Initialize the Appium driver
driver = webdriver.Remote(
"https://" + cloudName + ".perfectomobile.com/nexperience/perfectomobile/wd/hub",
capabilities,
)
# set implicit wait time
driver.implicitly_wait(5)
timeout = 30
wait = WebDriverWait(driver, timeout)
search = "perfectomobile"
driver.get("https://www.google.com")
searchbox = wait.until(EC.presence_of_element_located((MobileBy.NAME, "q")))
searchbox.send_keys(search)
searchbox.send_keys(Keys.ENTER)
expectedText = "perfectomobile - Google Search"
assert expectedText == driver.title
# Quits the driver
driver.quit()
print("Python web Execution completed")

Prerequisites
Make sure you have installed the following items on your machine:
- The latest Ruby 2.7 version appropriate for your platform
-
The following RubyGems:
Run the following commands from a command line window:
Copygem install ffi
gem uninstall -aIx eventmachine
gem install eventmachine --platform=ruby
gem install bundler
bundle install
Download and extract the project
-
Download the project.
-
Extract the project to your machine.
-
Inside the extracted project, navigate to Selenium > Ruby.
View the test script
The following code snippet shows the content of the test script included in the web
folder, sample.rb
.

require 'perfecto-reporting'
require 'selenium-webdriver'
# 1. Replace <<cloud name>> with your perfecto cloud name (e.g. demo is the cloudName of demo.perfectomobile.com).
server_url = 'https://%s.perfectomobile.com/nexperience/perfectomobile/wd/hub' % "<<cloud name>>"
capabilities = {
# 2. Replace <<security token>> with your perfecto security token.
securityToken: '<<security token>>',
# 3. Set web capabilities. More info: https://developers.perfectomobile.com/display/PD/Select+a+device+for+manual+testing#Selectadeviceformanualtesting-genCapGeneratecapabilities
platformName: 'Windows',
platformVersion: '10',
browserName: 'Chrome',
browserVersion: 'latest',
location: 'US East',
resolution: '1024x768',
takesScreenshot: false,
screenshotOnError: true
}
# Initialize the driver
@driver = Selenium::WebDriver.for(:remote, :url => server_url, :desired_capabilities => capabilities)
# Setting implicit wait
@driver.manage.timeouts.implicit_wait = 5
# Initialize Smart Reporting
if ENV["jobName"] != nil
perfectoExecutionContext = PerfectoExecutionContext.new(PerfectoExecutionContext::PerfectoExecutionContextBuilder
.withWebDriver(@driver).withJob(Job.new(ENV["jobName"], ENV["jobNumber"].to_i)).build)
else
perfectoExecutionContext = PerfectoExecutionContext.new(PerfectoExecutionContext::PerfectoExecutionContextBuilder
.withWebDriver(@driver).build)
end
@reportiumClient = PerfectoReportiumClient.new(perfectoExecutionContext)
tec = TestContext::TestContextBuilder.build()
@reportiumClient.testStart("Selenium Ruby Web Sample", tec)
begin
timeout = 30
wait = Selenium::WebDriver::Wait.new(:timeout => timeout)
search = "perfectomobile"
@reportiumClient.stepStart('Navigate to Google');
@driver.get('https://www.google.com');
@reportiumClient.stepEnd();
@reportiumClient.stepStart('Search for ' + search);
wait.until{ @driver.find_element(:xpath => '//*[@name="q"]') }
@driver.find_element(:xpath => '//*[@name="q"]').send_keys(search)
@driver.find_element(:name => 'q').send_keys:return
@reportiumClient.stepEnd();
@reportiumClient.stepStart('Verify Title');
expectedText = "perfectomobile - Google Search";
@reportiumClient.reportiumAssert(expectedText, @driver.title === expectedText)
@reportiumClient.stepEnd();
@reportiumClient.testStop(TestResultFactory.createSuccess(), tec)
rescue Exception => exception
@exception = exception
@reportiumClient.testStop(TestResultFactory.createFailure(@exception.exception.message, @exception.exception, nil), tec)
raise exception
ensure
# Prints the report url
puts 'Report url - ' + @reportiumClient.getReportUrl
#Quits the driver
@driver.quit
puts "Ruby web Execution completed"
end