Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Selenium Testing Tools Cookbook
Selenium Testing Tools Cookbook

Selenium Testing Tools Cookbook: Unlock the full potential of Selenium WebDriver to test your web applications in a wide range of situations. The countless recipes and code examples provided ease the learning curve and provide insights into virtually every eventuality.

eBook
$9.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Selenium Testing Tools Cookbook

Chapter 2. Working with Selenium API

In this chapter, we will cover:

  • Checking an element's text

  • Checking an element's attribute values

  • Checking an element's CSS values

  • Using Advanced User Interactions API for mouse and keyboard events

  • Performing double-click on an element

  • Performing drag-and-drop operations

  • Executing JavaScript code

  • Capturing screenshots with Selenium WebDriver

  • Capturing screenshots with RemoteWebDriver/Grid

  • Maximizing the browser window

  • Automating dropdowns and lists

  • Checking options in dropdowns and lists

  • Checking selected options in dropdowns and lists

  • Automating radio buttons and radio groups

  • Automating checkboxes

  • Controlling a Windows process

  • Reading a Windows registry value from Selenium WebDriver

  • Modifying a Windows registry value from Selenium WebDriver

Introduction


Selenium WebDriver implements a very comprehensive API for working with web elements, Advanced User Interactions, executing JavaScript code, and support for various types of controls such as List, Dropdown, Radio Button, and Checkbox.

In this chapter, we will explore how these APIs can be used to build simple to complex test steps. This chapter will also help in overcoming some common issues while building tests with Selenium WebDriver. The chapter examples are created with Selenium WebDriver Java bindings. The sample code for this chapter contains some of these recipes implemented with C#, Ruby, and Python.

Checking an element's text


While testing a web application, we need to verify that elements are displaying correct values or text on the page. Selenium WebDriver's WebElement API provides various ways to retrieve and verify text. Sometimes, we need to retrieve text or value from an element into a variable at runtime and later use it at some other place in the test flow.

In this recipe, we will retrieve and verify text from an element by using the WebElement class' getText() method .

How to do it...

Here, we will create a test that locates an element and then retrieves text from the element in a string variable. We will verify contents of this string for correctness.

