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

Implementing custom wait conditions


As we have seen earlier, the expected_conditions class provides various predefined conditions to wait. We can also build custom conditions with WebDriverWait. This becomes useful when there is no suitable expected condition available for which to wait.

Let's modify one of the tests we created earlier in this chapter and implement a custom wait condition to check the number of the drop-down items:

def testLoginLink(self):
    WebDriverWait(self.driver, 10).until(lambda s: s.find_element_by_id "select-language").get_attribute("length") == "3")

    login_link = WebDriverWait(self.driver, 10).until(expected_conditions.visibility_of_element_located((By.LINK_TEXT,"Log In")))
       login_link.click();

We can implement custom wait conditions with WebDriverWait using the Python lambda expressions. In this example, the script will wait for 10 seconds until the Select Language dropdown has eight options for selection. This condition is useful when the dropdowns are...