-1

I am brand new to Software/application testing. I am testing a Web application using Cypress. For this web application, I have created my first login test. But for any subsequent test case, I need to login first. How should I tackle this situation. Should I add login functionality to before/beforeAll hook, but then The first test won't make sense.

Am I thinking about this correctly, if not then what would be the correct approach?

2 Answers 2

1

Hmm, from my side, what i do is that for all other tests that require a user to be logged in but are not testing the login functionality itself, i bypass the UI programmatically through setting the state as if the user is already logged in by making API calls or setting a session token, but this depends on how your application handles authentication. Not sure if this helps

0

A key thing to remember is that the value of our 'tests' is not from the steps they take, but the assertions we make within them.

Lets take your login test as an example. It will likely type in a username and password then press enter or click the Login button. These steps may pass successfully but for our test to have value, we have to add an assertion:

  • Username field is visible and I can type in it
  • Password field is visible and I can type in it
  • Login button is visible and clickable
  • When I type a valid username+password in AND I login
    • I am logged in

Your assertion to say that you are logged in could be a variety of different things, it could simply be the redirect to the next page (lets call it Dashboard), it could be something on the Dashboard page ("Welcome firstname lastname") or any number of things.

When we then use our login steps for future tests in a beforeeach hook, we would not have the same assertions. We might use some of them to cater for the way Cypress handles pages loading, but we have no reason to assert all of the same things, those assertions were our Login tests.

We also have more Login tests involving failing to Login, so try not to see our test steps as the tests themselves, remember it is the assertions that matter the most.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.