Serenity BDD is an open-source library that helps you write cleaner and more maintainable automated acceptance and regression tests faster. Serenity also uses the test results to produce illustrated, narrative reports that document and describe what your application does and how it works.
Below are code samples that demonstrate how to add Applitools Eyes visual validations to your Serenity tests and adding the test results to your Serenity reports.
The most important thing to understand when working with any Selenium wrapper tool (like Serenity) is that the driver we are using is not the actual WebDriver but a wrapped version of it. The challenge is that they sometimes fail to implement all methods of the WebDriver, especially methods that are required by Eyes for a successful test run. This means we need to find a way to extract the driver from the framework and pass it to Eyes.
Extract the WebDriver
Here is an example of how we can grab the WebDriver from Serenity
((WebDriverFacade) navigateTo.duckDuckGoHomePage.getDriver()).getProxiedDriver();
Extract the AppiumDriverProvider
When testing a native mobile app with Serenity we need to get the actual IOSDriver or AndroidDriver which are managed by the AppiumDriverProvider class which implements the DriverProvider interface.
Adding Applitools Test Results To Serenity Reports
TestResultsSummary myTestResults = runner.getAllTestResults(false);
Serenity.recordReportData().withTitle("Applitools Report").andContents(myTestResults.toString());
Complete Example
@Given("^(?:.*) is on the DuckDuckGo home page")
public void i_am_on_the_DuckDuckGo_home_page() {
EyesRunner runner = new ClassicRunner();
// Configure Eyes
eyes = new Eyes(runner);
Configuration sconf = new Configuration();
sconf.setAppName("My App Name");
sconf.setTestName("My Test Name");
sconf.setApiKey(YOUR_APPLITOOLS_API_KEY_GOES_HERE);
sconf.setViewportSize(new RectangleSize(1200, 600));
sconf.setForceFullPageScreenshot(true);
sconf.setStitchMode(StitchMode.CSS);
eyes.setConfiguration(sconf);
navigateTo.theDuckDuckGoHomePage();
// Open connection to Eyes server
eyes.open(((WebDriverFacade) navigateTo.duckDuckGoHomePage.getDriver()).getProxiedDriver());
// Take visual validation
eyes.check(Target.window().fully());
// Close connection to Eyes server
eyes.closeAsync();
// Get test results from Eyes
TestResultsSummary myTestResults = runner.getAllTestResults(false);
// Push test results into Serenity report
Serenity.recordReportData().withTitle("Applitools Report").andContents(myTestResults.toString());
}
My code examples are based on this repo
Comments
0 comments
Please sign in to leave a comment.