0

I am trying to pull out a smoke suite from my regression suite written using the Jasmine framework (wdio-jasmine-framework).

Is it possible to just add a tag on specific testcases in Jasmine?

iamdanchiv
  • 4,052
  • 4
  • 37
  • 42
user3920295
  • 889
  • 2
  • 13
  • 31

2 Answers2

2

If I remember correctly from my Jasmine/Mocha days, there were several ways to achieve this. I'll detail a few, but I'm sure there might be some others too. Use the one that's best for you.

1. Use the it.skip() statement inside a conditional operator expression to define the state of a test-case (e.g: in the case of a smokeRun, skip the non-smoke tests using: (smokeRun ? it.skip : it)('not a smoke test', () => { // > do smth here < });).

Here is an extended example:

// Reading the smokeRun state from a system variable:
const smokeRun = (process.env.SMOKE ? true : false);

describe('checkboxes testsuite', function () {

    // > this IS a smoke test! < //
    it('#smoketest: checkboxes page should open successfully', () => {
        CheckboxPage.open();
        // I am a mock test... 
        // I do absolutely nothing!
    });

    // > this IS NOT a smoke test! < //
    (smokeRun ? it.skip : it)('checkbox 2 should be enabled', () => {
        CheckboxPage.open();
        expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(false);
        expect(CheckboxPage.lastCheckbox.isSelected()).toEqual(true);
    });

    // > this IS NOT a smoke test! < //
    (smokeRun ? it.skip : it)('checkbox 1 should be enabled after clicking on it', () => {
        CheckboxPage.open();
        expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(false);
        CheckboxPage.firstCheckbox.click();
        expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(true);
    });
});

2. Use it.only() to achieve mainly the same effect, the difference being the test-case refactor workload. I'll summarize these ideas as:

  • if you have more smoke tests than non-smoke tests, use the it.skip() approach;
  • if you have more non-smoke tests than smoke tests, use the it.only() approach;

You can read more about pending-tests here.


3. Use the runtime skip (.skip()) in conjunction with some nested describe statements.

It should look something like this:

// Reading the smokeRun state from a system variable:
const smokeRun = (process.env.SMOKE ? true : false);

describe('checkboxes testsuite', function () {

    // > this IS a smoke test! < //
    it('#smoketest: checkboxes page should open successfully', function () {
        CheckboxPage.open();
        // I am a mock test... 
        // I do absolutely nothing!
    });

    describe('non-smoke tests go here', function () {
        before(function() {
            if (smokeRun) {
                this.skip();
            }
        });
        // > this IS NOT a smoke test! < //
        it('checkbox 2 should be enabled', function () {
            CheckboxPage.open();
            expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(false);
            expect(CheckboxPage.lastCheckbox.isSelected()).toEqual(true);
        });
        // > this IS NOT a smoke test! < //
        it('checkbox 1 should be enabled after clicking on it', function () {
            CheckboxPage.open();
            expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(false);
            CheckboxPage.firstCheckbox.click();
            expect(CheckboxPage.firstCheckbox.isSelected()).toEqual(true);
        });
    });
});

!Note: These are working examples! I tested them using WebdriverIO's recommended Jasmine Boilerplace project.

!Obs: There multiple ways to filter Jasmine tests, unfortunately only at a test-file(testsuite) level (e.g: using grep piped statements, or the built-in WDIO specs & exclude attributes).

iamdanchiv
  • 4,052
  • 4
  • 37
  • 42
0

In addition to the iamdanchiv's answer, with WebdriverIO ~7+ & Jasmine ~3.7+ (maybe with older versions too) you can add any text tag to your its and describes, and filter the specs to run by it.

A working package.json script is using the Jasmine's grep:

"smoketest": "wdio run wdio.local.conf.js --suite=temp --jasmineOpts.grep=_smoke"

where:

--suite=temp is defined in the wdio.local.conf.js suites and runs only those spec files,

--jasmineOpts.grep=_smoke finds '_smoke' part in the test (it) titles AND describe titles inside the above spec files and runs only them.

This would run the full describe

describe(`Suite 1 _smoke any other text`, () => {
   it('Test 1-1', async () => {});
   it('Test 1-2', async () => {});
});

and tests from another describe(s) like:

it('Test 2-1 _smoke is for smoke runs', async () => {});

Non-matching tests (its) are skipped.

_smoke can be any other text tag you add to the titles.

P.S.: I could not make multiple tags work together, but this is enough to select only smoke tests.

Nata K
  • 11
  • 1