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.
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.
npm install –g testcafe ————- for windows platform
sudo npm install –g testcafe ————–for linux platform
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.
Now if you will run this test with the help of command testcafe yourfilename.js; then testcafe will emulate the actions defined by you.
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
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!’);
});
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.