ExtWebDriver inherits all the wonderful concept of WebDriver. It allows you to test web applications and verify they are working as expected. You have the flexibility to run your tests against multiple browsers using your favorite testing framework as well IDE. The value of ExtWebDriver is to bring better experience through features such as the extended API, widget library, and session management. This guide will help you write your first test using ExtWebDriver.
The first thing you need to do is to create a new Java project in your favorite IDE. Our recommendation is to create a Java maven project so that you can easily manage your dependencies. Once you create the project, you can add the ExtWebDriver maven dependency to your pom file and you should have all the required libraries.
POM Snippet:
<dependency>
<groupId>org.finra.jtaf</groupId>
<artifactId>jtaf-extwebdriver</artifactId>
<version>1.5.5</version>
</dependency>
Now that you have all the required libraries to use ExtWebDriver, you need to choose your testing framework. Let's try using JUnit 4. To do this, first you need to add JUnit 4 maven dependency to your pom file similar to how you added ExtWebDriver maven dependency. Please refer to this link to add JUnit 4 maven dependency.
Now you are ready to write some code! Let's create a test which performs a simple scenario on this website. We will open up the ExtWebDriver homepage and validate 'Learn More' button exists, click on it and finally verify that we have landed on the correct page.
package org.finra.jtaf.extwebdriver.example;
import org.finra.jtaf.ewd.ExtWebDriver;
import org.finra.jtaf.ewd.session.SessionManager;
import org.finra.jtaf.ewd.widget.IButton;
import org.finra.jtaf.ewd.widget.element.html.Button;
import org.junit.Assert;
import org.junit.Test;
/**
* Tests for ExtWebDriver homepage
*/
public class ExtWebDriverHomeTest {
@Test
public void testLearnMoreButton() throws Exception {
// Get a new ExtWebDriver session
ExtWebDriver ewd = SessionManager.getInstance().getNewSession();
// Open ExtWebDriver home page
ewd.open("http://finraos.github.io/JTAF-ExtWebDriver");
// Create Button object
IButton b = new Button("//*[contains(@class,'btn') and text()='Learn more ยป']");
// Wait for existence of the button
b.waitForElementPresent();
// Click on button
b.click();
// Verify the page title
Assert.assertEquals("Extensions for WebDriver - Getting Started", ewd.getTitle());
}
}
That's it! You can simply run your test and it will execute your test scenario. You will notice that it is very easy to start a new browser session by using the SessionManager. Also, it is very easy to interact with elements, such as a Button in this example, which is included within the Widget Library. One thing to note is that you will not be able to see the actual browser running your scenario because ExtWebDriver will use HtmlUnitDriver by default. With a small tweak, you can run against a different browser.
// Get a new ExtWebDriver session
ExtWebDriver ewd = SessionManager.getInstance().getNewSession("client", "client.properties");
Leaving everything the same, all you need to do is provide a file name to getNewSession() method. The file needs to be a resource to the project and you need to have one property configured:
browser=firefox
Now if you run your test, you will see a Firefox browser start up and running your test scenario. You can also run against other browsers which are supported by WebDriver. Please refer to Client Properties page for other useful configurations.