Step-by-step tutorial for testing a simple web application.
Recently I have decided to solve the Test.Bash 2022 UI Automation challenge. I need to test a small web application running at https://automationintesting.online/; it is a message form. A user can submit the form, and then the admin can log in and read the message. The total time to solve it is twenty minutes, so let's go.
Video
You can watch the video I submitted to the challenge below
Create a repo and a local project
I have created a repository for my tests bahmutov/test-bash-2022-ui. Locally I have created a new folder with Git and NPM package
1 2 3 4 5 6
# "md" is my aliasfor creating folders # a combination of "mkdir" and "cd" ~/git $ md test-bash-2022-ui ~/git/test-bash-2022-ui $ git init ~/git/test-bash-2022-ui $ git remote add origin [email protected]:bahmutov/test-bash-2022-ui.git ~/git/test-bash-2022-ui $ npm init -y
If you have never seen a Cypress test, take a look at the Cypress introduction. We visit the base URL, find the message form, and then enter some text into the fields. To make sure we can find our message, I use the Lodash library (bundled with Cypress) to generate a random id to include in the message subject.
The test runs pretty quickly, as you can see in this video
Of course, it is not a problem - we can always hover over the test steps to see how the application's DOM looked at that particular moment.
Tip: the demo application resets itself every 10 minutes. Thus it could potentially reset during the test run, causing the test to fail. To mitigate this, we can turn on Cypress test retries.