有没有办法使测试套件停止,答案为成功?使用茉莉花

时间:2019-01-06 20:12:53

标签: javascript node.js jasmine protractor

我有一个问题,我想让测试在中间停止 执行“ IT”的步骤,因此进入下一个“ IT”。我找到了两种方法来执行此操作,一种使用未决()或fail(),但是我想执行类似的操作,而不是将其返回“ pending”或“ fail”以返回成功。

套房测试

const URLs = 'https://www.google.com/';
const searchGoogle = 'music eletronic youtube';
const searchYoutube = 'nerdologia';

describe('Start simulator False', () => {
  it('Enter youtube ', () => {
    browser.driver.get(URLs);

    browser.sleep(5000);

    browser.driver.findElement(by.name('q')).sendKeys(searchGoogle);
    browser.driver.findElement(by.xpath('/html/body/div/div[3]/form/div[2]/div/div[3]/center/input[1]')).click();

    browser.sleep(1000);

    // browser.pause();
    browser.driver.findElement(by.xpath('//*[@id="rso"]/div/div/div[2]/div/div/div[1]/a')).click();

    isAngularSite(false);
  });
  it('Search to data random youtube', () => {
    browser.sleep(6000);
    element(by.id('search')).sendKeys(searchYoutube).then((visible) => {
      if (visible) {
        throw 'Error';
      }
      element(by.id('search-icon-legacy')).click();
    });
    // browser.driver.findElement(by.css('[#search]')).sendKeys(searchYoutube);
    browser.sleep(6000);
    browser.driver.findElement(by.xpath('//*[@id="contents"]/ytd-video-renderer[1]')).click().then(() => {
      throw 'Stop the test';
    });
    browser.sleep(6000);
    browser.executeScript('document.querySelector(\'#movie_player > div.html5-video-container > video\').pause();');
  });
})

Protractor.conf.js

const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
const AllureReporter = require('jasmine-allure-reporter');


exports.config = {
  // The address of a running selenium server.
  seleniumAddress: 'http://localhost:4444/wd/hub',

  // Spec patterns are relative to the location of this config.
  specs: [
    'webapp/e2e/spec/*.js',
  ],

  capabilities: {
    browserName: 'chrome',
    shardTestFiles: true,
    maxInstances: 5,
    marionette: true,
    acceptInsecureCerts: true,
    chromeOptions: { args: ['--disable-extensions'] },
    // browserName: 'chrome',

    // chromeOptions: {
    //     args: ['--no-sandbox', '--disable-dev-shm-usage',
    //         "--headless", "--disable-gpu", "--window-size=1366x768" ]
    // }
  },


  // capabilities: {
  //   directConnect: true,
  //   browserName: 'chrome',
  //   marionette: true,
  //   acceptInsecureCerts: true,
  //   chromeOptions: {
  //     args: ['--no-sandbox', '--disable-dev-shm-usage',
  //       '--headless', '--disable-gpu', '--window-size=800x600'],
  //   },
  // },

  //     capabilities: {
  //     'browserName': 'chrome',
  //         'chromeOptions': {'args': ['--disable-extensions']}
  //     //   browserName: 'chrome',
  //     //
  //     //   chromeOptions: {
  //     //       args: [ "--headless", "--disable-gpu", "--window-size=800,600" ]
  //     //   }
  // },

  onPrepare() {
    global.isAngularSite = function (flag) {
      browser.ignoreSynchronization = !flag;
    };

    jasmine.getEnv().addReporter(new SpecReporter({
      displayFailuresSummary: true,
      displayFailuredSpec: true,
      displaySuiteNumber: true,
      displaySpecDuration: true,
    }));
    jasmine.getEnv().addReporter(new AllureReporter({
      resultsDir: 'allure-results',
    }));
    jasmine.getEnv().afterEach((done) => {
      browser.takeScreenshot().then((png) => {
        allure.createAttachment('Screenshot', () => new Buffer(png, 'base64'), 'image/png')();
        done();
      });
    });
    beforeEach(() => {
      originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
      jasmine.DEFAULT_TIMEOUT_INTERVAL = 1800000;
    });
    afterEach(() => {
      jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
    });
  },

  allScriptsTimeout: 180000,
  getPageTimeout: 180000,


  jasmineNodeOpts: {
    onComplete: null,
    isVerbose: false,
    showColors: true,
    includeStackTrace: true,
    defaultTimeoutInterval: 1800000,
  },
};

如何更快地运行

protractor protractor.conf.js  --specs='nameOfFile.js'

1 个答案:

答案 0 :(得分:2)

量角器使用开箱即用的Jasmine testing framework

Jasmine允许声明在testFunction中传递的Specs来接收回调。

即使您的测试是同步的,也可以将其转换为异步测试,以便您控制Jasmine何时将测试移至下一个测试。

您可以通过调用此参数来使Jasmine知道继续前进。 例如

it('Enter youtube ', (done) => {
  // some operations that you care about running
  done();
  // other operations that you like to skip
});