Search code examples
python-3.xassert

Someone can tell me about Assert in Python3


This code is from:https://selenium-python.readthedocs.io/getting-started.html

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element(By.NAME, "q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

assert "Python" in driver.title //i don't understand this line what is


Solution

  • Assert statements are used as a sort of quick check of logical condition. In this case, if the string "Python" is not in the driver.title string, an exception will be raised.

    The assert statement can be found here