Company
Date Published
Author
Bill McGee
Word count
1282
Language
English
Hacker News points
None

Summary

The Selenium framework is being introduced as a solution to automate tests for web applications. The main challenge with Selenium tests is that they can be brittle and difficult to maintain over time due to changes in the application, which breaks the tests. To address this issue, Page Objects are used, where simple objects model the behavior of an application, allowing tests to be written against them instead of directly against the application. This approach enables controlled chaos, reusability of functionality across tests, and makes it easier to update test code when changes occur in the application. A class called `Login` is created with locators for the login form, username input field, password input field, success message, and failure message. The class has an initializer that receives the Selenium driver object and visits the login page, a method `with` that accepts username and password values as arguments and performs the core functionality of the login page, and methods to check if the success or failure messages are present. Another test is added in the spec file to demonstrate a failed login scenario, which also uses the Page Object approach. The limitation of asserting false for the absence of a success message is discussed, and an assertion is added to ensure Selenium is in the right place before proceeding with the tests.