Combining assertions

0.0 00 allOf Given the following example: <code lang="java"> public void testAssert() { String s = "This is some text."; assertThat( "Assert a string starting with Tis and a string ending with ext.", s, Matchers.allOf(Matchers.startsWith("Tis"), […]

Assert collections

5.0 01 hasItems Given the following example: <code lang="java"> public void testAssert() { List<String> list = new ArrayList<String>(); list.add("test"); list.add("webdriver"); assertThat("Assert that the list contains: tedst", list, Matchers.hasItems("tedst")); } </code> Returns the following output when […]

Assert booleans

0.0 00 Given the following example: <code lang="java"> public void testAssert() { boolean b = false; assertThat("Assert boolean b against expected result: true", b, Matchers.equalTo(true)); } </code> Returns the following output when the assertion fails: […]

Assert numbers

0.0 00 equalTo Given the following example: <code lang="java"> public void testAssert() { int n = 4; assertThat("Assert that n is equal to 5", n, Matchers .equalTo(5)); } </code> Returns the following output when the […]

Assert text

0.0 00 equalTo Given the following example: <code lang="java"> public void testAssert() { String s = "This is some text."; assertThat("Assert s to match the exact text", s, Matchers .equalTo("Tis is some text.")); } </code> […]

Add dependency to your project

0.0 00 There are two ways of adding dependencies to your project, as discussed in chapter 4. You can manually add dependencies or you can add the dependency to the POM file (then it will […]

Improved assertions – Introduction

5.0 01 Matchers are the way to validate the result in your test script. Hamcrest is a Java library of Matchers objects. Hamcrest has been ported to several languages, like: Java, C++, Objective-C, Python, ActionScript […]

Accept Security Certificate Warning Internet Explorer

0.0 00 <code lang="java"> public void acceptCertificateWarning() { System.setProperty("webdriver.ie.driver", this.getClass() .getClassLoader().getResource("IEDriverServer.exe") .getPath()); WebDriver driver = new InternetExplorerDriver(); driver .navigate() .to("javascript:document.getElementById('overridelink').click()"); } </code>

Manage cookies

4.9 55 For one of the biggest beer brewers of the world it is required to enter your birthdate, before you get access the main website. This functionality is made in flash and selenium WebDriver […]

Take screenshots

5.0 01 Screenshot of page <code lang="java"> public void takeScreenshot() throws IOException { File scrFile = ((TakesScreenshot) driver) .getScreenshotAs(OutputType.FILE); String fileName = UUID.randomUUID().toString(); File targetFile = new File("target/screenshots/" + fileName + ".jpg"); FileUtils.copyFile(scrFile, targetFile); } […]

Interact with WebElements

0.0 00 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 […]

Finding WebElements

0.0 00 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 […]

Using WebDriver

0.0 00 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() { […]

Interact with the Browser – Introduction

0.0 00 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