The problem solving guide to Selenium WebDriver in C#

A quick problem-solving guide to automated testing web applications with Selenium WebDriver in C#. It contains hundreds of solutions to real-world problems, with clear explanations and ready-to-run Selenium test scripts that you can use in your own projects.

Selenium WebDriver is a popular browser automation framework. Testers or developers with Selenium skills are in high demand.   It is easy to get started with Selenium, but do you use effectively for testing real-world test scenarios? Such as data driving test from an Excel spreadsheet and handling pop up dialogs.

Selenium Recipes will show you solutions to your problems from the experts who have already solved them. All recipe tests (100+ in a C# Visual Studio Solution) are ready-to-run. I created the target web site and offline web pages, so that you can simply find the recipes and run, in a matter of seconds. Owning this book is like having a test automation coach sitting next to you.

Zhimin Zhan

Zhimin Zhan is the founder and Continuous Integration Officer of AgileWay Pty Ltd, Australia. As an advisor and coach, he helps organzations by implementing test automation with Continuous Integration using open technologies such as Selenium WebDriver and Watir. Zhimin is the creator of TestWise, the next-generation functional testing tool that supports functional test refactorings, and frequent speaker and writer. He shares his test automation and CI experience at testwisely.com.

  • Preface

    • Who should read this book

    • How to read this book

    • Recipe test scripts

    • Send me feedback

  • 1. Introduction

    • 1.1 Selenium
    • 1.2 C# language binding
    • 1.3 Cross browser testing
    • 1.4 Visual Studio Unit Testing Framework
    • 1.5 Alternative framework NUnit
    • 1.6 Run recipe scripts
  • 2. Hyperlink
    • 2.1 Start browser
    • 2.2 Click a link by label text
    • 2.3 Click a link by ID
    • 2.4 Click a link by partial label text
    • 2.5 Click a link by XPath
    • 2.6 Click Nth link with exact same label
    • 2.7 Click Nth link by CSS Selector
    • 2.8 Verify a link present or not?
    • 2.9 Getting link data attributes
    • 2.10 Test links open a new browser window
  • 3. Button
    • 3.1 Click a button by text
    • 3.2 Click a form button by text
    • 3.3 Submit a form
    • 3.4 Click a button by ID
    • 3.5 Click a button by name
    • 3.6 Click a image button
    • 3.7 Assert a button present
    • 3.8 Assert a button enabled or disabled?
  • 4. TextField and TextArea
    • 4.1 Enter text into a text field by name
    • 4.2 Enter text into a text field by ID
    • 4.3 Enter text into a password field
    • 4.4 Clear a text field
    • 4.5 Enter text into a multi-line text area
    • 4.6 Assert value
    • 4.7 Focus on a control
    • 4.8 Set a value to a read-only or disabled text field
  • 5. Radio button
    • 5.1 Select a radio button
    • 5.2 Clear radio option selection
    • 5.3 Assert a radio option is selected
    • 5.4 Iterate radio buttons in a radio group
    • 5.5 Click Nth radio button in a group
  • 6. CheckBox
    • 6.1 Check by name
    • 6.2 Check by id
    • 6.3 Uncheck a checkbox
    • 6.4 Assert a checkbox is checked (or not)
  • 7. Select List
    • 7.1 Select an option by text
    • 7.2 Select an option by value
    • 7.3 Select an option by iterating all options
    • 7.4 Select multiple options
    • 7.5 Clear one selection
    • 7.6 Clear all selections
    • 7.7 Assert selected option
    • 7.8 Assert the value of a select list
    • 7.9 Assert multiple selections
  • 8. Navigation and Browser
    • 8.1 Go to a URL
    • 8.2 Go to pages within the site without specifying full url
    • 8.3 Perform actions from right click context menu such as ‘Back’, ‘Forward’ or ‘Refresh’
    • 8.4 Open browser in certain size
    • 8.5 Maximize browser window
    • 8.6 Move browser window
    • 8.7 Minimize browser window
    • 8.8 Switch between browser windows or tabs
    • 8.9 Remember current web page URL, then come back to it later
  • 9. Assertion
    • 9.1 Assert page title
    • 9.2 Assert Page Text
    • 9.3 Assert Page Source
    • 9.4 Assert Label Text
    • 9.5 Assert Span text
    • 9.6 Assert Div text or HTML
    • 9.7 Assert Table text
    • 9.8 Assert text in a table cell
    • 9.9 Assert text in a table row
    • 9.10 Assert image present
  • 10. Frames
    • 10.1 Testing Frames
    • 10.2 Testing iframe
    • 10.3 Test multiple iframes
  • 11. Testing AJAX
    • 11.1 Wait within a time frame
    • 11.2 Explicit Waits until Time out
    • 11.3 Implicit Waits until Time out
  • 12. File Upload and Popup dialogs
    • 12.1 File upload
    • 12.2 JavaScript pop ups
    • 12.3 Timeout on a test
    • 12.4 Popup Handler Approach
    • 12.5 Handle JavaScript dialog with Popup Handler
    • 12.6 Basic or Proxy Authentication Dialog
    • 12.7 Internet Explorer modal dialog
  • 13. Debugging Test Scripts
    • 13.1 Print text for debugging
    • 13.2 Write page source or element HTML into a file
    • 13.3 Take screenshot
    • 13.4 Leave browser open after test finishes
    • 13.5 Debug test execution using Debugger
  • 14. Test Data
    • 14.1 Get date dynamically
    • 14.2 Get a random boolean value
    • 14.3 Generate a number within a range
    • 14.4 Get a random character
    • 14.5 Get a random string at fixed length
    • 14.6 Get a random string in a collection
    • 14.7 Generate a test file at fixed sizes
  • 15. HTML 5 and Dynamic Web Sites
    • 15.1 HTML5 Email type field
    • 15.2 HTML5 Time Field
    • 15.3 Drag and drop
    • 15.4 Drag slider
    • 15.5 Chosen - Standard Select
    • 15.6 Chosen - Multiple Select
    • 15.7 AngularJS web pages
    • 15.8 Ember JS web pages
  • 16. Browser Profile and Capabilities
    • 16.1 Get browser type and version
    • 16.2 Set HTTP Proxy for Browser
    • 16.3 Set download path for Chrome
    • 16.4 Bypass basic authentication by embedding username and password in URL
    • 16.5 Bypass basic authentication with Firefox AutoAuth plugin
  • 17. Advanced topics
    • 17.1 Invoke ‘onclick’ JavaScript event
    • 17.2 Invoke JavaScript events such as ‘onchange’
    • 17.3 Ignorable test statement error
    • 17.4 Read external file
    • 17.5 Data-Driven Tests with Excel
    • 17.6 Data-Driven Tests with CSV
    • 17.7 Identify element IDs with dynamically generated long prefixes
    • 17.8 Failed to assert copied text in browser in test scripts, reporting “text not found”?!
    • 17.9 Sending special keys such as Enter to an element or browser
    • 17.10 Use of unicode in test scripts
  • 18. Selenium Remote Control Server
    • 18.1 Selenium Server Installation
    • 18.2 Execute tests in specified browser on another machine
    • 18.3 Selenium Grid
  • Resources

    • Books

    • Web Sites

    • Tools