Issues in testing REST API using Cypress in corporate env #20963
Unanswered
anithiya
asked this question in
Questions and Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am working in a corporate environment. I need to test certain APIs using Cypress. The major challenge I have is I need to call APIs which require Client Certificates to be passed. However, the Client Certificates are not being detected by Cypress.
I followed the steps laid out to for configuring proxy as explained in: https://docs.cypress.io/guides/references/proxy-configuration#Set-a-proxy-on-Linux-or-macOS
I am able to test the UI using Cypress in our corporate env.
However, when testing with REST APIs, i followed the steps here to capture the ClientCertificates as our API use certs for auth.
https://docs.cypress.io/guides/references/client-certificates
But I get a timeout error:
`CypressError
cy.request() failed trying to load:
https://apiendpoint1.com:1234/v1/resourceName
We attempted to make an http request to this URL but the request failed without a response.
We received this error at the network level:
CYPRESS.JSON
{ "viewportHeight":1080, "viewportWidth":1920, "testFiles": "**/*.{feature,features,js}", "defaultCommandTimeout": 60000, "responseTimeout":120000, "supportFile": "cypress/support/index.js", "reporter":"mochawesome", "reporterOptions": { "reportDir": "cypress/results", "overwrite": false, "html": true, "json": false }, "pageLoadTimeout": 120000, "env": { "testEnv": "qa", "apiendpoints":{ "apiendpoint1": "https://apiendpoint1.com:1234", "apiendpoint2": "https://apiendpoint2.com:1234" } },"clientCertificates": [ { "url": "https://apiendpoint1.com:1234", "ca": [], "certs": [ { "pfx": "cypress/certs/certs.jks", "passphrase": "cypress/certs/pass_phrase.txt" } ] }, { "url": "https://apiendpoint2.com:1234", "ca": [], "certs": [ { "pfx": "cypress/certs/certs.jks", "passphrase": "cypress/certs/pass_phrase.txt" } ] } ] }
SPEC.JS
`describe("SampleTest", () => {
it('gives a response matching a fixture object', () => {
let requestBody = "{ 'name':'nameValue','address':'addressVal'}";
cy.request({
method: 'POST',
url: Cypress.env("apiendpoints").apiendpoint1 + "v1/resourceName",
body: requestBody
})
.then((response) => {
expect(response.body).to.have.property('code', 200);
})
})
})
`
Environment Variables:
HTTPS_PROXY=http://corporateproxy.com:443/
HTTP_PROXY=http://corporateproxy..com:80/
NODE_EXTRA_CA_CERTS=C:\Users\usrname.dotfiles\bundle.crt
NODE_HOME=C:\Program Files\nodejs
NODE_TLS_REJECT_UNAUTHORIZED=0
NO_PROXY=*.apiendpoint1.com, *.apiendpoint2.com
Beta Was this translation helpful? Give feedback.
All reactions