Sunday, September 20, 2020

TestCafe Setup

Getting Started


Make sure Node.js (version 6 or newer) and npm are installed on your computer.

Please refer this url for Node.js installer https://nodejs.org/en/download/ 

Check the Node and npm version in the terminal

Install the testcafe using npm

npm install -g testcafe

Creating the sample test

For sample test we are going to test https://devexpress.github.io/testcafe/example page.

Create a sample.js file.The file must have a special structure.

Tests must be organized into fixtures.

Copy paste the following code to see the test in action.

import { Selector } from 'testcafe'; // import testcafe selectors

fixture `Getting Started`// declare the fixture
    .page `https://devexpress.github.io/testcafe/example`;  // specify the start page


// Create a test and place your code there
test('My first test', async t => {
    await t
        .typeText('#developer-name', 'Saranraj')
        .click('#submit-button')

        // Use the assertion to check if the actual header text is equal to the expected one
        .expect(Selector('#article-header').innerText).eql('Thank you, Saranraj!');
});

Running the Test

Execute the following command in a terminal.

Specify the target browser and the test script path.

testcafe chrome sample.js

TestCafe automatically opens the chosen browser and starts test execution within it.

Viewing the Results

TestCafe outputs the results into a command shell by default.







Friday, September 18, 2020

TestCafe Architecture


  • TestCafe uses the web proxy called testcafe-hammerhead for URL-rewriting.

  • When a test script is executed the web proxy server spun up and it redirects the original URL provided in the test script to the URL-rewriting proxy server.

  • The URL-rewriting proxy server emulates the request to the web server. 

  • The web server reads the javascript test script file and checks the available tests.

  • The web server then sends the test case one by one to the URL-rewriting proxy and the each test will be executed on the web browser.

  • As soon as the test cases are executed the test case status is sent to the Web server via the URL-rewriting proxy.

  • In case if we are requesting the screenshots of the test case then the request will be sent to the browser directly from the web browser and the screenshot will be sent to the web server.







TestCafe Overview

 


 

  • TestCafe is a node.js tool to automate end-to-end web testing.

  • TestCafe is a product of DevExpress.

  • TestCafe uses a proxy in-between which performs URL rewriting and injects the test scripts into the browser.

  • Proxies manage all storage/cookies for the tests.

  • Clean and isolated test environment which is difficult to achieve in other web testing frameworks.

 

Main Features of TestCafe

  • TestCafe is an Open source framework.

  • 1 minute setup with just one command (npm install -g TestCafe).

  • While TestCafe is designed to support most modern browsers.

  • TestCafe don’t need an external driver to run end-to-end tests in the browser.

  • TestCafe detect all the browsers installed on your machines.

  • It can run tests in headless mode (Both in Chrome & Firefox browser).

  • Allow tests to run in parallel.

  • Live mode allows you to edit your TestCafe tests on the fly. Changes you make in the code will immediately restart the tests. And you'll see test results instantly.

  • TestCafe is easy to set up with most modern CI systems (Team City, Jenkins, Travis & etc.).

  • TestCafe supports latest JavaScript and TypeScript.






TestCafe Setup

Getting Started Make sure Node.js (version 6 or newer) and npm are installed on your computer. Please refer this url for Node.js installer h...