Qytera-Gmbh / cypress-xray-plugin

A plugin for uploading Cypress test results to Xray.
https://qytera-gmbh.github.io
MIT License
21 stars 7 forks source link

Error: `Cannot read properties of undefined (reading 'key')` #119

Closed Dhaval8087 closed 1 year ago

Dhaval8087 commented 1 year ago

cypress-xray-plugin version - 3.3.3 cypress version - 12.16.0 I am trying to upload the e2e test execution into Xary server, I am getting error like

Cypress Xray Plugin | ERROR | Failed to upload results to Xray: "TypeError: Cannot read properties of undefined (reading 'key')"

Please find the cypress config

// @ts-ignore
import {defineConfig} from "cypress"
import { addXrayResultUpload, configureXrayPlugin } from "cypress-xray-plugin/plugin"

export default defineConfig({
  reporter: 'junit',
  video:false,
  reporterOptions: {
    mochaFile: 'cypress/results/output.xml',
  },
  e2e: {
    // We've imported your old cypress plugins here.
    // You may want to clean this up later by importing these.
    async setupNodeEvents(on, config) {
        // implement node event listeners here
        await configureXrayPlugin({
          plugin: {
            debug: true,
            overwriteIssueSummary: true
          },
          jira: {
              projectKey: "projectkey",
              url:"jiraurl"
          },
          xray: {
            statusPassed: "SUCCESS",
            uploadResults: true
         },
      });
      await addXrayResultUpload(on);
    },
    baseUrl: 'base url',
  },
})

my test.cy.ts file looks like


//@ts-nocheck

describe('The UserName/Password Field', () => {
    beforeEach(()=>{
        cy.visit('/')
    });
    it("Load the Kuma Title", () => {
      cy.get('input[name="username"]').type('username');
      cy.wait(500);
      cy.get('[data-cy="login"]').should('exist').click();
      cy.wait(4000);
      cy.get('[data-cy="kuma"]').should('exist').click();
      cy.wait(2000);
    });
});

in Gitlab CI it's throwing the type error "Failed to upload results to Xray: "TypeError: Cannot read properties of undefined (reading 'key')"

image

csvtuda commented 1 year ago

Hey @Dhaval8087,

thank you for raising the issue. I see that you have debug logging enabled and your screenshot tells me that the results import request went through just fine (the results should actually have been imported, despite the error).

Can you check what the data property contains in file GET_https_[...]_import_execution_1690047539266_response.json? It should usually contain something like:

data: {
  testExecIssue: {
    key: "PROJECT-12345"
  }
}

If you've deleted it, please repeat the scenario and check the file contents of the response received just before the error occurs.

Dhaval8087 commented 1 year ago

@csvtuda Hey Sorry for the late reply , I have attached a log file of GET_https_jira_rest_raven_latest_api_import_execution_1690178879367_response.json file

logs.txt

csvtuda commented 1 year ago

Thank you for the logs. Based on the information you've provided so far, everything seems fine:

The only curious thing is that the response debug message is a GET response and contains a login page as content, although a POST was sent.

When I try to access one of the publicly available API endpoints (which can be accessed anonymously/without credentials) of your Jira instance :

curl https://skyway.porsche.com/jira/rest/api/2/dashboard

it redirects me:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
   <head>
      <title>302 Found</title>
   </head>
   <body>
      <h1>Found</h1>
      <p>The document has moved <a href="https://skyway.porsche.com/crowd/plugins/servlet/saml-login?redirect=%2fjira%2frest%2fapi%2f2%2fdashboard">here</a>.</p>
   </body>
</html>

Ideally, the response should look something like this:

{
   "startAt":0,
   "maxResults":20,
   "total":1,
   "dashboards":[
      {
         "id":"10000",
         "name":"System Dashboard",
         "self":"https://skyway.porsche.com/jira/rest/api/2/dashboard/10000",
      }
   ]
}

Can you make sure to use the actual Jira URL instead of the one which leads to redirects? If the same error occurs, the 2FA might be the problem.

Dhaval8087 commented 1 year ago

@csvtuda Hey Thanks for your help , yes I have tried with actual URL for calling the API and it's work, Thank you so much for your help here