Selenium WebDriver 3 Practical Guide
eBook - ePub

Selenium WebDriver 3 Practical Guide

End-to-end automation testing for web and mobile browsers with Selenium WebDriver, 2nd Edition

  1. 280 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Selenium WebDriver 3 Practical Guide

End-to-end automation testing for web and mobile browsers with Selenium WebDriver, 2nd Edition

About this book

Real-world examples of cross-browser, mobile, and data-driven testing with all the latest features of Selenium WebDriver 3

Key Features

  • Unlock the full potential of Selenium to test your web applications
  • Use Selenium Grid for faster, parallel running, and cross-browser testing
  • Test iOS and Android Apps with Appium

Book Description

Selenium WebDriver is an open source automation tool implemented through a browser-specific driver, which sends commands to a browser and retrieves results. The latest version of Selenium 3 brings with it a lot of new features that change the way you use and setup Selenium WebDriver. This book covers all those features along with the source code, including a demo website that allows you to work with an HMTL5 application and other examples throughout the book.

Selenium WebDriver 3 Practical Guide will walk you through the various APIs of Selenium WebDriver, which are used in automation tests, followed by a discussion of the various WebDriver implementations available. You will learn to strategize and handle rich web UI using advanced WebDriver API along with real-time challenges faced in WebDriver and solutions to handle them. You will discover different types and domains of testing such as cross-browser testing, load testing, and mobile testing with Selenium. Finally, you will also be introduced to data-driven testing using TestNG to create your own automation framework.

By the end of this book, you will be able to select any web application and automate it the way you want.

What you will learn

  • Understand what Selenium 3 is and how is has been improved than its predecessor
  • Use different mobile and desktop browser platforms with Selenium 3
  • Perform advanced actions, such as drag-and-drop and action builders on web page
  • Learn to use Java 8 API and Selenium 3 together
  • Explore remote WebDriver and discover how to use it
  • Perform cross browser and distributed testing with Selenium Grid
  • Use Actions API for performing various keyboard and mouse actions

Who this book is for

Selenium WebDriver 3 Practical Guide is for software quality assurance/testing professionals, software project managers, or software developers interested in using Selenium for testing their applications. Prior programming experience in Java is necessary.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

The PageObject Pattern

So far, we have seen various APIs of WebDriver and learned how to use them to accomplish various actions on the web application we have been testing. We created a number of tests that use these APIs and are executed continuously to validate the application. However, as your test suite grows, the complexity of your tests and code will also grow. This becomes a challenge, with respect to the maintainability of your scripts and code. You will need to design a maintainable, modular, and reusable test code that will scale as you add more test coverage. In this chapter, we will explore the PageObject pattern to build a highly maintainable test suite. We will cover the following topics:
  • What is the PageObject pattern design?
  • Good practices for designing PageObjects
  • Extensions to the PageObject pattern
  • An end-to-end example
A decently written test script would work just fine, as long as the target web application doesn't change. But once one or more pages in your web application change, as a test-script developer, you shouldn't be in a position where you have to refactor your test scripts in a hundred different places. Let's understand this statement better with the help of an example. We will try to go through this chapter by working on a WordPress blog. Before we start, I would like you to create a WordPress blog (http://wordpress.com/about) or use one of your existing ones.

Creating test cases for our WordPress blog

Here, we are using a WordPress blog: http://demo-blog.seleniumacademy.com/wp/. Let's create three test cases for it before we start talking about the PageObject pattern.

Test case 1 – adding a new post to our WordPress blog

The following test script will log into the Admin portal of our WordPress blog and add a new blog post:
@Test
public void testAddNewPost() {
WebElement email = driver.findElement(By.id("user_login"));
WebElement pwd = driver.findElement(By.id("user_pass"));
WebElement submit = driver.findElement(By.id("wp-submit"));
email.sendKeys("admin");
pwd.sendKeys("$$SUU3$$N#");
submit.click();

// Go to AllPosts page
driver.get("http://demo-blog.seleniumacademy.com/wp/wp-admin/edit.php");

// Add New Post
WebElement addNewPost = driver.findElement(By.linkText("Add New"));
addNewPost.click();

// Add New Post's Content
WebElement title = driver.findElement(By.id("title"));
title.click();
title.sendKeys("My First Post");

driver.switchTo().frame("content_ifr");
WebElement postBody = driver.findElement(By.id("tinymce"));
postBody.sendKeys("This is description");
driver.switchTo().defaultContent();

// Publish the Post
WebElement publish = driver.findElement(By.id("publish"));
publish.click();
}
The following is the sequence of steps that the preceding code performs:
  1. Log into the WordPress Admin portal.
  2. Go to the All Posts page.
  3. Click on the Add New post button.
  4. Add a new post by providing the title and description.
  5. Publish the post.

Test case 2 – deleting a post from our WordPress blog

The following test script will log into our WordPress blog and delete an existing post:
@Test
public void testDeleteAPost() {
WebElement email = driver.findElement(By.id("user_login"));
WebElement pwd = driver.findElement(By.id("user_pass"));
WebElement submit = driver.findElement(By.id("wp-submit"));
email.sendKeys("admin");
pwd.sendKeys("$$SUU3$$N#");
submit.click();

// Go to AllPosts page
driver.get("http://demo-blog.seleniumacademy.com/wp/wp-admin/edit.php");

// Click on the post to be deleted
WebElement post = driver.findElement(By.linkText("My First Post"));
post.click();

// Delete Post
WebElement publish = driver.findElement(By.linkText("Move to Trash"));
publish.click();
}
The following is the sequence of steps that the preceding test script follows to delete a post:
  1. Log into the WordPress Admin portal.
  2. Go to the All Posts page.
  3. Click...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Introducing WebDriver and WebElements
  7. Different Available WebDrivers
  8. Using Java 8 Features with Selenium
  9. Exploring the Features of WebDriver
  10. Exploring Advanced Interactions of WebDriver
  11. Understanding WebDriver Events
  12. Exploring RemoteWebDriver
  13. Setting up Selenium Grid
  14. The PageObject Pattern
  15. Mobile Testing on iOS and Android using Appium
  16. Data-Driven Testing with TestNG
  17. Assessments
  18. Other Books You May Enjoy

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Selenium WebDriver 3 Practical Guide by Unmesh Gundecha, Satya Avasarala in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in Java. We have over one million books available in our catalogue for you to explore.