cy.request with FormData and QueryString

correct FormData snippet

please pass form: true and with the payload as body rather than use FormData

cy.request({
    url,
    method: "post",
    headers: {
      Authorization: "Basic xxx",
      Accept: "*/*",
      "Cache-Control": "no-cache",
      "Accept-Encoding": "gzip, deflate, br"
    },
    form: true,
    body: {
      "xxx":"yyy"
    }
  }).then((response) => {})

I tried create a FormData object and past it as body, but didn't work.

correct QueryString snippet

please pass qs with a JSON object rather than use URLSearchParams

cy.request({
      url,
      method: "post",
      headers: {
        Authorization: `Bearer ${access_token}`,
      },
      qs: {
        "parametername": "parametervalue"
      }
    });

I tried create a URLSearchParams  object and past it as qs, but didn't work.

cy.intercept won't work if the request not send by browser or send via cy.request

the below code will not work. the wait for the request alias will timeout with error: expect request of url but never occurred.

const url = "your api"
cy.intercept(url).as("yourapi");
cy.request(url);
cy.wait("@yourapi");

Comments

Popular posts from this blog

How to fix error : no module named sendgrid when try to use sendgrid python lib in PHP.

react-native run-android : sun.security.provider.cert path.SunCertPathBuilderException : unable to find valid certification path to req uested target

react-native run-android : do not build/update modified code(App.js)