Isolation of actions and tests

牧云@^-^@ 提交于 2019-12-08 11:06:42

问题


I try to refactor my code. I know that if I have several expectations they should be isolate in 'it'. I try to understand how I can write instead this:

describe('my scenario should make', function () {

  var config = browser.params;
  var url = config.listOfReferencesUrl,
      grid,
      numberField;

  it('test1', function () {

    browser.get(url);
    browser.executeScript("icms.go('WEB_INQ_PROC', 'InquiryList', null, 0)");

    grid = psGrid(by.css("table[class='n-grid']"));
    numberField = grid.getQuickFilter(1);
    numberField.click().sendKeys("Hello!");

    since('fail1').expect(numberField.getInputText()).toEqual("");
  });

  it('test2', function () {
    since('fail2').expect(numberField.getInputText()).toEqual("Hello!");
  });

});

Something like this:

    describe('my scenario should make', function () {

      var config = browser.params;
      var url = config.listOfReferencesUrl,
          grid,
          numberField;

 *********Make this part of code ONES before all tests in spec ****
    browser.get(url);
    browser.executeScript("icms.go('WEB_INQ_PROC', 'InquiryList', null, 0)");

    grid = psGrid(by.css("table[class='n-grid']"));
    numberField = grid.getQuickFilter(1);
    numberField.click().sendKeys("Hello!"); 
*******************************************************************   
      it('test1', function () {
        since('fail1').expect(numberField.getInputText()).toEqual("");
      });

      it('test2', function () {
        since('fail2').expect(numberField.getInputText()).toEqual("Hello!");
      });

    });

Maybe somebody have an idea how I can do this?


回答1:


To answer your question, if you want to run your code once before all tests then use beforeAll() function available in Jasmine 2. Here's a sample -

beforeAll(function(){
    //Write your code here that you need to run once before all specs
});

You can use beforeEach() function available in Jasmine to run it each time before a test spec. Here's a sample -

beforeEach(function(){
    //Write your code here that you need to run everytime before each spec
});

If you are facing issue in getting these functions to work, then update your plugins to latest version and then try running it. Also use the framework: 'jasmine2' in your conf.js file

Hope this helps.



来源:https://stackoverflow.com/questions/32249393/isolation-of-actions-and-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!