2. Agenda:
•
•
•
•
•
•
•
1. Introduction in JBehave
2. Behavior driven development
3. Selenium as a tool for automation testing
4. How to create new test scenario
5. The page objects pattern
6. Good and bad practices
7. Running test scenarios through maven
4. Behavior driven development
• Behavior-driven development is a software development
process based on test-driven development (TDD)
5. Selenium
• Selenium is a suite of tools to automate web browsers across
many platforms.
• Selenium IDE is a complete integrated development
environment (IDE) for Selenium tests.
• Selenium Remote Control (RC) is a server, written in Java, that
accepts commands for the browser via HTTP.
• Selenium WebDriver is the successor to Selenium RC.
6. Create new test
• Write new test scenario on the Gherkin like:
Scenario: “describes what should be passed”
Given: “given something”
When: “something happened”
Then:
“should be something”
• Implementation for this scenario
@Given ("given something")
public void givenSomething() {
}
@When ("something happened")
public void whenSomethingHappened() {
}
@Then ("should be something")
public void thenShouldBeSomething() {
}
7. The page objects pattern
• More popular in test automation;
• Page object is an object-oriented;
• Serves as an interface to a page;
Web page
Java class
Enhancing test maintenance;
Reducing code duplication;
Test cases
8. Good and bad practices
public class GoogleLoginSteps {
private Selenium selenium;
public void googleLoginSteps() {
selenium.open("google.com");
selenium.waitForPageToLoad("10000");
selenium.click("id=gb_70");
selenium.type("id=Email", "wrong@gmail.com");
selenium.type("id=Passwd", "wrong password");
selenium.click("id=signIn");
selenium.waitForPageToLoad("10000");
assertTrue(selenium.isElementPresent("errormsg_0_Passwd"));
}
}
9. Running test scenarios through maven
Maven is a build automation tool used primarily for Java projects
Basic concepts, examples:
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-core</artifactId>
<version>3.4</version>
</dependency>
<execution>
<id>unpack-view-resources</id>
<phase>process-resources</phase>
<goals>
<goal>unpack-view-resources</goal>
</goals>
</execution>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>1.5</compilerVersion>
</configuration>
</plugin>
mvn clean install