55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import './commands';
|
|
|
|
function randomString(options = { length: 10 }) {
|
|
let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
return randomizeValue(possible, options);
|
|
}
|
|
|
|
function randomNumber(options = { length: 10 }) {
|
|
let possible = '0123456789';
|
|
return randomizeValue(possible, options);
|
|
}
|
|
|
|
function randomizeValue(characterSet, options) {
|
|
return Array.from({ length: options.length }, () =>
|
|
characterSet.charAt(Math.floor(Math.random() * characterSet.length)),
|
|
).join('');
|
|
}
|
|
|
|
const style = document.createElement('style');
|
|
style.innerHTML = `
|
|
* {
|
|
transition: none !important;
|
|
animation: none !important;
|
|
}
|
|
`;
|
|
document.head.appendChild(style);
|
|
|
|
const waitForApiReady = (url, maxRetries = 20, delay = 1000) => {
|
|
let retries = 0;
|
|
|
|
function checkApi() {
|
|
return cy
|
|
.request({
|
|
url,
|
|
failOnStatusCode: false,
|
|
})
|
|
.then((response) => {
|
|
if (response.status !== 200 && retries < maxRetries) {
|
|
retries++;
|
|
cy.wait(delay);
|
|
return checkApi();
|
|
}
|
|
expect(response.status).to.eq(200);
|
|
});
|
|
}
|
|
|
|
return checkApi();
|
|
};
|
|
|
|
before(() => {
|
|
waitForApiReady('/api/Applications/status');
|
|
});
|
|
|
|
export { randomString, randomNumber, randomizeValue };
|