https://cypress.io logo
Join Discord
Powered by
# help
  • a

    acceptable-journalist-55984

    02/02/2022, 11:44 AM
    Hi! I have a problem with the
    selectFile()
    API. Despite me being on 9.4.1, neither
    cy.document().selectFile
    nor
    cy.get('input[type=file]').selectFile
    are defined. Did I miss some config?
  • a

    ancient-minister-75558

    02/02/2022, 2:38 PM
    Hi, I want to save access token from the api call with custom command into environmental variable, but it does not work. Doesn't it work in this way?
    Copy code
    Cypress.Commands.add('getAccessToken', () => {
        const options = {
            method: "POST",
            url: '/token.json',
            form: true,
            body: {
              grant_type: "password",
              username: Cypress.env('username'),
              password: Cypress.env('pass'),
              client_id: Cypress.env('client_id')
            }
          };
          
          cy.request(options)
              .then(response => {
                  expect(response.body).to.have.property('access_token');
                  Cypress.env('accessToken', response.body.access_token);
          });
        }
  • h

    handsome-cartoon-58565

    02/02/2022, 2:54 PM
    how do you know it doesn't work? if you are trying to access this env in other spec file, then it might not work, because
    Cypress.env
    appears to only set/change env variables for one spec file https://docs.cypress.io/api/cypress-api/env#Why-is-it-Cypress-env-and-not-cy-env
  • h

    handsome-cartoon-58565

    02/02/2022, 2:54 PM
    you can ensure that 'accessToken' is set by reading it after setting it by
    Cyress.env('accessToken')
  • h

    handsome-cartoon-58565

    02/02/2022, 2:55 PM
    https://docs.cypress.io/api/cypress-api/env#Name-and-Value > Scope > > Remember, any changes that you make to environment variables using this API will only be in effect for the remainder of the tests in the same spec file.
  • a

    ancient-minister-75558

    02/02/2022, 3:15 PM
    it works in the same spec file, that is true. I was mistakenly thinking
    Cypress.env
    is set as a global variable which could be updated in env file... Thanks @User As my token expires, ideally, I was thinking to get it once and use it for whole test session...
  • h

    handsome-cartoon-58565

    02/02/2022, 3:17 PM
    you can try setting such env variable through Node's
    process.env
    , but that would require to use Cypress plugin (not command) https://docs.cypress.io/api/plugins/writing-a-plugin
  • a

    ancient-minister-75558

    02/02/2022, 3:27 PM
    Will investigate this way further, thanks for advice!
  • g

    gorgeous-insurance-13289

    02/02/2022, 8:35 PM
    When using
    cy.get('#element').click()
    , what's happening in the background? We're encountering an error which only happens when the cypress test runs. If we mimic its behavior manually we don't have any issues. Here is [the test](https://github.com/carbon-design-system/carbon-for-ibm-dotcom/pull/8174/files#diff-a00eb0a05c99c0a2bdfd49f3f79145e86aeeb09e909c68c3c8c42f3cbda2841dR52-R71) Here is the page of the deploy environment that has [the component being tested](https://ibmdotcom-web-components-experimental.s3.us-east.cloud-object-storage.appdomain.cloud/deploy-previews/8174/iframe.html?id=components-cloud-masthead--default) The failure:
    Copy code
    dds-masthead | cloud platform (desktop)
        ✓ should have url for IBM logo (3613ms)
        ✓ should have cloud platform name (4120ms)
        ✓ should load top-nav with no more than one active item (4079ms)
        (Attempt 1 of 3) should have tabbed-interface megamenus
        (Attempt 2 of 3) should have tabbed-interface megamenus
        1) should have tabbed-interface megamenus
        ✓ should have functioning search bar with typeahead (7118ms)
        ✓ should have contact, login, and create-account CTAs (5095ms)
    
    
    1) dds-masthead | cloud platform (desktop)
           should have tabbed-interface megamenus:
         AssertionError: Timed out retrying after 90000ms: expected '<div#panel-0-0>' to be 'visible'
    
    This element `<div#panel-0-0>` is not visible because its parent `<dds-cloud-megamenu-right-navigation>` has CSS property: `visibility: hidden`
          at Context.eval (http://localhost:8081/__cypress/tests?p=tests/e2e-storybook/cypress/integration/masthead/cloud/cloud-masthead.e2e.js:150:33)
    a
    m
    • 3
    • 9
  • a

    adventurous-dream-20049

    02/02/2022, 11:21 PM
    You shouldn't need to add anything to the config, only fixtures (or whatever you are needing to reference). Can you provide a reproducible example?
  • a

    acceptable-journalist-55984

    02/03/2022, 3:44 PM
    I just tried it in a clean [repository](https://github.com/sweidac/cypress-selectFile) and it works there. Unfortunately I can't share my original code, so I'll have to find it out for myself.
    a
    • 2
    • 10
  • n

    numerous-gpu-95965

    02/03/2022, 4:38 PM
    Hello , i need some help understanding how i do i get access to this property value, , im doing my-data-cy.should('exist').and('has.value', 'MyValue') i got the path correctly implemented, i have access to the mat-toogle-group, but still i cannot get the [value] proprety to make the assertion can some one help me ?
  • n

    numerous-gpu-95965

    02/03/2022, 4:38 PM
    its returning ' '
  • n

    numerous-gpu-95965

    02/03/2022, 4:38 PM
    instead of MyValue
  • n

    numerous-gpu-95965

    02/03/2022, 4:38 PM
    and the test fail
  • g

    gorgeous-insurance-13289

    02/03/2022, 6:28 PM
    Does anyone have an idea why clicking would cause a behavior when Cypress is running, but not in a "normal" scenario?
  • b

    breezy-oyster-69258

    02/03/2022, 7:45 PM
    Got a weird issue happening. My application is using decorators, and while running unit tests with Cypress, I get this error
    Copy code
    Error: Webpack Compilation Error
    ./src/resources/custom-attributes/after-render.js
    Module build failed (from C:/Users/xxxxx/AppData/Local/Cypress/Cache/9.4.1/Cypress/resources/app/node_modules/babel-loader/lib/index.js):
    SyntaxError: E:\xxxxx\form-builder\src\resources\custom-attributes\after-render.js: Support for the experimental syntax 'decorators-legacy' isn't currently enabled (3:1):
    
      1 | import { INode, bindable, BindingMode, customAttribute } from 'aurelia';
      2 |
    > 3 | @customAttribute({
        | ^
      4 |     name: 'after-render'
      5 | })
      6 | export class AfterRender {
     @ ./src/resources/custom-attributes/index.js 21:19-44
     @ ./src/start.js
     @ ./src/FormVersion.spec.js
    It looks like Webpack is trying to load in my file but complains about decorators with babel (note, I'm not using webpack in our application, so this is a Cypress error). I have a babel.config.json with this configuration
    Copy code
    {
      "presets": [
        [
          "@babel/preset-env",
          {
            "loose": true,
            "exclude": [
              "@babel/plugin-proposal-dynamic-import"
            ]
          }
        ]
      ],
      "plugins": [
        [
          "@babel/plugin-proposal-decorators",
          {
            "legacy": true
          }
        ],
        [
          "@babel/plugin-proposal-class-properties",
          {
            "loose": true
          }
        ],
        "@babel/plugin-syntax-dynamic-import"
      ]
    }
    So it should definitely be working with the decorators. Anybody have any clues? I'm about to open a bug with it, but wanted to run it here first.
  • a

    adventurous-dream-20049

    02/03/2022, 9:14 PM
    Clicking provides actionability similar to how a User would interact. For example, before typing into a form, a User will typically need to click the input box prior to typing. Is this what you mean by "normal" scenario?
  • g

    gorgeous-insurance-13289

    02/03/2022, 9:24 PM
    @User I mentioned you in the thread I started above - just wanted to make sure you saw that
  • h

    handsome-cartoon-58565

    02/04/2022, 12:16 AM
    TypeScript and Docker - compilation error
    • 1
    • 2
  • a

    adventurous-dream-20049

    02/04/2022, 3:52 AM
    Can you try
    cy.get('[data-cy="my-data-cy"]').should('exist').and('has.value', 'MyValue')
  • n

    numerous-gpu-95965

    02/04/2022, 7:56 AM
    hello @User if if put [value]="myValue" it returns undefined
  • n

    numerous-gpu-95965

    02/04/2022, 7:57 AM
    but value="MyValue" works
  • n

    numerous-gpu-95965

    02/04/2022, 7:58 AM
    MyValue came from parent to child, so maybe in the tests im getting undefined
  • m

    many-dinner-79149

    02/04/2022, 6:05 PM
    Hello, I am accessing the UI application I want to test via a kubernetes ingress controller and although I am able to access the application manually via my browser (Chrome, MacOS) I am unable to access the app via the automated browser that Cypress uses
  • m

    many-dinner-79149

    02/04/2022, 6:07 PM
    The app is normally accessible via a url like 'http://ui.localhost' but when I try to navigate to this url from inside the cypress browser I do not receive a response
  • a

    adventurous-dream-20049

    02/04/2022, 6:40 PM
    hmm.. you may want to try aliasing. Is it possible to provide a reproducible example that I can test?
    n
    • 2
    • 2
  • a

    adventurous-dream-20049

    02/04/2022, 6:53 PM
    Not getting value
  • s

    silly-horse-70115

    02/04/2022, 11:16 PM
    i was just running into this problem and clearing my .next cache fixed it!
  • n

    numerous-gpu-95965

    02/05/2022, 12:07 PM
    hey @User , my main objective was to test if a inside a was active in a form and have certain value, for that i was trying to get the value from the class directive , but what i did was , instead i "reach" to the button itself and check if as class active and the value i want, and now the test is ok. 🙂 !!
1...474849...252Latest