TestCafe unique features

Ryan Song
5 min readSep 8, 2020

Part two of the comparison between Selenium(Java) and TestCafe (Javascript)

Many readers are interested in knowing more about TestCafe’s unique features compared to Selenium. In this article, I am going to discuss two TestCafe’s features, one is unique to TestCafe (mobile web app testing), and the other one is more accessible compared to Selenium (concurrent and parallel testing). Limited by the length of the article, I am not going to provide all the Selenium implementation details.

  1. Mobile Web App Testing

The definition of mobile web app testing is testing a web browser via IOS or Android devices. Many start-ups or midsize companies will only have a website, and the website will display different designs based on the screen sizes of the browsing devices (e.g. desktop, tablet, or mobile). There is a good chance that the desktop view is perfect, yet the mobile web app view shows a broken design. Therefore, testing the mobile web app view is essential. Selenium does not support testing on mobile devices, a workaround is to use Appium for web app testing. Since Appium’s installation and configuration are complicated and its implementation will take up a full article, I will only go over the TestCafe implementation when testing the mobile web app view.

TestCafe lets you run tests on your real mobile devices or simulators as long as you run them under the same Wi-Fi network. The test scripts you wrote for the desktop view can also be used for your mobile web app view. All you need to do is to run the command in the console and an URL will be populated for your tests.

testcafe remote tests/test.js
Image is from TestCafe documentation

You can copy and paste this URL to your mobile devices or simulators on your desktop, a test will start running after you click on the URL.

If you are using a company testing device and are not able to send the URL to the device, the workaround is to use a QR code instead of copying and pasting the URL. When you run the command with the QR code option in a console, a QR code will be displayed on the page. After you scan the QR code using the test device, and the test run will start.

testcafe remote tests/test.js --qr-code
Image is from TestCafe documentation

If you want to check the mobile web app view designs without a mobile testing device nor a simulator on your desktop machine, the workaround is to emulate a device or customized device screen size. For example, If you want to test the design for IphoneX, just run the command in the console and an emulated IphoneX screen size will display on the web browser.

testcafe "chrome:emulation:device=iphone X" tests/sample-fixture.js

If you want to test a device with a customized screen size, just specify the specs in the command.

testcafe"chrome:emulation:width=100;height=200;mobile=true;orientation=vertical;touch=true" tests/sample-fixture.js

Summary: Compared to Appium’s complicated implementation, TestCafe supports mobile web app testing conveniently without the need for additional servers, libraries or wiring to a real device.

2. Concurrent and Parallel testing

Concurrent testing means running test cases concurrently. Assuming that you need to run 50 test cases in a browser and each test case takes one minute, the total testing time is 50 * 1= 50 minutes. If you spin up five same browsers and run all 50 test cases concurrently, then each identical browser will run 10 test cases. The currently testing time is (50/5) * 1 = 10 minutes.

Parallel testing is to run test cases on different browsers simultaneously. For example, if you run 50 test cases on a Chrome browser and then you run the same 50 test case on a Safari browser, the total testing time is 50 * 1 + 50 * 1 = 100 minutes. If you spin up one Chrome browser and one Safari browser to run all the tests in simultaneously, the parallel testing time is (50 * 1 + 50 * 1)/2 = 50 minutes.

In Selenium, running concurrent testing requires using additional testing frameworks such as TestNG. Should you desire to run parallel testing, you will need to configure the Selenium Grid or cloud-hosted platforms, such as Saucelabs or BrowserStack. Again, I will not elaborate on the Selenium implementation. Following is the TestCafe example of concurrent and parallel testing.

For concurrent testing, enter the command below in the console. This command means you initiate TestCafe and open 5 Chrome browsers, then run all 50 tests concurrently in each browser. TestCafe will automatically assign all the test cases inside the test.js file to five Chrome browsers evenly.

testcafe -c 5 chrome tests/test.js

When running the tests in Safari or Chrome headless mode, simply update the command from Chrome to Safari or Chrome:headless.

testcafe -c 5 Safari tests/test.js
testcafe -c 5 chrome:headless tests/test.js

For parallel testing, we can run all 50 tests in Chrome and Safari browser inside the test.js file in parallel. Following the command below, you initiate TestCafe and open two browsers, a Chrome browser and a Safari browser. The Chrome browser will run all 50 test cases inside the test.js file one by one. Meanwhile, the Safari browser will also run the same test cases in parallel.

testcafe chrome,safari tests/test.js

Additionally, you can combine both concurrent and parallel testing features and use them at the same time. For example, the command below allows you to initiate TestCafe and open five Chrome browsers and another five Safari browsers. 50 test cases inside test.js file will be distributed to five Chrome browsers and be run concurrently. Meanwhile, the same 50 test cases are also distributed to five Safari browsers and be run concurrently.

testcafe -c 5 chrome,safari tests/test.js

As you can see, the concurrent and parallel testing features in TestCafe allow you to run test cases more efficiently. These features can be run on any supported browsers installed on your desktop machine without downloading any drivers.

Officially Supported Browsers
-Google Chrome: Stable, Beta, Dev and Canary
-Internet Explorer (11+)
-Microsoft Edge (legacy and Chromium-based)
-Mozilla Firefox
-Google Chrome mobile
-Safari mobile

In a real case scenario, I have 30 test cases and it would take 25 mins to run all the tests one by one. Using TestCafe concurrent testing, I was able to spin up 6 Chrome browsers on my MacBook Pro and deliver the task under 5 minutes. Overall, the support of mobile web app testing, concurrent and parallel testing features are great incentives to give TestCafe a try. For small and mid-size companies in particular, the cost moving from Selenium to TestCafe is very low, all you need to do is just type npm install -g testcafe in the console and you can have all those cool features.

  • More comparisons in the next story.

[1]: Code source and examples: