Why JavaScript Is Not a Suitable Language for Real Web Test Automation?

JavaScript is OK for developing apps, but not for functional test automation, where its audience beyond programmers. Ruby is a far better choice.

  • Objective evaluation of JS against the test scripting language criteria in the classic Agile Testing book.
    JavaScript scores poorly.
  • Human Factors
    Technically, anyone out of the five Selenium WebDriver official languages (Ruby, Python, Java, JavaScript, and Python) will work. As the audience of functional test automation is beyond the developers, the human factors matter.

1. Is your test automation with JavaScript actually useful? I doubt it.

Judging by an objective AgileWay CT Grading, every test automation attempt using JavaScript that I knew of failed at Level 0 (i.e. total waste of time). Have you ever worked on a successful Agile project in which automated end-to-end regression tests are written in JavaScript? Some probably would say “Yes”. My next questions are:

  • How many times do you run all these tests a day? twice or 3 times?
  • Does the team have the confidence to push a new build to production after passed automated regression testing?
Zhimin’s Selenium Recipes books

Judge against Criteria listed in ‘Agile Testing’ book

While a language preference is subjective, test automation is objective. Let’s evaluate JavaScript against the criteria for a good automated testing language in the classic “Agile Testing” book.

home_page.check_remmeber_me if site_url.include?("test")
[1, 2, 3, 4, 5].select(&:even?) #=> [2, 4]
[2, 2, nil, 1, 3].compact.uniq.sort #=> [1,2,3]
['female', 'male', 'unknown'].sample #=> a radom value in list
[].empty? #=> true
3.days.ago # after loading activesupport gem

Human Factors

The audiences of end-to-end automated tests are not just the developers. They include all the team members. This will change the perspective totally, won’t it?

(async () => {
const browser = await firefox.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://www.example.com/');
const dimensions = await page.evaluate(() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio
}
});
console.log(dimensions);

await browser.close();
})();
  • what is const ?
  • what is await ?
  • console.log
  • })()
  • Unnecessary NPM package.json (from testing perspective)
  • Large node_modules folder
  • Testers need to ask programmers’ help for JS syntax and tool use
var webdriver = require('selenium-webdriver')
var expect = require("chai").expect;
const timeOut = 10000;
describe("Mocha, Chai with raw Selenium", function() { it("Verify Title", async function() {
this.timeout(timeOut);
let driver = await new webdriver.Builder().forBrowser('chrome').build();
await driver.get('https://whenwise.agileway.net');
driver.getTitle().then(title => expect(title).to.equal("WhenWise - Booking Made Easy") );
driver.quit();
});
});
var webdriver = require('selenium-webdriver');
var test = require('selenium-webdriver/testing');
var assert = require('assert');
var driver;
const timeOut = 10000;
test.describe('Mocha Seleenium Testing', function() {test.it('Verify Title', function() {
this.timeout(timeOut);
driver = new webdriver.Builder().forBrowser('chrome').build();
driver.get("https://whenwise.agileway.net")
driver.getTitle().then(function(the_title) {
assert.equal("WhenWise - Booking Made Easy", the_title);
});
driver.quit();
});
});
  • title => expert(title) ... vs function(title) { ...
require "rspec"
require "selenium-webdriver"
describe "RSpec Selenium" do
it "Verify Title" do
driver = Selenium::WebDriver.for(:chrome)
driver.get("https://whenwise.agileway.net")
expect(driver.title).to eq("WhenWise - Booking Made Easy")
driver.quit
end
end
function  selectTripType(trip_type) {
// ...
}
class FlightPage extends AbstractPage {
constructor(driver) {
super(driver);
}
selectTripType(trip_type) {
// ...
}
}
  1. Develop a few automated tests; Start to promote it within the team, set up CI/CD… 😑
  2. Struggle to maintain existing test suite😓
  3. Many tests failed in CI/CD every day 😫
  4. Blame the framework/tool, go to Step 1 (or abort) 😭
  • The target technologies (web) have largely not changed
  • If one test automation engineer successfully implemented the test automation once, the knowledge and practices can be directly appliable to other projects

Award-winning software developer, test automation & CT coach, author, and speaker. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store