From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Assertions page
When writing tests, we have used the assert statement to assert a piece of condition. And based on that condition, we either pass or fail our test. Now playwright offers another API, which is web first assertions, which can be used to perform the same in a more readable way. So let's go ahead and see how can we do it. So I'll go ahead and comment out this assert statement and then I'll go ahead and import the expect function from our playwright sync API. Now using this expect function, we can expect or assert different conditions on our page and other locator objects. So let's go ahead and try to assert this condition right here. That is the page URL should be equals to our dogs URL. For that, we start with our expect function, give it our page object, because in this case, that's what we're going to assert with. And then we can use the expects API to perform the certain task. In this case, we'll use to have URL method like this, we'll give it the URL we want to check with. So you can…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.