• info@testbytes.net
  • +91 811 386 5000
  • HR: +91 8113 862 000
whatsapp

Learn How to Use Testcafe For Creating Testcases Just Like That

Testcafe

TestCafe is an open source end-to-end browser testing tool released by DevExpress. This Node.Js open source framework is used to automate end-to-end web testing.

app testing

Astounding Features of Testcafe is that it is compatible with Windows, Mac and Linux. It also supports testing of desktop, mobile, remote and cloud browsers. Since installing Selenium webdriver and its libraries are tedious, Testcafe serves as an easy to handle alternate.

  • First of all let’s dive into the benefits of using TestCafe over others like Selenium/ UFT.
  • Downloading the software and creating test cases doesn’t take more than 5 minutes.
  • You can run tests in any browser without much effort (IE9+, Chrome, Firefox and Safari)
  • With the help of TestCafe you can run your test on multiple OS (Windows, Mac and Linux)
  • Without any extra server for multiple platform support TestCafe run tests in parallel browsers and on multiple machines.
  • TestCafe is 100% web based
  • No headache of writing code as assertions is added via a visual editor. Element selection process is very easy when it comes to TestCafe.
  • Record and play option
  • Tests made by TestCafe are purely based on JavaScript which directly communicates with DOM.
  • Learning TestCafe API’s is easy compared to Selenium’s APIs. Testcafe exposes a minimum number of APIs to learn.
  • It is affordable with flexible licensing. You will also get 12 month dedicated support.
  • Now let’s look at the steps which are involved in installing TestCafe and creating test cases.
  • First prerequisite is installation of node.js in your system. If you have node.js installed in your system then you can install packages with the help of npm command.

npm install –g testcafe                                                                 ————- for windows platform

sudo npm install –g testcafe                                                      ————–for linux platform

  • Once you are ready with installation; let’s look at the main steps to create tests. You can open any editor or IDE and make one file with extension as .js

First you have to define a text fixture whose value will contain the web app link you want to test.

Fixture ‘First practice fixture’

                .page ‘http://devexpress.github.io/testcafe/example/’;

Now you know that Node.js is asynchronous and non-blocking in nature. So, now comes a turn to declare your first testcase which you can define by

test(‘ My first test’, async t => {});

Now your fixture and first test case is ready. Now add the code to your first test case to test functionalities.

You can run this blank test by first saving the test with .js extension. Then, you can type the following command in console:

testcafe yourfilename.js

After running this blank testcase your test case will be tested against the browser explicitly mentioned. Else, it will automatically detect Google Chrome in your system and then it will open it. Hence; your test would be tested against the browser.

Now let’s add code to our first test

As of now our main structure is ready.

Fixture ‘First practice fixture’

.page ‘http://devexpress.github.io/testcafe/example/’;

test(‘ My first test’, async t => {

await t

.typeText(‘#developer-name’, ‘Nancy Tuli’);

.click(‘#macos’);

.click(‘#submit-button’);

});

What the above code will do is open Google Chrome browser and then loads the specified URL into the browser. The 3 lines of code which is defined in the test are to type ‘Nancy Tuli’ into the Developer-name field and then it will select the macos radio button. At last, it will click on the submit button.

testbytes-mobile-app-testing-banner

Now if you will run this test with the help of command testcafe yourfilename.js; then testcafe will emulate the actions defined by you.

  • You can even have a page object model with test case. In the pages.js files you can define the locators with the help of testcafe web integrated version. After having the pages of your application; you can make object of those pages and then use those locators.

Let’s suppose you have a page page.js

In the driver Script you can make object of this page by

Const page = new page();

Now you can use its locators by (.) operator.

Page.interfaceselect

Page. Macosselectbutton

  • Now in a test case you always have lot of things to verify. There is an assert statement which you will get to know from this underlying example. Let’s say after the first test a message pops up which says “Thank you, Nancy Tuli!”
  • For assertions you have to import Selector for the article header and then you can get its inner text. With this inner text you will be able to verify whether the text is present or not.

import {Selector} from ‘testcafe’;

Fixture ‘First practice fixture’

.page ‘http://devexpress.github.io/testcafe/example/’;

test(‘ My first test’, async t => {

await t

.typeText(‘#developer-name’, ‘Nancy Tuli’);

.click(‘#macos’);

.click(‘#submit-button’);

.expect(articleHeader.innerText).eql(‘Thank you, Nancy Tuli!’);

});

  • You must be amazed that till now addition of any kinds of explicit and implicit wait in the program has not taken place as we do in Selenium and UFT. Yes, you are right! TestCafe has brilliant automatic wait mechanism which takes care of all wait relates stuffs. You don’t have to introduce any kind of code for wait so that actions could be completed on time. Though, you can change the maximum wait time in testcafe itself.
  • The best thing about testcafe is its easy integration with CI/CD system. If you have a Jenkins server on which you tests would be running then no need to worry as testcafe can be integrated with Jenkins, Travis and TeamCity; and you can run all your test scripts from console.

mobile app

So, now you got to know how beneficial testcafe for testing your web apps is. You don’t need to code as it gives you ability to record and play. Even manual testers will find it easy to operate the software.

Testbytes