You are previewing Learning Selenium Testing Tools with Python.
O'Reilly logo
Learning Selenium Testing Tools with Python

Book Description

A practical guide on automated web testing with Selenium using Python

In Detail

Selenium WebDriver is a popular automated testing tool for web applications. Python is one of the top programming languages and when used with Selenium it can automate and test web applications. Using Python's unittest module, you can write test cases in Selenium. Over the years, Selenium has become a very powerful testing platform and many organizations are adopting Selenium WebDriver for creating automated user interface tests.

The book's main aim is to cover the fundamentals related to Python Selenium testing. You will learn how the Selenium WebDriver Python API can be integrated with CI and Build tools to allow tests to be run while building applications. This book will guide you through using the Selenium WebDriver Python client library as well as other tools from the Selenium project. Towards the end of this book, you'll get to grips with Selenium Grid, which is used for running tests in parallel using nodes for cross-browser testing. It will also give you a basic overview of the concepts, while helping you improve your practical testing skills with Python and Selenium.

What You Will Learn

  • Create Selenium WebDriver tests using the Python unittest module
  • Use Selenium WebDriver for cross-browser testing
  • Build reliable and robust tests using implicit and explicit waits
  • Set up and use Selenium Grid for distributed run
  • Test web applications on mobile platforms such as iOS and Android using Appium
  • Utilize various methods provided by Selenium WebDriver to locate web elements and interact with them
  • Capture screenshots and videos of the test execution
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Learning Selenium Testing Tools with Python
      1. Table of Contents
      2. Learning Selenium Testing Tools with Python
      3. Credits
      4. About the Author
      5. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders

      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Getting Started with Selenium WebDriver and Python
        1. Preparing your machine
          1. Installing Python
          2. Installing the Selenium package
          3. Browsing the Selenium WebDriver Python documentation
          4. Selecting an IDE
            1. PyCharm
            2. The PyDev Eclipse plugin
            3. PyScripter
          5. Setting up PyCharm
        2. Taking your first steps with Selenium and Python
        3. Cross-browser support
          1. Setting up Internet Explorer
          2. Setting up Google Chrome
        4. Summary
      9. 2. Writing Tests Using unittest
        1. The unittest library
          1. The TestCase class
            1. The setUp() method
            2. Writing tests
            3. Cleaning up the code
            4. Running the test
            5. Adding another test
          2. Class-level setUp() and tearDown() methods
          3. Assertions
          4. Test suites
        2. Generating the HTML test report
        3. Summary
      10. 3. Finding Elements
        1. Using developer tools to find locators
          1. Inspecting pages and elements with Firefox using the Firebug add-in
          2. Inspecting pages and elements with Google Chrome
          3. Inspecting pages and elements with Internet Explorer
        2. Finding elements with Selenium WebDriver
          1. Using the find methods
            1. Finding elements using the ID attribute
            2. Finding elements using the name attribute
            3. Finding elements using the class name
            4. Finding elements using the tag name
            5. Finding elements using XPath
            6. Finding elements using CSS selectors
            7. Finding links
            8. Finding links with partial text
        3. Putting all the tests together using find methods
        4. Summary
      11. 4. Using the Selenium Python API for Element Interaction
        1. Elements of HTML forms
        2. Understanding the WebDriver class
          1. Properties of the WebDriver class
          2. Methods of the WebDriver class
        3. Understanding the WebElement class
          1. Properties of the WebElement class
          2. Methods of the WebElement class
        4. Working with forms, textboxes, checkboxes, and radio buttons
          1. Checking whether the element is displayed and enabled
          2. Finding the element attribute value
          3. Using the is_selected() method
          4. Using the clear() and send_keys() methods
        5. Working with dropdowns and lists
          1. Understanding the Select class
          2. Properties of the Select class
          3. Methods of the Select class
        6. Working with alerts and pop-up windows
          1. Understanding the Alert class
          2. Properties of the Alert class
          3. Methods of the Alert class
          4. Automating browser navigation
        7. Summary
      12. 5. Synchronizing Tests
        1. Using implicit wait
        2. Using explicit wait
        3. The expected condition class
          1. Waiting for an element to be enabled
          2. Waiting for alerts
        4. Implementing custom wait conditions
        5. Summary
      13. 6. Cross-browser Testing
        1. The Selenium standalone server
          1. Downloading the Selenium standalone server
          2. Launching the Selenium standalone server
        2. Running a test on the Selenium standalone server
          1. Adding support for Internet Explorer
          2. Adding support for Chrome
        3. Selenium Grid
          1. Launching Selenium server as a hub
          2. Adding nodes
            1. Adding an IE node
            2. Adding a Firefox node
            3. Adding a Chrome node
        4. Mac OS X with Safari
        5. Running tests in Grid
        6. Running tests in a cloud
          1. Using Sauce Labs
        7. Summary
      14. 7. Testing on Mobile
        1. Introducing Appium
          1. Prerequisites for Appium
            1. Setting up Xcode for iOS
            2. Setting up Android SDK
            3. Setting up the Appium Python client package
        2. Installing Appium
          1. Appium Inspector
        3. Testing on iOS
          1. Writing a test for iOS
        4. Testing on Android
          1. Writing a test for Android
        5. Using Sauce Labs
        6. Summary
      15. 8. Page Objects and Data-driven Testing
        1. Data-driven testing
        2. Using ddt for data-driven tests
          1. Installing ddt
          2. Creating a simple data-driven test with ddt in unittest
        3. Using external data sources for data-driven tests
          1. Reading values from CSV
          2. Reading values from Excel
        4. The page objects pattern
          1. Organizing tests
          2. The BasePage object
          3. Implementing page objects
          4. Creating a test with page objects
        5. Summary
      16. 9. Advanced Techniques of Selenium WebDriver
        1. Methods for performing keyboard and mouse actions
          1. Keyboard actions
          2. The mouse movement
            1. The double_click method
            2. The drag_and_drop method
        2. Executing JavaScript
        3. Capturing screenshots of failures
          1. Recording a video of the test run
        4. Handling pop-up windows
        5. Managing cookies
        6. Summary
      17. 10. Integration with Other Tools and Frameworks
        1. Behavior-Driven Development
          1. Installing Behave
          2. Writing the first feature in Behave
            1. Implementing a step definition file for the feature
            2. Creating environment configurations
            3. Running features
            4. Using a scenario outline
        2. CI with Jenkins
          1. Preparing for Jenkins
          2. Setting up Jenkins
        3. Summary
      18. Index