happy-megabyte-98400
11/29/2022, 7:50 PM.should()
and add retry-ability maybe.happy-megabyte-98400
11/29/2022, 7:51 PMCypress.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;
});
late-planet-4481
11/29/2022, 8:05 PMprevSubject
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.late-planet-4481
11/29/2022, 8:16 PMjs
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:
js
cy.get('.buttonOrWhatever').pickRandom().click()
happy-megabyte-98400
11/29/2022, 9:52 PMprevSubject: '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.bulky-breakfast-19364
11/29/2022, 11:53 PMfast-napkin-36711
11/30/2022, 2:36 AMcool-toothbrush-53313
11/30/2022, 3:38 AMadorable-smartphone-87280
11/30/2022, 4:51 AM/support/
directory? Do I need to explicitly import my /support/e2e.ts
file in each test spec
?mysterious-belgium-25713
11/30/2022, 9:09 AMnutritious-analyst-96582
11/30/2022, 9:09 AMflaky-barista-77342
11/30/2022, 9:12 AMCypress + 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?enough-truck-68085
11/30/2022, 4:49 PMsupport/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-fileadorable-smartphone-87280
11/30/2022, 5:32 PMadorable-smartphone-87280
11/30/2022, 5:33 PMspec
file. Can I instead just put that line once in my e2e.ts
file?adorable-smartphone-87280
11/30/2022, 5:33 PMadorable-smartphone-87280
11/30/2022, 5:44 PMe2e.ts
. Works like a charm, thanks!adorable-smartphone-87280
11/30/2022, 5:47 PMimport Chainable = Cypress.Chainable;
declare const cy: Chainable<any>;
that I had in each spec
too.stale-furniture-7985
11/30/2022, 7:45 PMbitter-fountain-36713
11/30/2022, 8:01 PMnutritious-analyst-96582
11/30/2022, 8:01 PMbitter-fountain-36713
11/30/2022, 8:02 PMrough-book-31535
12/01/2022, 7:06 AMastonishing-window-24437
12/01/2022, 7:35 AMfresh-doctor-14925
12/01/2022, 8:15 AMfresh-doctor-14925
12/01/2022, 8:17 AMrough-book-31535
12/01/2022, 8:32 AMfresh-doctor-14925
12/01/2022, 8:46 AMnutritious-analyst-96582
12/01/2022, 8:46 AMfresh-doctor-14925
12/01/2022, 8:48 AM