AMA: JavaScript in Test Automation

Max asks…

First of all thanks for sharing all your insights on this blog. I regularly try to come back to your blog and I helped me grow as a QA Engineer quite a lot.
I wanted to ask you on your opinion on a seemingly new generation of test tools for the web that are written in JavaScript to help deal with all the asynchronicity on modern front end frameworks. Our company is in the process of redesigning our website and it seems that it just gets harder and harder to deal with all the JavaScript in test automation. I recently started looking into some other tool like cypress.io, but as of now they still seem quite immature.
Could you help me and point me in the right direction?

My response…

I think there’s two parts to the JavaScript asynchronicity issue which are not necessarily related.

Modern JavaScript front-end web frameworks (like React and Angular) are designed to be asynchronous and fast and therefore this can cause issues when trying to write automated tests against them. I don’t believe writing automated tests in an asynchronous way actually makes the tests easier to write, or more maintainable or robust, but just a result of writing these tests in the same way the web frameworks work.

You can write synchronous tests (like using Watir/Ruby) against asynchronous web interfaces, you just need to use the waiting/polling mechanisms (or write/extend your own) – the same as you need to do in asynchronous test automation tools.

We choose WebDriverJS for automated end-to-end testing of our React application as it was the official WebDriver for JavaScript project and seems to be a good choice at the time. I somewhat regret that decision now as using a synchronous third party implementation like webdriver.io seems like an easier way to write and maintain tests.

I have tried to use cypress.io but the way it controls sites (through proxies) has (current) limitations like not working on iFrames and cross-domains which are deal-breakers for our end-to-end testing needs at present.

If you don’t need to write your end-to-end tests in JavaScript I’d say avoid it unless absolutely necessary and stick to another non-asynchronous programming language.

I’m glad I’ve been able to help you grow over the years.

Author: Alister Scott

Alister is a Software Quality Engineer for Automattic.

2 thoughts on “AMA: JavaScript in Test Automation”

  1. Hi, I am truly stunned by the number of professional programmers saying that writing tests with Javascript is too “hard”. Using WebdriverJS I’ve been able to automate all sorts of scenarios and the difficulties almost never had anything to do with asynchronicity. When Selenium had the promise manager everything was taken care of. Now that it’s deprecated simply use async/await. There should never be an issue. Any decent JS programmer should know how to code with promises, it’s not that hard once you get past the initial hurdle, it’s a simple concept really. Admittedly I am very junior in my QA career, so perhaps I haven’t had to deal with advanced scenarios. But I really can’t see the difficulty in using Javascript that working with something like Python might solve. Cheers!

    Like

  2. I am truly stunned by the number of professional programmers saying that writing tests with Javascript is too “hard”.

    It’s not too hard, it’s just relatively harder than using say ruby or python, particularly for people already experienced in those languages

    Admittedly I am very junior in my QA career, so perhaps I haven’t had to deal with advanced scenarios.

    It sounds like have a strong career ahead of you, well done and good luck

    Like

Comments are closed.