Interact with WebElements

Interact with a button <code lang="java"> package book.chapter05; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import book.chapter09.tests.DriverBase; public class InteractWithButton extends DriverBase { @BeforeMethod public void setUp() { driver.get("http://techblog.polteq.com/testshop/"); } @Test public void interactButton() […]

Finding WebElements

We have the option to find a single WebElements or create a list of multiple elements. Find a single WebElement <code lang="java"> package book.chapter05; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import book.chapter09.tests.DriverBase; public […]

Using WebDriver

Every supported browser has its own driver class implementation. This section provides examples on how to use those different browsers. In practice Firefox FirefoxDriver is part of WebDriver itself. public void startFirefoxBrowser() { WebDriver driver […]

Interact with the Browser – Introduction

This chapter reveals the Selenium WebDriver API. It will provide working examples of the most frequently used Selenium WebDriver functionality. Further references Selenium JavaDoc: http://selenium.googlecode.com/git/docs/api/java/index.html

Useful Eclipse shortcuts

I listed the most useful and frequently used shortcuts in Eclipse. Shortcut Explanation CTRL + 1 Shows quick fixes for common issues, like missing semi colons, import issues, missing declarations. CTRL + Shift + O […]

Add logging to your test

We can implement a flexible logging system, called log4j. With log4j we can make use of six levels of logging. Every log level can be treated differently. We can make the following distinction between log […]

Introducing pre and post methods

Introducing pre and post methods In the previous test script you can see that we opened and closed the browser from within the test. You can imagine that we have to do this for every […]

Execute your test

Explain why we would like to run our tests outside of eclipse. Use Eclipse to execute your tests We can use the Eclipse to run the tests, via right-click on the test class or method […]

Assert your result

TestNG provides some assertions. In this section you will see how to apply them. In practice The previous test will look like this when we add an assertion. <code lang="java"> import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import […]

Write your test

To write a tests with TestNG we have to annotate methods or classes with the @org.testng.annotations.Test annotation. Annotations on class level mean that all public methods within the class are considered test methods. Annotations on […]

Project structure

It is usefull to put the actual test scripts in the src/test/java source folder and all the framework code in the src/main/java source folder. The difference between packages / classes and methods is explained in […]

Add dependencies to your project

There are two ways of adding dependencies as well. You have to select the same method (manual or Maven) that you used to create the project in previous section. Add manual dependencies Download the Java […]

Create a project

There are two ways of creating a project. You can do it either with maven (build manager) or without. I will explain both ways in this tutorial. Normal project creation Create a Java project by […]

Setting up Eclipse

Eclipse is an Integrated Development Environment (IDE) mainly used for Java programming. Eclipse is open source and can be extended with additional plug-ins. Those plug-ins can be used through the entire software development cycle. By […]

Locating child elements

A frequently used element which can have children is the list element. There are different kinds of list elements, like: definition list <df>, ordered list <ol> and unordered list <ul>. Each list item below the […]