Using .csv files with serenity is straight forward.
If you are about to start a new Maven project and let us assume everything is new to you, the following few steps will get you up and running.
Spend some time to understand what you are copying and pasting just to get a better understanding of what it is your doing.
First your pom file
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>netbal.co.za</groupId> <artifactId>a</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Google test</name> <properties> <version.serenity>1.0.47</version.serenity> <version.serenity.maven>1.0.25</version.serenity.maven> <version.junit>4.11</version.junit> <webdriver.driver>firefox</webdriver.driver> <jdk.source>1.8</jdk.source> <jdk.target>1.8</jdk.target> <jdk.debug>true</jdk.debug> <jdk.optimize>false</jdk.optimize> </properties> <dependencies> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>core</artifactId> </dependency> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-junit</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <configuration> <includes> <include>**/requirements/**/*.java</include> </includes> <systemProperties> <webdriver.driver>${webdriver.driver}</webdriver.driver> </systemProperties> </configuration> <executions> <execution> <goals> <goal>integration-test</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>net.serenity-bdd.maven.plugins</groupId> <artifactId>serenity-maven-plugin</artifactId> <dependencies> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>core</artifactId> <version>${version.serenity}</version> </dependency> </dependencies> <executions> <execution> <id>serenity-reports</id> <phase>post-integration-test</phase> <goals> <goal>aggregate</goal> </goals> </execution> </executions> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> <configuration> <forkMode>once</forkMode> <argLine>-enableassertions</argLine> </configuration> </plugin> <plugin> <groupId>net.serenity-bdd.maven.plugins</groupId> <artifactId>serenity-maven-plugin</artifactId> <version>${version.serenity.maven}</version> </plugin> </plugins> </pluginManagement> </build> <dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${version.junit}</version> <scope>test</scope> </dependency> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>core</artifactId> <version>${version.serenity}</version> </dependency> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-junit</artifactId> <version>${version.serenity}</version> </dependency> </dependencies> </dependencyManagement> </project>
Create your package structure
Create your Classes
Write one or two paragraphs describing your product or services. To be successful your content needs to be useful to your readers.
Start with the customer – find out what they want and give it to them.
GoogleLandingPageTest class
import net.serenitybdd.junit.runners.SerenityParameterizedRunner; import net.thucydides.core.annotations.Managed; import net.thucydides.core.annotations.ManagedPages; import net.thucydides.core.annotations.Steps; import net.thucydides.core.pages.Pages; import net.thucydides.junit.annotations.UseTestDataFrom; import netbal.test.console.steps.UserSteps;
import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.WebDriver;
@RunWith(SerenityParameterizedRunner.class) @UseTestDataFrom(value = “src/test/resources/testdata.csv”) public class GoogleLandingPageTest { @Managed(driver = “firefox”, uniqueSession = true)
WebDriver driver;
@ManagedPages(defaultUrl = “https://www.google.co.za”)
public Pages pages;
private String searchItem;
public String getSearchItem() { return searchItem; } public void setSearchItem(String searchItem) {
this.searchItem = searchItem;
}
/*@Qualifier
public String qualifier() {
return searchItem;
}*/
@Steps
UserSteps user;
@Test
public void should_login_and_logout_user_successfully() {
user.openLandingPage();
user.searchForStuffOnGoogle(searchItem);
}
UserSteps class
import net.thucydides.core.annotations.Step; import net.thucydides.core.pages.Pages; import net.thucydides.core.steps.ScenarioSteps; import netbal.test.console.pages.LandingPage;
public class UserSteps extends ScenarioSteps {
public UserSteps(Pages pages) {
super(pages);
} /**
*
*/
private static final long serialVersionUID = 1L;
LandingPage landingPage;
@Step
public void openLandingPage(){
landingPage.open();
}
@Step
public void searchForStuffOnGoogle(String searchItem){
landingPage.findNetbal21Blog(searchItem);
}
}
LandingPage class
import org.openqa.selenium.WebElement; import net.serenitybdd.core.annotations.findby.FindBy; import net.thucydides.core.annotations.DefaultUrl; import net.thucydides.core.pages.PageObject; @DefaultUrl("https://www.google.co.za") public class LandingPage extends PageObject { @FindBy(id = "lst-ib") //this ID might change from time to time so if elemet not found just change the ID WebElement searchTxt; public void findNetbal21Blog(String searchItem){ element(searchTxt).sendKeys(searchItem); } }
testdata.csv file should look like this
SEARCH ITEM, why am I working, play more golf .co.za,
and should be placed in your resources folder.
Serenity Report
If Serenity is set up correctly in your POM, this test should run twice.
So now Run the test!!!
Your report should now look like this: