When your app requires a login, you need to consider the following:
- Tests should work locally and remotely.
- Enable different credentials for different users/environments.
- Deal with a situation where you are already logged in.
- Start a new test.
- Record the steps of your login process.
- Run the test to see if it works.
Typically, the steps in the login process will include:
- Click sign in button
- Enter username
- Enter password
- Click log in
If this is your first test, use this guide to help you.
Running in incognito mode can be very useful when creating the login process.
When you run in incognito mode, you start with a clean browser every time i.e. without cookies, without a local storage, and the browser does not remember you.
Learn here how to run in an incognito mode here.
Grouping your login steps will allow reuse of these steps for the other tests.
Learn how to group your login steps here.
Note: Make sure you give your group a meaningful name.
For this, we'll add a condition, which determines at run-time whether the step should be executed or not.
E.g. the test should work when you're already logged and also when login is required.
These are a few options for common conditions in the login scenario:
- Check if a login button is visible - use element condition.
- Check the current URL if it matches a login page - use custom condition.
Learn about how to add conditions.
If we want to make this group more generic and allow for each reuse of the group to use different certificates, we would like to add parameters for the username and password.
- Go to the group properties panel (select the group and open the property panel).
- Set the values for this parameters
- Enter the group steps.
- Change the set username step, and set password step and put these parameters instead of the constants values.
Learn more about adding parameters to a group.
Now, whenever you use this group, you can set up different credentials.
When we create a test, some of the steps that we recorded as a manual user may not be relevant to the automatic test. For example, pressing "Tab" between text fields, clicking on a text field to input data. These steps can be deleted.
- Clear unnecessary steps. Learn more on how to delete steps.
- Run again to make sure you have not deleted anything you need.
- Save again.
Be careful, in some applications these steps are required because they do more than just focusing on the field.
Updated almost 3 years ago