automation-v

6.0.1 • Public • Published

Automation Core Library

This library provides the most common methods/steps to start any automation project.

Getting Started

npm install @jala/automation-core

Prerequisites

Create "automation.conf.js" file at the project root path, after the Automation Core library is successfully installed. The file should have the following content with at least one service:

exports.config = {
  "services": {
    "default": {
      "baseApi": "",
      "header": {
        "content-type": ""
      }
    }
  }
}

declare the automation alias for the recent file created

 "_moduleAliases": {
    "@auto_config": "automation.conf",
  },

Setting automation.conf.js file

Set the url services to execute the api tests.

exports.config = {
  "services": {
    "default": {
      "baseApi": "https://jsonplaceholder.typicode.com",
      "header": {
        "content-type": "application/json"
      }
    }
    "myapp": {
      "baseApi": "https://172.10.25.33:5050",
      "header": {
        "content-type": "application/json",
        "x_token": "FF12AFBC525DE54"
      }
    }
  }
}
  • services keys content the information to make request to the application api what we want automate
  • default keys imply that this is the main services or application what we want test another ones can be added adding the key to identify
  • baseApy key identify the base api to send adding in the rest of the endpoint in the steps
  • header keys set a header by default that the service or application requires

Writing a Test

create a cucumber file e.g. test/first-tc.feature write a test with steps already defined e.g.

Feature: post test
  Scenario: scenario test
    When I set a "GET" request to "/posts/1"
    And I send the request
    And I save the response as "place_holder_post"
    Then I expect the status code is equals than "200"
    And I expect the response "$.place_holder_post.title" contains "sunt aut" value
    When I set a "GET" request to "/posts"
    And I send the request
    Then I expect the status code is equals than "200"

Create a script command to execute test cases

"scripts": {
    "test": "cucumber-js test/*.feature --require node_modules/@jala/automation-core/src/*"
  },

call to cucumber-js command add the path where the TC are add -- required command with path were the core is found

Built With

Authors

License

========================================

API Documentations

Step Definitions

Structure

Apply builder pattern overstep definitions.

Builder Pattern Examples:

https://refactoring.guru/design-patterns/builder

https://sourcemaking.com/design_patterns/builder

Examples

Builder Steps

Create a Request

To create a request we should define the method 'POST, GET, PUT, DELETE' and endpoint '/person' this endpoint its concatenated with a base endpoint, in this also we can add JSON-query e.g. '/person/$.person.id' the JSON-query will get the value stored in context when saving the response

When  I set a "POST" request to "/person"

Modify the default Header

To modify the header by default and set up another the current request. This steps also can be used to add new values into header Note: Header step can be omitted since in the most of cases the content-type header is by default application/json

And   I set the following headers:
      | content-type    | application/vnd.api+json  |

Set as body a template

Create a template into the body to make a request this template gets using @alias.filename$.templateKeyName

I set  the "@templates.person$.employee" template

Set and modify as body a template

Setting and modifying a template this template gets using @alias.filename$.templateKeyName this values can be replaced using Json-query or a simple string

And   I set the "@templates.person$.employee" template replacing:
      | id     | $.buildingHook.id |

Set a Form-Data as body

Setting a form-data as body set a form data to send as body this step should have as header [key, type, value]

Note : This steps also set a header [application-type:multipart/form-data ] and adding the boundary of the form

    And I set form-data:
      | key  | type | value                 |
      | file | file | ./images/employee.png |
      | name | text | Juan Peter            |

Send a Request

send request setup

And   I send the request 

Store response

Save the response Body with a key name 'employee1' this is stores into the context and we can use this using json-query, into steps in order to get some values necessaries along of test execution

example to use

below we can review the response is saved as employee1, taking into account the response of the request returns the name and the id we can get these values using the following json-quries:

get Name: $.employee1.name
get Id: $.employee1.id
And I save the response as "employee1"

Expect status code

This can be applied after sending the request, this compares the status code of the last request sent

I expect the status code is equals than "200"

========================================

Automation Core Library Unit Tests and Code Coverage

To run the Unit Tests and Code Coverage please follow the next:

Unit Tests

This library has Mocha Unit Tests for almost all the src/**/* .js files, except for the cucumber steps js file.

Configurations

To run only the unit test you should first go to request_helper.js and replace:

const Config = require('../../../../../automation.conf').config;

with:

const Config = require('../../automation.conf').config;

Running

To run the unit test you should execute the following:

npm run test

Code Coverage

This library use NYC code coverage tool to ensure the code have unit tests. Follow the next to run it: The results are available in text as an output in command line and also as html in coverage folder (index.html)

Configurations

To run the code coverage script, perform the same configuration for the unit tests described above.

Running

To run the unit test you should execute the following:

npm run coverage

Readme

Keywords

none

Package Sidebar

Install

npm i automation-v

Weekly Downloads

2

Version

6.0.1

License

ISC

Unpacked Size

33 kB

Total Files

20

Last publish

Collaborators

  • lufercc