You are previewing Selenium WebDriver Recipes in C#, Second Edition.
O'Reilly logo
Selenium WebDriver Recipes in C#, Second Edition

Book Description

Solve your Selenium WebDriver problems with this quick guide to automated testing of web applications with Selenium WebDriver in C#. Selenium WebDriver Recipes in C#, Second Edition 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.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Preface
  11. Chapter 1: Introduction
    1. Selenium Language Bindings
    2. Set up the Development Environment
      1. Prerequisites
      2. Set up Visual Studio Solution
      3. Create a test and run it
    3. Cross-Browser Testing
      1. Firefox
      2. Chrome
      3. Internet Explorer
      4. Edge
    4. Visual Studio Unit Testing Framework
      1. Visual Studio Unit Testing Framework Fixtures
      2. Alternative Framework NUnit
    5. Run Recipe Scripts
      1. Run Tests in Visual Studio
      2. Run Tests from the Command Line
  12. Chapter 2: Locating Web Elements
    1. Start browser
    2. Find element by ID
    3. Find element by Name
    4. Find element by Link Text
    5. Find element by Partial Link Text
    6. Find element by XPath
    7. Find element by Tag Name
    8. Find element by Class
    9. Find element by CSS Selector
    10. Chain FindElement to find child elements
    11. Find multiple elements
  13. Chapter 3: Hyperlink
    1. Click a link by text
    2. Click a link by ID
    3. Click a link by partial text
    4. Click a link by XPath
    5. Click nth link with exact same label
    6. Click nth link by CSS selector
    7. Verify that a link is present or not
    8. Getting link data attributes
    9. Test links open a new browser window
  14. Chapter 4: Button
    1. Click a button by text
    2. Click a form button by text
    3. Submit a form
    4. Click a button by ID
    5. Click a button by name
    6. Click an image button
    7. Click a button via JavaScript
    8. Assert a button present
    9. Assert a button enabled or disabled
  15. Chapter 5: TextField and TextArea
    1. Enter Text into a Text Field by Name
    2. Enter Text into a Text Field by ID
    3. Enter Text into a Password Field
    4. Clear a Text Field
    5. Enter Text into a Multiline Text Area
    6. Assert Value
    7. Focus on a Control
    8. Set a Value to a Read-only or Disabled Text Field
    9. Set and assert the value of a hidden field
  16. Chapter 6: Radio Button
    1. Select a Radio Button
    2. Clear Radio Option Selection
    3. Assert a Radio Option is Selected
    4. Iterate Radio Buttons in a Radio Group
    5. Click nth Radio Button in a Group
    6. Click Radio Button by the Following Label
    7. Customized Radio Buttons: iCheck
  17. Chapter 7: Check Box
    1. Check by name
    2. Check by ID
    3. Clear a check box
    4. Assert a check box is checked (or not)
    5. Chain FindElement to find child elements
    6. Customized Check Boxes: iCheck
  18. Chapter 8: Select List
    1. Select an option by text
    2. Select an option by value
    3. Select an option by index
    4. Select an option by iterating all options
    5. Select multiple options
    6. Clear one selection
    7. Clear all selections
    8. Assert selected option
    9. Assert the value of a select list
    10. Assert multiple selections
  19. Chapter 9: Navigation and Browser
    1. Go to a URL
    2. Visit pages within a site
    3. Perform actions from the right-click context menu
    4. Open browser in certain size
    5. Maximize browser window
    6. Move browser window
    7. Minimize browser window
    8. Scroll focus to control
    9. Switch between browser windows or tabs
    10. Remember current web page URL and return to it later
  20. Chapter 10: Assertion
    1. Assert page title
    2. Assert page text
    3. Assert page source
    4. Assert checkbox selected
    5. Assert button enabled
    6. Assert label text
    7. Assert span text
    8. Assert div text or HTML
    9. Assert table text
    10. Assert text in a table cell
    11. Assert text in a table row
    12. Assert image present
  21. Chapter 11: Frames
    1. Testing Frames
    2. Testing iframe
    3. Test multiple iframes
  22. Chapter 12: AJAX
    1. Wait within a time frame
    2. Explicit waits until time out
    3. Implicit waits until time out
    4. Wait AJAX call to complete using JQuery
  23. Chapter 13: Pop-up
    1. File upload
    2. JavaScript pop-ups
    3. Modal style dialog boxes
    4. Timeout on a test
    5. Pop-up handler approach
    6. Basic or Proxy Authentication dialog box
    7. Internet Explorer modal dialog box
  24. Chapter 14: Debugging Test Scripts
    1. Print text for debugging
    2. Write page source or element HTML into a file
    3. Take a screenshot
    4. Leave the browser open after test finishes
    5. Debug test execution using Debugger
      1. Enable breakpoints
      2. Execute one test case in debugging mode
      3. Step over test execution
  25. Chapter 15: Test Data
    1. Get date dynamically
    2. Get a random boolean value
    3. Generate a number within a range
    4. Get a random character
    5. Get a random string at fixed length
    6. Get a random string in a collection
    7. Generate a test file at fixed sizes
    8. Retrieve data from database
  26. Chapter 16: Browser Profile
    1. Get browser type and version
    2. Set HTTP proxy for browser
    3. Verify file download in Chrome
    4. Verify file download in Firefox
    5. Bypass basic authentication by embedding username and password in URL
    6. Bypass basic authentication with Firefox AutoAuth plug-in
    7. Manage cookies
    8. Headless browser testing with PhantomJS
    9. Test responsive web sites
  27. Chapter 17: Advanced User Interactions
    1. Double-click a control
    2. Move mouse to a control: Mouse over
    3. Click and hold: Select multiple items
    4. Context click: Right-click a control
    5. Drag-and-drop
    6. Drag slider
    7. Send key sequences: Select All and Delete
  28. Chapter 18: HTML5 and JavaScript
    1. HTML5 email type field
    2. HTML5 time field
    3. Invoke ‘onclick’ JavaScript event
    4. Invoke JavaScript events such as onchange
    5. Scroll to the bottom of a page
    6. Chosen: Standard select
      1. Chosen: Multiple select
    7. AngularJS web pages
    8. Ember JS web pages
  29. Chapter 19: WYSIWYG Editor
    1. TinyMCE
    2. CKEditor
    3. SummerNote
    4. CodeMirror
  30. Chapter 20: Leverage Programming
    1. Throw exceptions to fail test
      1. Flag incomplete tests
      2. Stop test execution during debugging a test
    2. Ignorable test statement error
    3. Read external file
    4. Data-driven tests with Excel
    5. Data-driven tests with CSV
    6. Identify element IDs with dynamically generated long prefixes
    7. Sending special keys such as Enter to an element or browser
    8. Use of Unicode in test scripts
    9. Extract a group of dynamic data: Verify search results in order
    10. Verify uniqueness of a set of data
    11. Extract dynamic visible data rows from a results table
    12. Extract dynamic text following a pattern using Regex
  31. Chapter 21: Optimization
    1. Assert string in page_source is faster than the text
    2. Getting text from more specific elements is faster
    3. Avoid programming if-else block code if possible
    4. Use variable to cache unchanged data
    5. Enter large text into a text box
    6. Use environment variables to change test behaviors dynamically
    7. Test a web app in two languages
    8. Multi-language testing with lookups
  32. Chapter 22: Gotchas
    1. Test starts browser but no execution with blank screen
    2. Be aware of browser and driver changes
    3. Failed to assert copied text in browser
    4. The same test works for Chrome, but not for Internet Explorer
    5. “Unexpected tag name ‘input’”
    6. Element is not clickable or not visible
  33. Chapter 23: Remote Control Server
    1. Selenium Server installation
    2. Execute tests in the specified browser on another machine
    3. Selenium Grid
      1. Start the hub
      2. Start the nodes
      3. Using Grid to run tests
      4. Concerns with Selenium Grid
  34. Chapter 24: Afterword
    1. Practice makes perfect
      1. Write tests
      2. Improve programming skills
    2. Successful test automation
      1. Maintain test scripts to keep up with application changes
      2. Shorten test execution time to get quick feedback
  35. Chapter 25: Resources
    1. Books
    2. Web sites
    3. Tools
  36. Index