0

Just wanted to hear some thoughts about asserting against the database during a selenium test suite. For the website I am working on is a SPA with API backend where the majority of the service interactions follow the flow: FE > BE > DB > BE > FE

Is it breaking the end-to-end test paradigm if I were to do something along the lines of: pull list of web elements directly related to documents within the database and assert against the count of items in the database? Or is it better practice to do a more white box style of testing when doing end-to-end?

  • Welcome. After reading your question, I have little idea what you're actually asking. Could you please give us more information, perhaps even an example? – pavelsaman Jun 12 at 18:21
  • do you mean as an example your page is supposed to show X items in a list and you want to verify the proper number of items is displayed? Like a page shows users, and you need to verify the 7 users the page shows are the 7 users in the database? – squeemish Jun 12 at 18:28
  • Yeah that's exactly right squeemish – st0ve Jun 12 at 18:33
1

In my experience, querying the DB to assert content is correct in the front-end is rarely done.

The main idea behind the E2E automation tests is to ensure the functionality of the web elements are working and present. Things like:

  • Links are clickable and navigate to the correct page
  • Forms can be filled out
  • User sign up, user login, user modification (password reset), user delete, etc
  • Some content is present like logo is present.

You typically want to stay away from content testing in UI automation testing since content is always changing.

Ensuring that the database is returning the correct data is usually done via API automation tests or through integration testing. If you can create test automation for the API, you are proving the data is correct and that the database is working correctly without having to involve the UI. Then, when you do UI testing, you know the data is correct and just need to verify UI usability and functionality.

My recommendation would be to review the Test Automation Pyramid. Martin Fowler has a good explanation. This concept allows you to separate out testing areas into unit tests, integration tests, and UI/E2E tests with more testing done at the bottom and fewer tests at the top.

| improve this answer | |
  • Thank you for the detailed response. So in the case of E2E testing, we want to ensure the presence of data and absence of error. But we aren't concerned with the validity of what is displayed for the user? We can use other testing phases to validate data. – st0ve Jun 12 at 22:40
  • @st0ve Correct. The validity of the data can be tested via API testing, which is going to be faster. API testing is where a bulk of data testing should be. You can do some data testing in e2e, things like ensuring the correct error message is shown. – Lee Jensen Jun 15 at 15:56
1

I don't think querying the DB for verification is necessary. Since your app FE is connected to API, you just need to query through API to verify things. The data verification should be done through testing of the APIs themselves.

| improve this answer | |
  • So in that sense. We should be testing that data is displayed on the page, but we don't care if the data is correct? I feel like proving correctness adds more value – st0ve Jun 12 at 18:27
  • You can verify the data through the API test. it's much faster and easier to maintain in the long run – DayDreamer Jun 14 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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