Selenified Test Framework

Max Saperstone, https://www.coveros.com/

Selenified is an open source test framework that provides mechanisms for simply testing applications at multiple tiers while easily integrating into DevOps build environments. Selenified offers traceable reporting for both web and API testing, wraps and extends Selenium calls to more appropriately handle testing errors, and supports testing over multiple browsers in parallel, either locally or in the cloud. It can be a great starting point for building or improving test automation in your organization.

Web Site: https://www.coveros.com/products/selenified/

Version Tested: 3.2.0, June-July 2019

License & Pricing: Apache License 2.0

Support: https://github.com/Coveros/selenified/issues

What makes Selenified different?

Selenified is Java-based framework for testing at web and API level thatproduces detailed traceable reporting with screenshots that can be used to debug code and tests.

It wraps Selenium calls to more appropriately handle missing or slow to load page elements

It supports simply running multiple tests over different browsers in parallel On local browsers Through Selenium Grid Via SauceLabs connect

It allows running tests through proxy server

Selenium is supported on major build tools Maven Gradle Ant/Ivy



(click on figure to enlarge)

Installation:

Selenified can easily be run in a new or existing project in a matter of minutes by adding the selenified.jar to your project then beginning to write your test cases. If you are using a build tool, simply add the jar as a dependency.

Maven

Update your pom.xml file to include (or add the dependency block to your current dependencies)

<dependencies> <dependency> <groupId>com.coveros</groupId> <artifactId>selenified</artifactId> <version>3.2.0</version> <scope>test</scope> </dependency> </dependencies>

Ant

Update your ivy.xml file to include (or add the `dependency` block to your current dependencies)

<dependencies> <dependency org="com.coveros" name="selenified" rev="3.2.0" /> </dependencies>

Gradle

Update your build.gradle file to include (or add the testCompile line to your current dependencies)

dependencies { testCompile group: 'com.coveros', name: 'selenified', version: '3.2.0' }

Writing Tests

It is suggested to setup your functional Selenified tests as integration tests, following typical java structure, in the src/test/java folder, in packages if desired. A sample file is included below, which will compile and run if you create the file src/test/java/ReadmeSampleIT.java, and paste in the contents.

@BeforeClass(alwaysRun = true)

public void beforeClass(ITestContext test) {

// set the base URL for the tests here

setAppURL(this, test, "https://www.coveros.com/");

}

@DataProvider(name = "coveros search terms", parallel = true)

public Object[][] DataSetOptions() {

return new Object[][]{new Object[]{"python"},

new Object[]{"perl"}, new Object[]{"bash"},};

}

@Test(groups = {"sample", "coveros"}, description = "A sample selenium test to check a title")

public void sampleTest() {

// use this object to manipulate the app

App app = this.apps.get();

// verify the correct page title

app.azzert().titleEquals("Coveros | Bringing together agile and security to deliver superior software");

// verify no issues

finish();

}

@Test(dataProvider = "coveros search terms", groups = {"sample", "coveros"},

description = "A sample selenium test using a data provider to perform a search")

public void sampleTestWDataProvider(String searchTerm) {

// use this object to manipulate the app

App app = this.apps.get();

// find the search box element and create the object

Element searchBox = app.newElement(Locator.NAME, "s");

//perform the search and submit

searchBox.type(searchTerm);

searchBox.submit();

//wait for the page to return the results

app.newElement(Locator.ID, "recent-posts-4").waitForState().present();

// verify the correct page title

app.azzert().titleEquals("You searched for " + searchTerm + " - Coveros");

// verify no issues

finish();

}

@Test(groups = {"sample", "service", "coveros", "https"}, description = "A sample web services test to verify the response code")

public void sampleServicesSearchTest() {

HashMap<String, Object> params = new HashMap<>();

params.put("s", "Max+Saperstone");

// use this object to verify the app looks as expected

Call call = this.calls.get();

// retrieve the zip code and verify the return code

call.get("", new Request().setUrlParams(params)).azzert().equals(403);

// verify no issues

finish();

}

Test Execution

To execute these tests, either do that directly from your IDE, or you can execute the below commands.

Maven

If following the setup indicated, you will need to use the failsafe plugin in order to execute the tests. Update your pom.xml file to include

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>3.0.0-M3</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin>

Then from the command line run

mvn verify

More information about Maven execution can be found here

Ant

If following the setup indicated, you will need to setup your test files in a testng block. Update your build.xml file to include

<taskdef name="testng" classname="org.testng.TestNGAntTask"> <classpath location="lib/testng-6.14.3.jar" /> </taskdef> <target name="testng" depends="compile"> <testng classpathref="classpath" outputDir="./target" haltOnFailure="true" verbose="2"> <classfileset dir="./target/classes" includes="**/*IT.class" /> </testng> </target>

Additionally, you will need to add a target to execute your tests. Update your build.xml file to include

<target name="test" depends="testng" description="Run integration tests in parallel"> <java classpathref="classpath" classname="org.testng.TestNG" failonerror="true" /> </target>

Then from the command line run

ant test

More information about Ant execution can be found here

Gradle

If following the setup indicated, you will need to add a task to execute your tests. Update your build.gradle file to include

task selenified(type:Test) { useTestNG() {} }

Then from the command line run

gradle selenified

More information about Gradle execution can be found here

Viewing Test Results

After writing and running the Selenified tests you can view the test results by navigating to the newly created output folder within the framework directory. This will be either target if run with Gradle or Maven, target-output if run through an IDE, or a custom directory if run with Ant. Navigate to the folder of the runner used to execute the tests, and locate the reports.html file. Open this file in a browser. This will give an overview of the tests run, showing the number of tests executed, passed, skipped and failed. Additionally, each test is listed in a table, with high-level information about it.

(click on figure to enlarge)

Links to detailed reports are provided, for more information on each step run. Clicking on each of these links will display a step by step procedure about what was run, in addition to details about the test. These steps and information are also very useful for debugging. They will alert if elements are missing, locators are bad, or anything else. Both locators and associated IDs are listed to make fixing tests or the app easier.

(click on figure to enlarge)

Additionally, a JUnit XML results file is produced. This is great for storing results/metrics within Jenkins, or other CI tools and tracking trends. Additionally, consider archiving testing results to go along with these trending results.

Want to see more details? Check out the README file. You can also checkout the documentation here.

Related Resources

This article was originally published in August 2019

Click here to view the complete list of tools reviews