• Stars
    star
    253
  • Rank 160,776 (Top 4 %)
  • Language
    TypeScript
  • License
    ISC License
  • Created about 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

cypress-plugin-steps

TypeScript
64
star
2

trelloapp

JavaScript
56
star
3

cypress-tau-course

JavaScript
41
star
4

cypress-plugin-xhr-toggle

TypeScript
30
star
5

trelloapp-vue-vite-ts

TypeScript
28
star
6

udemy-cypress-course

Companion repo for course: Cypress automation for people in a hurry
JavaScript
19
star
7

testing-lists

JavaScript
15
star
8

testing-pdf-with-cypress

TypeScript
9
star
9

how-to-start-with-cypress

Repository for How to start with Cypress workshop
JavaScript
9
star
10

playwright-vs-cypress-stability

TypeScript
7
star
11

learn2cypress

JavaScript
5
star
12

cypress-core-workshop

JavaScript
5
star
13

tau-workshop

TypeScript
5
star
14

slidev-theme-excali-slide

CSS
4
star
15

filiphric.com

Personal blog
Vue
4
star
16

testing-api

TypeScript
4
star
17

usertesting-workshop

JavaScript
4
star
18

cypress-basics-tau

JavaScript
4
star
19

mini-testing-united

TypeScript
3
star
20

cypress-flakiness-debug-examples

This is a project containing different examples of flaky tests. The aim of this project is to walk you through each case, provide an explanation and suggest a possible fix either on the test, or the app (possibly both).
TypeScript
3
star
21

filiphric.com-new

Personal blog, written in Nuxt 3
Vue
2
star
22

understanding-coverage

JavaScript
2
star
23

tesena-cypress-course

JavaScript
2
star
24

cypress-api-testing

JavaScript
2
star
25

cypress-selectors

HTML
2
star
26

cypress-advanced-tau

TypeScript
2
star
27

start-with-cypress-webinar

TypeScript
2
star
28

todomvc-expanded

expanded todomvc with login, signup and drag and drop
JavaScript
2
star
29

online-cypress-workshop

JavaScript
2
star
30

command-palette

JavaScript
1
star
31

cypress-pro-test-talk

TypeScript
1
star
32

javascript-days-workshop

JavaScript
1
star
33

cypress-cookies

JavaScript
1
star
34

gb-tools

Vue
1
star
35

applitools-selectors-webinar

Vue
1
star
36

testing-links

TypeScript
1
star
37

skillmea-cypress-kurz

TypeScript
1
star
38

introduction-to-cypress-workshop

Vue
1
star
39

cypress-api-module-workshop

JavaScript
1
star
40

wearedevs-workshop

TypeScript
1
star
41

cypress-typescript-module-workshop

TypeScript
1
star
42

tesena-workshop-cypress

JavaScript
1
star
43

workshop-edtell

TypeScript
1
star
44

the-road-from-hell-called-end-to-end-tests

Vue
1
star
45

cypress-best-practices-module-workshop

TypeScript
1
star
46

cypress-bootcamp

JavaScript
1
star
47

cypress-workshop

JavaScript
1
star
48

moodys-cypress-workshop

JavaScript
1
star
49

multiple-redirects

HTML
1
star
50

testing-visibility

HTML
1
star
51

geostqb-2021

JavaScript
1
star
52

knowit-cypress-workshop

JavaScript
1
star
53

krone-breakfast

JavaScript
1
star