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 attribute

Assertions attribute

In this lesson, we'll learn how to expect an element to have a certain class, an ID, or any other attribute along with its value. So we'll go ahead and check our docs classes, that is, navbar-item and navbar-link. So we'll go ahead and expect the same to have these classes so that it's styled properly. but locate it using its tag name that is the link role and the name of docs so back in VS code we can go ahead and create a docs link use page get by role and the role is link and the name is docs now we can go ahead and expect the same to have a class using the to have class method so to our to have class method we can provide a last name that is navbar item and an F bar link now if I go ahead and run the test and I have enabled the headless mode because we don't need to see the ui and you will notice that our test has passed so our docs link has these two classes now if you only want to check or expect an element to have only one class you have to use regular expressions that is if i…

Contents