4

Say that I am testing a GET api. The get api fetches data which is stored due to user actions on a web UI. The data cannot be setup by simply looking at the network inspector calls for these actions and then repeating the calls. Ideally, I'd like to use apis to setup the data, but that is not possible now. So, I was thinking of putting UI automation code in my api automation code just to setup the data. Is this acceptable ? If not, then why ?

I don't see any challenges other than html locators getting changed, which would be very rarely for this web app.

  • 2
    If you can use the UI to create the data, why can't you mimic the underlying API calls? – ernie May 30 at 21:05
6

Creating test data via GUI will have the following impact:

  • test execution time will grow,
  • test will become 'flaky', results will not be trusted,
  • test will be prone to errors due to html changes,
  • if you use CI you will become dependent on browser,
  • or will have to write browser independent code,

I suggest creating the data straight in the database (if possible), if not you can separate the jobs, so if test data creation fails test are not executed (this might help a little with trust issues, but you will still encounter all other problems).

  • 3
    +1 Good answer with one exception: relying on DB structure is a bad idea in tests. Of course, both API and DB structure can be objects of change, but APIs tends to be versioned (so you can still use v1 when changes are introduced to v2) while DB structure does not. I know relying on DB might be practical for an immediate solution but for a long-term solution it would be better to ask devs to expose API for data setup. – dzieciou May 30 at 10:48
  • how would ci make the automation dependent on browsers ? one browser is enough for the automation. the goal is to create test data with the browser, and not test the ui. – MasterJoe2 Jun 4 at 18:22
  • What I meant by the browser dependency is that your CI will need a browser installed to run the tests. It should be "browser" not "browsers" I have edited it. – Moro Jun 4 at 19:47
1

Generally, It is not an optimal idea to use UI automation for data setups for your API tests because of inherent slowness and flakiness.

Ideally, you should pair with the dev and understand the data source from where this GET API is getting results from (Could be a Redis cache, database or flat file). Once you understand the mechanics, you can manipulate that to set up your test data.

As an idea, you can also create a test API/Script to set this data up.

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.