Intility / cypress-msal

A cypress plugin for projects using @azure/msal-browser.
MIT License
17 stars 0 forks source link

Plugins folder not supported #2

Open AlphaGeek opened 1 year ago

AlphaGeek commented 1 year ago

Docs say to include the code with the publicClientConfig, module.exports, etc in the /plugins/index.js file however I am using Cypress 10.4 and the plugins folder is no longer supported. Is there an example of how to use this with Cypress 10+?

xec commented 1 year ago

Ah yes, they changed cypress config in 10.* :(

It should be fairly similar though, can you test something like this and see if it works for you?

in cypress.config.js (should be on project root, not under cypress/, I believe)

import { defineConfig } from 'cypress'
import generateLogin from '@intility/cypress-msal'

let publicClientConfig = {
  auth: {
    clientId: "APP_CLIENT_ID",
    authority: "https://login.microsoftonline.com/TENANT_ID",
  },
};

let requests = [
  {
    scopes: ["User.Read"],
  },
];

let login = generateLogin(publicClientConfig, requests);

export default defineConfig({
  // ...other cypress settings here...
  e2e: {
    setupNodeEvents(on, config) {
      // `on` is used to hook into various events Cypress emits
      on('task', {
        // register a task named login which calls the generated login from @intility/cypress-msal
        login
      })
    }
  }
})
AlphaGeek commented 1 year ago

Thanks, tried this but am getting the error below...may be due to the import { defineConfig } from 'cypress' line:

ReferenceError The following error originated from your test code, not from Cypress.

process is not defined

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure. node_modules/ci-info/index.js:5:1 3 | const vendors = require('./vendors.json') 4 |

5 | const env = process.env | ^ 6 | 7 | // Used for testing only 8 | Object.defineProperty(exports, '_vendors', {

h3rmanj commented 1 year ago

Hi @AlphaGeek, I merged the updated getting started section, which hopefully resolves your issue 😊

AlphaGeek commented 1 year ago

still getting the "login is not a function" error in the before()

using latest Cypress version

xec commented 1 year ago

still getting the "login is not a function" error in the before()

using latest Cypress version

@AlphaGeek can you share (the important parts of) your config / setup?

AlphaGeek commented 1 year ago

cypress.config.ts (does it matter that it is a TS file?) [client_id] is replaced by our QA client id and [tenant] is replaced by our tentant

import { defineConfig } from "cypress"; import generateLogin from "@intility/cypress-msal"

let publicClientConfig = { auth: { clientId: "[client_id]", authority: "https://login.microsoftonline.com/[tenant]", }, };

let requests = [ { scopes: [our_scope], }, ];

let login = generateLogin(publicClientConfig, requests);

export default defineConfig({ e2e: { defaultCommandTimeout: 20000, "retries": { // Configure retry attempts for cypress run // Default is 0 "runMode": 2, // Configure retry attempts for cypress open // Default is 0 "openMode": 2 }, "viewportHeight": 1080, "viewportWidth": 1920, "baseUrl": "https://localhost:5173", //"https://summitqa.blairnet.net" "redirectionLimit": 5, "specPattern": "cypress/e2e/*/.{js,jsx,ts,tsx,feature}", setupNodeEvents(on, config) { on("task", { // register a task named login which calls the generated login from @intility/cypress-msal login, }); } } });

my cypress test (smokeTest.js):

describe("Ensure site is up and running", () => { /before(() => { cy.exec('npm run get-token') cy.wait(1000) })/ before(() => cy.login());

it("Home page should open", () => { cy.visit("/")
cy.wait(14000) })

it("Should display the WB logo", () => { cy.get('.logo').should('be.visible') })

it("Should have All Active silos", () => { cy.get('.p-carousel-item-active').contains('All Activity') })

it("Should have Trading Desk Commentary silos", () => { cy.get('.p-carousel-item-active').contains('Trading Desk Commentary') })

after(() => { cy.exec('npm run clear-token') }) })

run using "npx cypress open"

currently running 10.11.0 of Cypress but have tried with 12.* and had same issue

AlphaGeek commented 1 year ago

tried using: before(() => cy.task('login')); instead of: before(() => cy.login); and that seemed to help in that I think it found it but then it timed out

h3rmanj commented 11 months ago

Sorry the late response, we haven't really had time to maintain this package. Just ran into something similar myself; https://github.com/Intility/cypress-msal/issues/5#issuecomment-1824552340

Did you find another solution to your problem?