Book Image

Learning Selenium Testing Tools with Python

By : Unmesh Gundecha
Book Image

Learning Selenium Testing Tools with Python

By: Unmesh Gundecha

Overview of this book

<p>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.</p> <p>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.</p>
Table of Contents (17 chapters)
Learning Selenium Testing Tools with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Putting all the tests together using find methods


In the previous sections, we saw various find_element_by methods along with examples. Let's pull together all these examples in a test.

  1. Create a new homepagetest.py file and copy all the tests that we created earlier as shown in the following code:

    import unittest
    from selenium import webdriver
    
    class HomePageTest(unittest.TestCase):
        @classmethod
        def setUpClass(cls):
            # create a new Firefox session
            cls.driver = webdriver.Firefox()
            cls.driver.implicitly_wait(30)
            cls.driver.maximize_window()
    
            # navigate to the application home page
            cls.driver.get('http://demo.magentocommerce.com/')
    
        def test_search_text_field_max_length(self):
            # get the search textbox
            search_field = self.driver.find_element_by_id("search")
    
            # check maxlength attribute is set to 128
            self.assertEqual("128", search_field.get_attribute ("maxlength"))
    
        def test_search_button_enabled(self...