Using API calls to speed up selenium tests

  • Once I test a certain part of the website, I don't repeat that process again. For example, if I tested creating a 'Stackoverflow question'(which takes 10 seconds on UI), and if I need to test some other part that requires that question, I just create that scenario with an API call(which is created almost instantly).

    What would be the drawbacks of this technique? Can I do this in every project?

  • This is a just your test data generation strategy. As with any strategy, it will have a balance between:

    • Maintainability cost x execution time;
    • Test code simplicity x test code flexibility;

    It will be a contextual decision on how and when to do X or Y.

    A good strategy to discover the best approach is to follow the DTSTTCPW principle: "Do the simplest thing that could possibly work". The implementation action will give you a better understanding of each problem. And with that, you may decide to refactor your solution.

    enter image description here

    E.g., given that you have test that requires 10 questions to be created. If you have a flow that creates a question using Selenium, simply use it. Then analyse what you get: Maybe the remaining part of this test takes 5 times the test data creation time - or maybe it takes 1/4 of the time to create the test data. In the first case, working on an API script maybe not the best approach; on the second one, it maybe the best approach.

    Other point you may consider on the above is the stability of the procedure to create the question with Selenium and the stability of the API. Which one can you rely the most, in order to decrease maintenance cost?

Log in to reply

Suggested Topics