@Test
public void testElementText()
{
  //Get the message Element
  WebElement message = driver.findElement(By.id("message"));
  
  //Get the message elements text
  String messageText = message.getText();
  
  //Verify message element's text displays "Click on me and my //color will change"
  assertEquals("Click on me and my color...

Checking an element's attribute values


Developers configure various attributes of elements displayed on the web page during design or at runtime to control the behavior or style of elements when they are displayed in the browser. For example, the <input> element can be set to read-only by setting the readonly attribute.

There will be tests that need to verify that element attributes are set correctly. We can retrieve and verify an element's attribute by using the getAttribute() method of the WebElement class.

In this recipe, will check the attribute value of an element by using the getAttribute() method.

How to do it...

Create a test which locates an element and check its attribute value as follows:

@Test
public void testElementAttribute()
{
  WebElement message = driver.findElement(By.id("message"));
  assertEquals("justify",message.getAttribute("align"));
}

How it works...

By passing the name of the attribute to the getAttribute() method, it returns the value of the attribute back to the...

Checking an element's CSS values


Various styles are applied on elements displayed in a web application, so they look neat and become more usable. Developers add these styles using CSS (also known as Cascading Style Sheets). There may be tests that need to verify that correct styles have been applied to the elements. This can be done using WebElement class's getCSSValue() method, which returns the value of a specified style attribute.

In this recipe, we will use the getCSSValue() function to check the style attribute defined for an element.

How to do it...

Let's create a test which reads the CSS width attribute and verifies the value.

@Test
public void testElementStyle()
{
  WebElement message = driver.findElement(By.id("message"));
  String width = message.getCssValue("width");
  assertEquals("150px",width);
}

How it works...

By passing the name of CSS attribute to the getCSSValue() method, it returns the value of the CSS attribute. In this example, we are checking that the width attribute of...

Using Advanced User Interactions API for mouse and keyboard events


The Selenium WebDriver's Advanced User Interactions API allows us to perform operations from keyboard events and simple mouse events to complex events such as dragging-and-dropping, holding a key and then performing mouse operations by using the Actions class, and building a complex chain of events exactly like a user doing these manually.

The Actions class implements the builder pattern to create a composite action containing a group of other actions.

In this recipe, we will use the Actions class to build a chain of events to select rows in a table.

How to do it...

Let's create a test to select the multiple rows from different positions in a table using the Ctrl key. We can select multiple rows by selecting the first row, then holding the Ctrl key, and then selecting another row and releasing the Ctrl key. This will select the desired rows from the table.

@Test
public void testRowSelectionUsingControlKey() {
  
  List<WebElement...

Performing double-click on an element


There will be elements in a web application that need double-click events fired for performing some actions. For example, double-clicking on a row of a table will launch a new window. The Advanced User Interaction API provides a method to perform double-click.

In this recipe, we will use the Actions class to perform double-click operations.

How to do it...

Let's create a test that locates an element for which a double-click event is implemented. When we double-click on this element, it changes its color.

@Test
public void testDoubleClick() throws Exception
{
  WebDriver driver = new ChromeDriver();
  driver.get("http://dl.dropbox.com/u/55228056/DoubleClickDemo.html");
    
  WebElement message = driver.findElement(By.id("message"));
    
  //Verify color is Blue
  assertEquals("rgb(0, 0, 255)",message.getCssValue("background-color").toString());
  
  Actions builder = new Actions(driver);
  builder.doubleClick(message).build().perform();
  
  //Verify Color...

Performing drag-and-drop operations


Selenium WebDriver implements Selenium RC's dragAndDrop command using Actions class. As seen in earlier recipes the Actions class supports advanced user interactions such as firing various mouse and keyboard events. We can build simple or complex chains of events using this class.

In this recipe, we will use the Actions class to perform drag-and-drop operations.

How to do it...

Let's implement a test which will perform a drag-and-drop operation on a page using the Actions class.

@Test
public void testDragDrop() {
  
  driver.get("http://dl.dropbox.com/u/55228056/DragDropDemo.html");
  
  WebElement source = driver.findElement(By.id("draggable"));
  WebElement target = driver.findElement(By.id("droppable"));

  Actions builder = new Actions(driver);
  builder.dragAndDrop(source, target).perform();
  try
  {
    assertEquals("Dropped!", target.getText());
  } catch (Error e) {
    verificationErrors.append(e.toString());
  }
}

How it works...

For dragging an element...

Executing JavaScript code


Selenium WebDriver API provides the ability to execute JavaScript code with the browser window. This is a very useful feature where tests need to interact with the page using JavaScript. Using this API, client-side JavaScript code can also be tested using Selenium WebDriver. Selenium WebDriver provides a JavascriptExecutor interface that can be used to execute arbitrary JavaScript code within the context of the browser.

In this recipe, we will explore how to use JavascriptExecutor for executing JavaScript code. This book has various other recipes where JavascriptExecutor has been used to perform some advanced operations that are not yet supported by the Selenium WebDriver.

How to do it...

Let's create a test that will call JavaScript code to return title and count of links (that is a count of Anchor tags) from a page. Returning a page title can also be done by calling the driver.getTitle() method.

@Test
public void testJavaScriptCalls() throws Exception
{
  WebDriver...

Capturing screenshots with Selenium WebDriver


Selenium WebDriver provides the TakesScreenshot interface for capturing a screenshot of a web page. This helps in test runs, showing exactly happened when an exception or error occurred during execution, and so on. We can also capture screenshots during verification of element state, values displayed, or state after an action is completed.

Capturing screenshots also helps in verification of layouts, field alignments, and so on where we compare screenshots taken during test execution with baseline images.

In this recipe, we will use the TakesScreenshot interface to capture a screenshot of the web page under test.

How to do it...

Let's create a test that will open our test application and take a screenshot of the page in PNG format.

@Test
public void testTakesScreenshot()
{
  try {
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scrFile, new File("c:\\tmp\\main_page.png"));
  } catch (Exception e...

Capturing screenshots with RemoteWebDriver/Grid


While running tests with RemoteWebDriver or Grid it is not possible to take the screenshots, as the TakesScreenshot interface is not implemented in RemoteWebDriver.

However, we can use the Augmenter class which adds the TakesScreenshot interface to the remote driver instance.

In this recipe, we will use the Augmenter class to capture a screenshot from RemoteWebDriver.

Getting ready

Create a test which uses RemoteWebDriver.

How to do it...

Add the following code to the test using RemoteWebDriver:

driver = new Augmenter().augment(driver);
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

How it works...

The Augmenter class enhances the RemoteWebDriver by adding to it various interfaces including the TakesScreenshot interface.

driver = new Augmenter().augment(driver);

Later we can use the TakesScreenshot interface from RemoteWebDriver to capture the screenshot.

Maximizing the browser window


Selenium RC's windowMaximize() command was missing in Selenium WebDriver. However starting from release 2.21, Selenium WebDriver supports maximizing the browser window.

In this short recipe, we will see how to maximize the browser window.

Getting ready

Create a new test which will get an instance of WebDriver, navigate to a site and perform some basic actions and verifications.

How to do it...

To maximize a browser window, we need to call the maximize() method of the Window interface of the driver class. Add the second line right below where you define an instance of FirefoxDriver.

driver = new FirefoxDriver();
driver.manage().window().maximize();

How it works...

The WebDriver class provides the window interface for setting up the browser window size, state, and so on. When we call the maximize() method, the browser window will be maximized from normal or minimized state.

driver.manage().window().maximize();

Automating dropdowns and lists


Selenium WebDriver supports testing Dropdown and List controls using a special Select class instead of the WebElement class.

The Select class provides various methods and properties to interact with dropdowns and lists created with the HTML <select> element.

In this recipe, we will automate Dropdown and List control using Select class.

How to do it...

Let's create a test for a Dropdown control. This test will perform some basic checks and then call various methods to select options in dropdown.

@Test
public void testDropdown()
{
  //Get the Dropdown as a Select using its name attribute
  Select make = new Select(driver.findElement(By.name("make")));
  
  //Verify Dropdown does not support multiple selection
  assertFalse(make.isMultiple());
  //Verify Dropdown has four options for selection
  assertEquals(4, make.getOptions().size());
  
  //With Select class we can select an option in Dropdown using //Visible Text
  make.selectByVisibleText("Honda");
  assertEquals...

Checking options in dropdowns and lists


While testing the dropdowns and lists created with the <select> element, there will be a need to check that correct options are displayed for user selection. These options may be static or populated from a database.

In this recipe we will see how options can be checked against the expected values.

Getting ready

This recipe will need the test created from the earlier Automating dropdowns and lists recipe. We will add additional steps for checking the options.

How to do it...

Let's modify the testDropdown() test method for checking the options. Add the following highlighted code to the test:

@Test
public void testDropdown()
{
  //Get the Dropdown as a Select using its name attribute
  Select make = new Select(driver.findElement(By.name("make")));
  
  //Verify Dropdown does not support multiple selection
  assertFalse(make.isMultiple());
  //Verify Dropdown has four options for selection
  assertEquals(4, make.getOptions().size());
  
  //We will verify...

Checking selected options in dropdowns and lists


In earlier recipes, we saw how to select options in the Dropdown and List controls as well as check what options are available for selection. We also need to verify that the correct options are selected in these controls, either by default or by the user.

In this recipe, we will see how to check options which are selected in a dropdown or list.

Getting ready

This recipe will need the test created from the earlier Automating dropdowns and lists recipe. We will add additional steps for checking the options.

How to do it...

Let's modify the testDropdown() test method for checking the options. Add the following highlighted code to the test:

@Test
public void testDropdown()
{
  ...
  
  //With Select class we can select an option in Dropdown using //Visible Text
  make.selectByVisibleText("Honda");
  assertEquals("Honda", make.getFirstSelectedOption().getText());
  
  //or we can select an option in Dropdown using value attribute
  make.selectByValue...

Automating radio buttons and radio groups


Selenium WebDriver supports Radio Button and Radio Group controls using the WebElement class. We can select and deselect the radio buttons using the click() method of the WebElement class and check whether a radio button is selected or deselected using the isSelected() method.

In this recipe, we will see how to work with the Radio Button and Radio Group controls.

How to do it...

Let's create a test which gets Radio Button and Radio Group controls. We will perform select and deselect operations.

@Test
public void testRadioButton()
{
  //Get the Radiobutton as WebElement using it's value attribute
  WebElement petrol = driver.findElement(By.xpath("//input[@value='Petrol']"));
  
  //Check if its already selected? otherwise select the Radiobutton 
  //by calling click() method 
  if (!petrol.isSelected())
    petrol.click();
  
  //Verify Radiobutton is selected 
  assertTrue(petrol.isSelected());
  
  //We can also get all the Radiobuttons from a Radio...

Automating checkboxes


Selenium WebDriver supports Checkbox control using the WebElement class. We can select or deselect a checkbox using the click() method of the WebElement class and check whether a checkbox is selected or deselected using the isSelected() method.

In this recipe, we will see how to work with the Checkbox control.

How to do it...

Here is a test which gets a Checkbox control. We will perform select and deselect operations.

@Test
public void testCheckBox()
{
  //Get the Checkbox as WebElement using it's value attribute
  WebElement airbags = driver.findElement(By.xpath("//input[@value='Airbags']"));
  
  //Check if its already selected? otherwise select the Checkbox
  //by calling click() method
  if (!airbags.isSelected())
    airbags.click();
  
  //Verify Checkbox is Selected
  assertTrue(airbags.isSelected());

  //Check Checkbox if selected? If yes, deselect it
  //by calling click() method
  if (airbags.isSelected())
    airbags.click();
  
  //Verify Checkbox is Deselected...

Controlling Windows processes


Selenium WebDriver Java bindings provide the WindowsUtils class with methods to interact with the Windows operating system. During test runs, there might be a need to close open instances of browser windows or processes at the beginning of the test. By using the WindowsUtils class, we can control the process and perform tasks, such as killing an open process, and so on.

In this recipe, we will use the WindowsUtils class to kill the open browser window.

How to do it...

Let's close an open instance of Firefox by using the WindowsUtils class in the setUp() method as follows:

@Before
public void setUp()
{
  WindowsUtils.tryToKillByName("firefox.exe");
  driver = new FirefoxDriver();
  driver.get("http://www.google.com");
  driver.manage().window().maximize();
}

How it works...

We can close or kill any process running on the Windows OS by using the tryToKillByName() function of the WindowsUtils class. We need to pass the name of process we wish to close.

WindowsUtils.tryToKillByName...

Reading a Windows registry value from Selenium WebDriver


The WindowsUtils class provides various methods to interact with the registry on the Windows operating system. While running tests on the Windows operating system and Internet Explorer, the test might need to read and modify IE settings or there may be a need to get some settings related to the web server or database from the registry in tests. The WindowsUtils class comes handy in these situations.

In this recipe, we will use WindowsUtil to read the exact name of the operating system on which the test is running. We might need this information printed in our test logs.

How to do it...

We need to import the org.openqa.selenium.os.WindowsUtils class and use the readStringRegistryValue() method for reading a registry value that is represented as a String.

String osname = WindowsUtils.readStringRegistryValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProductName");
System.out.println(osname);

How it works...

The WindowsUtils...

Modifying a Windows registry value from Selenium WebDriver


The WindowsUtils class also provides methods to update existing Windows registry values or create new registry keys and values. Similar to reading registry values, WindowsUtils class provides multiple methods to modify keys and values.

In this recipe, we will use the WindowsUtils class to create a new registry key with a string value.

How to do it...

Use the writeStringRegistryValue() method for modifying existing Windows registry value or creating a new key and value represented as a string.

WindowsUtils.writeStringRegistryValue("HKEY_CURRENT_USER\\SOFTWARE\\Selenium\\SeleniumVersion", "2.24");
assertEquals("2.24",WindowsUtils.readStringRegistryValue("HKEY_CURRENT_USER\\SOFTWARE\\Selenium\\SeleniumVersion")); 

How it works...

When the writeStringRegistryValue() method is executed along with the path, a new registry key will be created in HKEY_CURRENT_USER\SOFTWARE with Selenium and a new value will be stored in SeleniumVersion.

WindowsUtils...
Left arrow icon Right arrow icon

Key benefits

  • Learn to leverage the power of Selenium WebDriver with simple examples that illustrate real world problems and their workarounds
  • Each sample demonstrates key concepts allowing you to advance your knowledge of Selenium WebDriver in a practical and incremental way
  • Explains testing of mobile web applications with Selenium Drivers for platforms such as iOS and Android

Description

Web technologies are becoming increasingly complex and there is a need to test your web applications against a vast number of browsers and platforms, so you need to build highly reliable and maintainable test automation. This book will help you test your web applications effectively and efficiently with Selenium WebDriver."Selenium Testing Tools Cookbook" is an incremental guide that will help you learn and use advanced features of Selenium WebDriver API in various situations for building reliable test automation. You will learn how to effectively use features of Selenium using simple and detailed examples. This book will also teach you best practices, design patterns, and how to extend Selenium."Selenium Testing Tools Cookbook" shows developers and testers who already use Selenium, how to go to the next step and build a highly maintainable and reliable test framework using advanced features of the tool.The book starts with tips on advanced location strategy and effective use of Selenium WebDriver API. Then it demonstrates the use of design patterns such as Data Driven Tests and PageFactory for building maintainable test automation. It also explains extending Selenium WebDriver API along with implementing custom tasks and setting up your own distributed environment to run tests in parallel.It concludes with tips on integrating Selenium WebDriver with other popular tools, testing mobile web applications, and capturing videos of test runs. This books provides examples in Java, C#, Ruby, and Python."Selenium Testing Tools Cookbook" will help you in building a highly robust and maintainable test automation framework from start to finish.

Who is this book for?

This book is intended for software quality assurance/testing professionals, software project managers, or software developers with prior experience in using Selenium and Java for testing web-based applications. This book also provides examples for C#, Python, and Ruby users.

What you will learn

  • Understand Locators and use various locator methods to build reliable tests
  • Build reliable and maintainable tests with Selenium WebDriver API
  • Use PageFactory Pattern to build a robust and easy- to-maintain test framework
  • Build data driven tests and extend Selenium API to implement custom steps and checks
  • Learn to integrate and use ATDD/BDD tools such as JBehave, SpecFlow, and FitNesses with Selenium WebDriver
  • Set up iPhone/iPad & Android simulators and devices for testing your mobile web application
  • Set up Selenium Grid for faster and parallel run of tests, increasing test coverage and reducing test execution time
  • Capture screenshots and videos of test runs

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 23, 2012
Length: 326 pages
Edition : 1st
Language : English
ISBN-13 : 9781849515757
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 23, 2012
Length: 326 pages
Edition : 1st
Language : English
ISBN-13 : 9781849515757
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 84.98
Selenium Design Patterns and Best Practices
$35.99
Selenium Testing Tools Cookbook
$48.99
Total $ 84.98 Stars icon
Banner background image

Table of Contents

11 Chapters
Locating Elements Chevron down icon Chevron up icon
Working with Selenium API Chevron down icon Chevron up icon
Controlling the Test Flow Chevron down icon Chevron up icon
Data-driven Testing Chevron down icon Chevron up icon
Using the Page Object Model Chevron down icon Chevron up icon
Extending Selenium Chevron down icon Chevron up icon
Testing on Mobile Browsers Chevron down icon Chevron up icon
Client-side Performance Testing Chevron down icon Chevron up icon
Testing HTML5 Web Applications Chevron down icon Chevron up icon
Recording Videos of Tests Chevron down icon Chevron up icon
Behavior-driven Development Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(23 Ratings)
5 star 30.4%
4 star 52.2%
3 star 13%
2 star 0%
1 star 4.3%
Filter icon Filter
Top Reviews

Filter reviews by




kotoko Mar 02, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very well written for someone who is beginning to learn working on Selenium as well as advancing to refining and enhancing knowledge. It presents a good information recipe to accomplish functional test scripts. It also, easy to understand for technical and non-technical
Amazon Verified review Amazon
Roy Fine Feb 10, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you are doing automated web testing, you should consider Selenium. Not a lot of info in the book that cannot be found online, but having it handy on my Kindle is well worth the modest price of the book. Note - the books works very nicely with Kindle HD and Kindle PC AppThe book is full of "How to do" cases with complete details, and at the end of each there is a "How it works" sections.Selenium API are available to supports several languages: Java, C#, Python, and others I suspect. All of our test work is driven from python - and fortunate for us there were plenty of plenty of python based examples in the bookIf you have experience in one of the driver languages, and if you are accomplished enough to have developed a website with more than just one page, then this book is a good first read. Others have noted it is not for the beginner - but I found it well written and detailed enough for the average web developer.
Amazon Verified review Amazon
M. Zuzic Jul 14, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I read this book cover to cover over the space of a week, which is the first time I've ever read an entire techical book before.You will benefit largely to have an understanding of programming languages when reading this book. In my case, I have a software development background and an automated test development background which must be why I found the book so interesting.I have started to apply the concepts detailed in the book to my current project which is proving to be a fantastic basis for a highly maintainable and well structured framework.Well done to the author, I will certainly cnsider future updates as Selenium evolves
Amazon Verified review Amazon
Michael Larsen Jan 21, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As the experience level with Selenium and other open source automation tools grows, naturally there will also develop more questions. How would I effectively access elements? What's a good way to compartmentalize tests? How can I make my tests extensible? What's the best way to parallelize tests? What if my project doesn't use a standard approach like so many others? What if I'm not on Linux, or don't use Java?The idea and benefit of a "Cookbook" approach is that it allows developers and testers to look at the aspects that they need at that time, and see how they work in example formats, and then see how they relate to other topics. Packt has decided to take this approach with Selenium by publishing the Selenium Testing Tools Cookbook. In it, author Unmesh Gundecha has broken down thirteen areas of interest (eleven in the book itself, plus two additional areas as bonus download sections), and presents small sections and ideas to allow the developer or tester to leverage the ability to create tests, use the Selenium API, and test applications such as browsers and mobile applications. The book demonstrates examples primarily in Java, but several are provided that use C#, Python and Ruby.For the tl;dr crowd, if you have never used Selenium before, this should not be the book to start your exploration. I would suggest reading David Burns "Selenium 2 Testing Tools Beginner's Guide" or Alan Richardson's "Selenium Simplified" first. David's book is also a Packt Publishing title, and uses many of the same documentation standards, so it would feel very natural looking at section's of David's book, and then coming back to try out more examples in Unmesh's Cookbook here.As this is a Cookbook style title, I must give a disclaimer that I have not yet tried every single example in the book. For that matter, I haven't gone through even a minority of the examples, and that's OK. Cookbook's are not designed to be read from cover to cover, and neither is this one. It is expected, and intended, that the user pick an area that interested them, and explore that area. Different projects have different needs, and being able to skip around will help focus the reader's time on the areas that matter most to them at that given time.Each chapter uses a similar structure, with an introduction to explain the tools and calls that will be used in that section. The given recipe is described and gives the reader an idea as to what can be done (along with sample code for each of the recipes, which can be downloaded from Packt's site if you prefer to see the projects in their entirety, and would rather not have to type out the examples from the book directly. Each item then goes through and describes what you will need to accomplish the project at hand (if you need tools like Firebug or Intellij IDEA, it tells you what you need and where to get them). The recipe concludes with a How it Works section, and in many cases, additional recipes that relate to the one you are working with.The book starts out with locating elements, and the different ways in which that can be accomplished (CSS, XPath, text values, jQuery, locating table rows and cells, etc.).Next the Selenium API is explored and the various methods available to examine and determine what you are looking at (text, attributes, CSS values, interacting with the mouse and keyboard, using JavaScript, capturing screenshots, drop downs and menu items, even going in and changing values in the Windows Registry if desired).Chapters Three and Four will be important to testers especially, since these chapters deal with test flow and ways to create data driven tests. Topics such as waiting for elements, handling pop-ups, determining if elements are the correct state, working with JavaScript alerts, handling frames and iFRAME's, plus using a variety of frameworks to interact with tests and set up data driven tests in these frameworks are explored, with examples for Java, win32, Ruby and Python.Chapter Five talks about the Page Object model and how to use it when developing your tests in the languages covered in the book (Java especially, but examples also show how to use .NET, Python and Ruby).Chapter Six gets into some examples of how to extend selenium and shows some in depth examples using Java (examples include making an extension class for web tables, jQueryUI Tab widget, creating an object map for Selenium tests, capturing screenshots and comparing images).Chapter Seven Shows how to perform mobile testing using Selenium, and some of the tools and ways to automate tests on iPhone an Android devices using RemoteWebDriver and other tools, such as the iWebDriver App to be used on a simulator or real device, or AndroidDriver on an android Simulator or device)Chapter Eight demonstrates some examples of how to get a handle on the Performance aspects of your sites or applications. Using timers, accessing and using BrowserMob proxy, and integrating with dynaTrace or HttpWatch are likewise covered. For the Ruby users among us, an example with Watir-WebDriver-Performance is demonstrated.Chapter Nine covers HTML5 and some of the unique tools provided with HTML5, JavaScript and CSS3, such as video widgets, canvas and web storage, and how to interact with those elements.Chapter Ten shows a number of ways in which a user could Record a Video of a Test (not record and playback of a test, actually recording an instance of the test being run as a video file, so it can be reviewed later. Tools such as the Monte Media Library (Java), Microsoft Expression Encoder (.NET) and Castro (Python) are demonstrated.Chapter Eleven discusses Behavior Driven Development (BDD). There are several different books that go into this topic at length, so for more on how this works and how to leverage that aspect, you will definitely want to read more than this single chapter. Still, if you are interested in how BDD can be performed in different environments, this will be of interest. The goal of TDD is meant to be a way to write test cases in a more natural language that those who do not program can both read and, in some cases, create themselves. Ruby users will find examples using Cucumber and Cabybara. Java users will see examples using Cucumber-JVM and JBehave. .NET uses will see examples using SpecFlow.NET.Two additional chapters, Integration with Other Tools and Distributed Testing with Selenium Grid are not included with the book itself, but can be downloaded from the Packt site. these deal with integrating with tools like Eclipse and IntelliJ IDEA, as well as using Ant and Maven for Continuous Integration, as well as parallelization of tests using Selenium Grid.Bottom Line:We now have a number of titles to help users get into the world of Selenium and SeleniumWebDrier. Each of these titles, by necessity, can only go so deep and with so many examples. For many, that would be fine. For those who want to know "what's next" or "where could I take these ideas and expand on them" or even "can you give me some ideas as to where I might use the variety of options?", then Selenium Testing Tools Cookbook may be a great next step to explore. One thing's for sure, there's plenty in this book to keep the Selenium enthusiast busy for quite some time.
Amazon Verified review Amazon
Aziz Mar 15, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Written for the Tester novice, this book is a concise, thorough, and accurate and helps immensely for Test Managers also.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.