Compatibility
Util now, sentinela is available for Java.
How does it work?
- Mark some points where Sentinela will perform the tests
- Run your project as usual
- Every time point is reached Sentinela comes in
- Take a print and save in a new execution history
- Compares the result with a baseline. (if exists)
- Make tests results report
Basic Usage
This section demonstrates basic methods that you will be using with this library.
Initializing Sentinela
We can initialize sentinela in many ways.Sentinela(WebDriver driver, String pathImgs, String pathReport, int imgWidth, int imgHeight, String baseLineName, LanguageCodes lc)
Sentinela(WebDriver driver, String pathImgs, String pathReport, int imgWidth, int imgHeight, LanguageCodes lc)
Sentinela(WebDriver driver, String pathImgs, String pathReport, int imgWidth, int imgHeight, String baseLineName)
Sentinela(WebDriver driver, String pathImgs, String pathReport, int imgWidth, int imgHeight)
Sentinela()
- driver - Instance of selenium webdriver from your project.
- pathImgs - Path where sentinela will go generate the images prints.
- pathReport - Path where will go generate test result report.
- imgWidth - Resolution width(in pixels). Attetion, this will be the width of all images created.
- imgHeight - Resolution height(in pixels).
- baseLineName - Name of baseLine, in cases where it is necessary to have more than one baseLine.
- lc - Enum language code. Sentinela report and directory structure is available in more than one language. For use, import the Enum LanguageCodes from sentinela.
- EN_US - English (United States). Default value, no need report.
- PT_BR - Portuguese (Brazil).
- ZH_TW - Chinese (Taiwan).
Instance of sentinela example
To create an sentinela instance, working with resolution 1920 x 1080.Sentinela(WebDriver driver, String pathImgs, String pathReport, int imgWidth, int imgHeight)
//Usage
Sentinela sentinela = new Sentinela(driver, "C:\\testRegression\\testImages", "C:\\testRegression\\testReport\\", 1920, 1080);
Performing Sentinela validate
Sentinela has the following validate available methods.validate(String imageName)
validate(WebElement element, String imageName)
validate(List<WebElement> elements, String imageName)
validate(String imageName, String testDetails)
validate(WebElement element, String imageName, String testDetails)
validate(List<WebElement> elements, String imageName, String testDetails)
- imageName - It is very important to choose this name, because this will be unique identifier(that is, There can´t be another name on the same instance of sentinela or it will be orverwritten).
- element - WebElement from your driver (can be field, button, label, anything you have mapped).
- elements - Java list of webelement. See element.
- testDetails - Information to be shown on the test report.
Validate a full window broswer example
After you have a sentinela instance created, call the method validate only with the argument: imageName or imageName and testDetailsvalidate(String imageName)
validate(String imageName, String testDetails)
//Usage
sentinela.validate("checkLayoutLogin");
sentinela.validate("checkLayoutLogin","check access login layout.");
Generate Sentinela report
When all the tests are finished, should be call sentinela generate report.generateReport()
//Usage
sentinela.generateReport();
No arguments is necessary.
Know if any differences were found (uselful for sending notfications like JUnit Assert)
Sentinela has the method "isDiff".isDiff()
//Usage
sentinela.isDiff();
The return is a boolean. True if differences were found and false if not.
Full example
Complete example on google search webpage.import java.util.List;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import br.com.saraivaugioni.sentinela.main.Sentinela;
public class Teste {
public static void main(String[] args) {
// Webdriver driver
System.setProperty("webdriver.gecko.driver", "driver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
// Map webdriver elements
// Google
//Single elements
driver.get("https://www.google.com");
WebElement logoGoogle = driver.findElement(By.id("hplogo"));
WebElement buttonSearchGoogle = driver.findElement(By.name("btnK"));
WebElement fieldSearch = driver.findElement(By.id("lst-ib"));
//List of welbelements
List<WebElement> googleElements = driver.findElements(By.className("list"));
googleElements.add(logoGoogle);
googleElements.add(buttonSearchGoogle);
googleElements.add(fieldSearch);
// -------------------API USE EXAMPLE--------------------//
// Make API instance, set image path and gen report path
// and last a resolution to work.
Sentinela sentinela = new Sentinela(driver, "C:\\testRegression\\testImages", "C:\\testRegression\\testReport\\", 1920, 1080);
// Validate a webelement
sentinela.validate(logoGoogle, "logo_google");
// Validate a webelements list
sentinela.validate(googleElements, "elementsGoogle");
// Validate a full page
sentinela.validate("screen_google");
// Gen final report
sentinela.generateReport();
driver.quit();
Assert.assertFalse(sentinela.isDiff());
}
}