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

    happy-megabyte-98400

    11/29/2022, 7:50 PM
    Yes, I did read your blog post on random elements. It was helpful but I'd like to write it as a custom command without the extra logs that come with using
    .should()
    and add retry-ability maybe.
  • h

    happy-megabyte-98400

    11/29/2022, 7:51 PM
    Here's what i have so far (Excuse the messy code & any bad coding practices + errors)
    Copy code
    Cypress.Commands.add('random', { prevSubject: 'element' }, (subject, options = {}) => {
      const { _ } = Cypress;
    
      _.defaults(options, {
        log: true,
        timeout: Cypress.config().defaultCommandTimeout,
      });
    
      const randomElement = _.sample(subject);
    
      const consoleProps = {
        'Applied to': subject,
        Yielded: randomElement,
      };
    
      if (options.log) {
        // eslint-disable-next-line no-param-reassign,no-underscore-dangle
        options._log = Cypress.log({
          $el: subject,
          name: 'random',
          consoleProps: () => consoleProps,
        });
      }
    
      if (subject.length === 1) {
        return subject;
      }
    
      return randomElement;
    });
  • l

    late-planet-4481

    11/29/2022, 8:05 PM
    I'm not the best at eyeballing these things, but I do notice you've given the
    prevSubject
    argument a declarative subject validation by specifying
    prevSubject: 'element'
    . I don't think this is correct, because your intent is to provide an array of elements. So I would expect
    prevSubject: true
    instead.
  • l

    late-planet-4481

    11/29/2022, 8:16 PM
    I also don't know much about Lodash so I stripped away all that logging stuff you have and created a working example for you:
    Copy code
    js
    Cypress.Commands.add('pickRandom', { prevSubject: true }, (elementList) => {
      const randomElement =
        elementList[Math.floor(Math.random() * elementList.length)]
    
      return randomElement
    })
    So you'd be able to do something like this:
    Copy code
    js
    cy.get('.buttonOrWhatever').pickRandom().click()
  • h

    happy-megabyte-98400

    11/29/2022, 9:52 PM
    @late-planet-4481
    prevSubject: 'element'
    will work with an array of elements. Whereas changing it to true will work with any values as long as it's inside an array. Thanks for your input tho.
  • b

    bulky-breakfast-19364

    11/29/2022, 11:53 PM
    Does anyone have an example of changing the system time in a test? I got the date change to work, but I donโ€™t think the time of day is being set properly (I expect to see a specific modal after a certain time).
  • f

    fast-napkin-36711

    11/30/2022, 2:36 AM
    In reference to this: If you want to start your server and then run your tests i would recommend this plugin https://github.com/bahmutov/start-server-and-test Would you mind helping me use this in a windows runner w Github? I like to use http-server, and itโ€™s installed globally on my home machine. I read the guide, got it running w/npm start on my machine, but I am not sure how to automate the http-server install along side the cypress github action in my workflow.
  • c

    cool-toothbrush-53313

    11/30/2022, 3:38 AM
    Hi After I migrated to Cypress 10, I'm not able to run specific test scenarios using cucumber tags. I used to execute scripts using cypress-tags. Looks like after migrating cpress-tags is not available. How may I be able to run a specific script? Any help would be appreciated...
  • a

    adorable-smartphone-87280

    11/30/2022, 4:51 AM
    Is there a way to source custom commands from both a shared import package AND from the local
    /support/
    directory? Do I need to explicitly import my
    /support/e2e.ts
    file in each test
    spec
    ?
  • m

    mysterious-belgium-25713

    11/30/2022, 9:09 AM
    !duplicate
  • n

    nutritious-analyst-96582

    11/30/2022, 9:09 AM
    Uh oh, It looks like you have posted the same question in multiple channels. Help us prevent spam by removing any duplicates of your questions, Thanks! ๐Ÿ˜€
  • f

    flaky-barista-77342

    11/30/2022, 9:12 AM
    Hi, has anyone been able to get working the combination:
    Cypress + Mac M1 chip (arm64 arch) + docker + Chrome?
    I know that Cypress images support arm64 since this July, but on Electron only due to Chrome issue: https://bugs.chromium.org/p/chromium/issues/detail?id=677140 Is there any workaround to use Chrome?
  • e

    enough-truck-68085

    11/30/2022, 4:49 PM
    Yes just make sure to import all sources into the
    support/e2e.ts
    file like the example above That's it. You don't need to explicitly import the
    e2e
    file into any spec files. Additionally if you are using Typescript you will likely need to update your
    tsconfig.json
    file with any additional types from external sources. https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Support-file
  • a

    adorable-smartphone-87280

    11/30/2022, 5:32 PM
    Currently, I import my shared tools like this:``` import "@my-shared/cypress-utils"; ```
  • a

    adorable-smartphone-87280

    11/30/2022, 5:33 PM
    in each
    spec
    file. Can I instead just put that line once in my
    e2e.ts
    file?
  • a

    adorable-smartphone-87280

    11/30/2022, 5:33 PM
    This is a dumb question. You just demonstrated that I can. Sorry, just learning out loud. Thanks.
  • a

    adorable-smartphone-87280

    11/30/2022, 5:44 PM
    Just cleanup up a whole package by moving that import out of each spec and into my
    e2e.ts
    . Works like a charm, thanks!
  • a

    adorable-smartphone-87280

    11/30/2022, 5:47 PM
    I think I can also move the
    Copy code
    import Chainable = Cypress.Chainable;
    declare const cy: Chainable<any>;
    that I had in each
    spec
    too.
  • s

    stale-furniture-7985

    11/30/2022, 7:45 PM
    I want to assert prices of items from high to low and vice versa. Problem is that there is old and new price and no specific selector to somehow differentiate between them. So, always i am getting this result and don't know how to use this high price only, without second price. I have watch this code example from @gray-kilobyte-89541, so will be thankful for help here. โ˜บ๏ธ
  • b

    bitter-fountain-36713

    11/30/2022, 8:01 PM
    !threadit
  • n

    nutritious-analyst-96582

    11/30/2022, 8:01 PM
    Let's keep the conversation going! Please create a thread in the original question to submit your responses ๐Ÿ˜€
  • b

    bitter-fountain-36713

    11/30/2022, 8:02 PM
    I want to assert prices of items from
  • r

    rough-book-31535

    12/01/2022, 7:06 AM
    Hello, I would like to split my cypress project in 2 for the dashboard, but it doesn't work properly. I did this: projectId: process.env.PROJECT_ID as string | 'XXXXX' (XXXXX being the id of one of the 2 projects) It works with the CI but not with the application. With the application the project id is not recognised. Do you have an idea?
  • a

    astonishing-window-24437

    12/01/2022, 7:35 AM
    I use cypress with cucumber, I tried if element exist click(),type() methods and if element is not exist skip, but does return error when element is not exist I was try like conditions "if(cy.xpath("xpath").length>0)" - "if(cy.xpath("xpath").should('be.visible'))" - "cy.xpath('xpath).find('xpath')" "cy.get('body').then(find('xpath'))"etc. etc. None of them worked, I usually use xpath, maybe it has an effect I used serenity example this => Check.ifElementExist(Page.closeForm).then(Click.on(Page.closeFormVerify)) Skips if there is no element I try to migrate this code, Sorry for my english not very well
  • f

    fresh-doctor-14925

    12/01/2022, 8:15 AM
    What's the reason for wanting to split the project in 2 for the dashboard? It will be easier for you to use tags to distinguish between runs
  • f

    fresh-doctor-14925

    12/01/2022, 8:17 AM
    I use cypress with cucumber I tried if
  • r

    rough-book-31535

    12/01/2022, 8:32 AM
    using which plugin?
  • f

    fresh-doctor-14925

    12/01/2022, 8:46 AM
    !threadit
  • n

    nutritious-analyst-96582

    12/01/2022, 8:46 AM
    Let's keep the conversation going! Please create a thread in the original question to submit your responses ๐Ÿ˜€
  • f

    fresh-doctor-14925

    12/01/2022, 8:48 AM
    Hello I would like to split my cypress
1...217218219...252Latest