What is ?
Basically, this report of your scenarios/features:
Project Structure
+ src
+ main
+ java
+ com.mycompany.pages
- HomePage.java
+ test
+ java
+ com.mycompany.pages
+ requirements
- Application.java
+ steps
- EndUserSteps.java
- SearchByKeywordStoryTest.java
+ stories
+ com.wakaleo.webtests.wikipedia
- SearchingForCats.story
Starting
If you have maven installed, go to the terminal or IDE and:
– Create a new project:
mvn archetype:generate -Dfilter=thucydides
– Open your settings.xml and write:
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<pluginGroups>
<pluginGroup>net.thucydides.maven.plugins</pluginGroup>
</pluginGroups>
</settings>
– In the pom.xml
file, update the default JUnit dependency to at least 4.11
– Add a dependency to hamcrest-all
and thucydides-junit
. Thucydides uses SLF4J for its logging, so add an SLF4J implementation (e.g. slf4j-simple) as well.
– If you are not using Maven 3, make sure you configure the Maven compiler plugin to use Java 5.
– Finally, add the thucydides-maven-plugin
, which provides the Thucydides reporting services. The resulting pom.xml
file should look something like this:
<groupId>com.wakaleo.webtests.wikipedia</groupId>
<artifactId>wikipediawebtests</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>wikipediawebtests</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<thucydides.version>0.9.228</thucydides.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>net.thucydides</groupId>
<artifactId>thucydides-junit</artifactId>
<version>${thucydides.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>net.thucydides.maven.plugins</groupId>
<artifactId>maven-thucydides-plugin</artifactId>
<version>${thucydides.version}</version>
</plugin>
</plugins>
</build>
</project>
– Run this command to be sure that everything it is running correctly: mvn package
– Create a new class contains the list of “features” that make up the application, and stories related to each feature. These stories are not the tests themselves – rather they are used to model the application requirements.
– Writing your first test:
public class Application {
@Feature
public class Search {
public class SearchByKeyword {}
public class SearchByAnimalRelatedKeyword {}
public class SearchByFoodRelatedKeyword {}
public class SearchByMultipleKeywords {}
public class SearchForQuote{}
}
@Feature
public class Backend {
public class ProcessSales {}
public class ProcessSubscriptions {}
}
@Feature
public class Contribute {
public class AddNewArticle {}
public class EditExistingArticle {}
}
}
– Create a new test class in a package of your choice calledSearchByKeywordStoryTest.java
@Story(SearchBySingleKeyword.class)
@RunWith(ThucydidesRunner.class)
public class SearchByKeywordStoryTest {
@Managed(uniqueSession = true)
public WebDriver webdriver;
@ManagedPages(defaultUrl = "http://www.wikipedia.com")
public Pages pages;
@Steps
public EndUserSteps endUser;
@Test
public void should_display_article_about_cats() {
endUser.is_on_the_wikipedia_home_page();
endUser.searches_by_keyword("cats");
endUser.should_see_article_with_title("Cat - Wikipedia, the free
encyclopedia");
PS: @Managed
and @ManagedPages
are required to take care of our page objects.
– Create a step library called EndUserSteps
:
public class EndUserSteps extends ScenarioSteps {
public EndUserSteps(Pages pages) {
super(pages);
}
@Step
public void searches_by_keyword(String keyword) {
enters(keyword);
performs_search();
}
@Step
public void enters(String keyword) {
}
@Step
public void performs_search() {
}
@Step
public void should_see_article_with_title(String title) {
}
@Step
public void is_on_the_wikipedia_home_page() {
}
}
– You will need create your own classes inside of each Step.
– Run the command to generate your report: mvn verify thucydides:aggregate
– Your report will be in target/thucydides directory, open the home.html
If you want to see a complete model, go to this link.
If you want to learn more about maven commands, go to this link.
If you want to see the post of John Smart with his complete example, go to this link.
Thank you guys 🙂
Sources:
https://github.com/thucydides-webtests/thucydides/wiki/Getting-Started
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
cool article, I am going to share it on http://www.QATestingTools.com, with your permission, unless you will tell me otherwise.
No, feel free to share 🙂
I share a lot of things here as well !
Thanks, can you also share my new comparison table at http://www.qatestingtools.com/compare-bdd-testing-tools, which is missing the some information, on the other tools.?
Thank you in advance
Hi, I think I already shared your table ! I used a lot 🙂
This is an updated table, with 14 BDD tools inside
Huum ok, I will update the post with your table 🙂