https://cypress.io logo
Join Discord
Powered by
# general-chat
  • f

    few-musician-79351

    03/09/2022, 7:19 PM
    Hey guys, has anyone tried cypress with github actions? I can't make it work, i have a env var but it appears that github actions can't recognize it
  • s

    stocky-dream-36427

    03/09/2022, 7:24 PM
    Does it work locally? Outside of CI?
  • s

    stocky-dream-36427

    03/09/2022, 7:26 PM
    The only GH-actions specific thing that might not work is that the env var might be case-sensitive...?
  • f

    few-musician-79351

    03/09/2022, 7:29 PM
    So it should be CYPRESS_HOST/PORT?
  • s

    stocky-dream-36427

    03/09/2022, 7:29 PM
    Yeah perhaps
  • s

    stocky-dream-36427

    03/09/2022, 7:29 PM
    it depends on how GH Actions works, but that's the first thing I'd try
  • f

    few-musician-79351

    03/09/2022, 7:49 PM
    Well, this is progress but what I don't understand its why it says port 3000 its in use
  • f

    few-musician-79351

    03/09/2022, 7:50 PM
    But if I use another port it returns this
  • f

    few-musician-79351

    03/09/2022, 7:50 PM
    Meaning that there is no such port in the tests, which is true
  • i

    important-river-75795

    03/09/2022, 8:11 PM
    @User try using CYPRESS_BASE_URL instead of HOST and PORT
  • i

    important-river-75795

    03/09/2022, 8:12 PM
    Like this env: CYPRESS_BASE_URL: http://localhost:3000
  • i

    important-river-75795

    03/09/2022, 8:13 PM
    Also probobly just want to set the same thing in the cypress.json file
  • i

    important-river-75795

    03/09/2022, 8:13 PM
    Then you don't even need the env variable in github actions
  • s

    stocky-dream-36427

    03/09/2022, 8:13 PM
    😮‍💨 you're totally right @User
  • p

    powerful-orange-86819

    03/10/2022, 9:27 AM
    dont forget to change the cy.visit("/") from (url)
  • m

    melodic-apple-72412

    03/10/2022, 1:01 PM
    Hi, I have written a overwrite custom command for request, since I need to add an additional header
    Copy code
    Cypress.Commands.overwrite('request', (originalFn, ...args) => {
      cy.getCookies()
        .then((Cookie) => {
          const defaults = {
            headers: {
              'X-XSRF-TOKEN': Cookie[1].value,
              'Content-Type': 'application/json'
            }
          };
          let options = {};
          if (Cypress._.isObject(args[0])) {
            options = Object.assign({}, args[0]);
            ... 
          return originalFn(Object.assign({}, defaults, options));
        });
    });
    Problem here is as soon as I start running my spec file it fails with
    TypeError Cookie[1] is undefined
    Later when I change
    'X-XSRF-TOKEN': Cookie[1],
    it runs fine and gives validate 401, after that if I add
    'X-XSRF-TOKEN': Cookie[1].value,
    it works fine. I don't understand why at first it throws TypeError.
  • m

    melodic-apple-72412

    03/10/2022, 9:39 PM
    so, Cookie[1] contains cookies but when I specify
    'X-XSRF-TOKEN': Cookie[1].value,
    it throws
    TypeError Cookie[1] is undefined
    I specifically queried for
    cy.getCookie('XSRF-TOKEN')
    and assigned
    'X-XSRF-TOKEN': Cookie.value,
    now it throws
    Cookie is null
    just wondering why when Cookie has cookie details. I am calling this fn, in beforeEach of a spec file (for example) :
    Copy code
    beforeEach(() => {
        cy.login(Cypress.env('username'), Cypress.env('password'));
        cy.visit('/');
        cy.get('.c8y-ui-title > .text-truncate', { timeout: 10000 }).should('be.visible');
        cy.request('/inventory/managedObjects', 'POST', deviceObj);
      });
  • f

    few-musician-79351

    03/10/2022, 11:28 PM
    @User I'm still dealing with this, i can't make it work, now it returns this new error
  • i

    important-river-75795

    03/10/2022, 11:30 PM
    not cypress.env.json , but cypress.json , and the field is called baseUrl
  • i

    important-river-75795

    03/10/2022, 11:31 PM
    Then you can throw out the const url = Cypress.env("CYPRESS_BASE_URL") from your files , and throw away the env: from the github workflow
  • i

    important-river-75795

    03/10/2022, 11:31 PM
    And just do cy.visit("/") everywhere
  • f

    few-musician-79351

    03/10/2022, 11:39 PM
    Like this?
  • f

    few-musician-79351

    03/10/2022, 11:52 PM
    cypress.json should it be uploaded to github?
  • i

    important-river-75795

    03/10/2022, 11:53 PM
    Yeah, push everything, and looks good now
  • i

    important-river-75795

    03/10/2022, 11:55 PM
    Might want to have a read about it https://docs.cypress.io/guides/references/configuration#cypress-json
  • i

    important-river-75795

    03/10/2022, 11:56 PM
    And heres a bunch of examples how to set up github actions with cypress
  • i

    important-river-75795

    03/10/2022, 11:56 PM
    https://github.com/marketplace/actions/cypress-io
  • f

    few-musician-79351

    03/10/2022, 11:59 PM
    Yeah, that's where I got this
  • f

    few-musician-79351

    03/10/2022, 11:59 PM
    I have used actions before but never with env vars
  • i

    important-river-75795

    03/11/2022, 12:03 AM
    Planning to run this on multiple environments I assume?
1...313233...127Latest