I am trying to only run a set of tests if the version is a certain number or higher in cypress, however I can't seem to make it work correctly. The code below is a bit of an abstraction but shows the overall structure:
if (version < 8203) {
context('Skipping Tests', () => {
it('Feature Not Available', () => {
cy.task('log', "Skipping test. Feature not available in this version");
});
});
else {
context('Testing Feature', () => {
it('Test 1', () => {
});
it('Test 2', () => {
});
it('Test 3', () => {
});
});
}
I am not sure if this is the correct way to go about this and I have tried several different ways to structure this including putting the if statement in the context but it looks like cypress ignores the if statement or just moves on to the last context and it function.
You mention this code for obtaining the value in version
.
let version;
getVersion((setVersion) => {
version = parseInt(setVersion.replace(/[v.]/g, ''));
console.log(version); //8203
});
if (version < 8203) { ??? is this where you test ???
If the above pattern is how your test looks, I'd say the getVersion()
callback has not completed before the if()
is evaluated.
Does this structure improve things?
let version;
getVersion((setVersion) => {
version = parseInt(setVersion.replace(/[v.]/g, ''));
console.log(version); //8203
if (version < 8203) {
...
}
else {
context('Testing Feature', () => {
it('Test 1', () => {
...
});
}
});