GithubHelp home page GithubHelp logo

ssamoustafa / cypress-plugin-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from filiphric/cypress-plugin-api

0.0 0.0 0.0 2.32 MB

Cypress plugin to show your API information in the Cypress UI runner

License: ISC License

Shell 0.16% JavaScript 7.80% TypeScript 63.95% CSS 10.34% HTML 0.04% Vue 17.71%

cypress-plugin-api's Introduction

Cypress plugin API

Cypress plugin for effective API testing. Imagine Postman, but in Cypress. Prints out information about the API call in the Cypress App UI.

Cypress plugin for testing API

Features

Installation

Install this package:

npm i cypress-plugin-api
# or
yarn add cypress-plugin-api

Import the plugin into your cypress/support/e2e.js file:

import 'cypress-plugin-api'
// or
require('cypress-plugin-api')

Usage

You can now use cy.api() command. This command works exactly like cy.request() but in addition to calling your API, it will print our information about the API call in your Cypress runner.

Snapshot only mode

If you want to combine your API calls with your UI test, you can now use snapshotOnly mode, that will hide the plugin UI view after command ends. You can access it within the timeline.

snapshotOnly mode is set to false by default. To set up snapshotOnly mode, add following to your test configuration:

it('my UI & API test', { env: { snapshotOnly: true } }, () => {

  cy.visit('/') // open app
  cy.api('/item') // call api
  cy.get('#myElement') // still able to access element on page

})

or you can add the configuration to your cypress.config.{js,ts} file:

import { defineConfig } from 'cypress'

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
    },
    env: {
      snapshotOnly: true
    }
  },
})

Hiding credentials

You can hide your credentials by passing hideCredentials option to your env configuration. This will hide all the credentials from UI, but you can still access them via console. This option is set to false by default.

it('my secret test', { env: { hideCredentials: true } }, () => {

  cy.api({
      url: '/',
      headers: {
        authorization: Cypress.env('myToken')
      }
    })

})

The result will look like this:

Cypress plugin for testing API

You can also hide any credentials you want by defining array of keys in hideCredentialsOptions,

it('my secret test', { 
  env: { 
    hideCredentials: true, 
    hideCredentialsOptions: {
      headers: ['authorization'],
      auth: ['pass'],
      body: ['username'],
      query: ['password']
    }
  }
}, () => {

  cy.api({
      url: '/',
      headers: {
        authorization: Cypress.env('myToken') // hidden
      },
      auth: {
        pass: Cypress.env('myPass') // hidden
      },
      body: {
        username: Cypress.env('myUser') // hidden
      },
      qs: {
        password: Cypress.env('password') // hidden
      }
    })

})

This will override all the defaults set by hideCredentials.

requestMode - enable UI for cy.request() command

This setting adds all the functionality of cy.api() command to cy.request(). It’s set to false by default. This means that when you call cy.request() in your test, it will show UI.

TypeScript support

In most cases, types work just by installing plugin, but you can add the types to your tsconfig.json

{
  "types": ["cypress-plugin-api"]
}

This will add types for cy.api() command, it’s returned values as well as env properties.

Issues

All the issues can be found on issues page, feel free to open any new ones or contribute with your own code.


...powered by coffee and love ❤️ Filip Hric

cypress-plugin-api's People

Contributors

dodosaurus avatar filiphric avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.