2

I have unpredictable behavior page that depends on changes that create developers. And sometimes my tests failed, because page wasn't load. My test scenario structure looks like:

describe('0. first actions', function () {
    var lib = require("../../common.js");
    var config = browser.params;
    var url = config.listOfReferencesUrl, toolbar;

    load(url, "list-of-references");

    beforeAll(function () {
        // some actions on the page
    });

    it('test0', function () {
        since('test0 failed').
            expect(toolbar.isPresent()).toBe(true);
    });

    describe('1.actions1', function () {

    beforeAll(function () {
        // some actions on the page
    });

    it('test1', function () {
        since('test1 failed').       
            expect(table.getRow(clientNameNum).getRowInput().isEnabled()).toBe(true);
    });

    // ... another invested describes 
});

Where load function is:

global.load = function (url, pageType) {
  browser.get(url);
  if (pageType == 'list-of-references'){
    browser.executeScript("icms.go('WEB_INQ_PROC', 'InquiryList', null, 0)");
  }
  browser.waitForAngular();
};

I wonder if I can create structure to stop my tests if page isn't load. But I don't want to use 'jasmine-bail-fast', because I want to see another failures if page will load. I tried to write something like:

if (this.results_.failedCount > 0) {
    // Hack: Quit by filtering upcoming tests
    this.env.specFilter = function(spec) {
        return false;
    };
}

But it isn't working. I use jasmine2. Maybe somebody know how I can organize it?

1 Answers1

1

You can define a wrapper

var filter = function (fn) {
  if (!condition)
    throw new Error('skipped');

  return fn;
}

and use it on all relevant describe/it blocks:

describe('...', filter(function () {
  ...
}));
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
  • @ estusThanks! But I have an error: "ReferenceError: filter is not defined". Where I can see some examples of using it? – Лилия Сапурина Nov 02 '15 at 14:13
  • You need to have it defined in your specs. `require` `filter` function or define it as `window.filter` (similar to how angular-mock [defines its globals](https://docs.angularjs.org/api/ngMock#function)). I think it is more straightforward and clean approach than hijacking `env.specFilter`. – Estus Flask Nov 02 '15 at 14:59