批量运行时,量角器中出现超时错误,但单独运行时,它工作正常吗?

时间:2018-09-25 14:22:25

标签: angular jasmine protractor automated-tests end-to-end

我正在使用量角器和Angular设置e2e测试。在这里,我正在套件中编写3个测试用例。当只有2个时,它运行良好。除此之外,它还会因超时错误而失败。我什至尝试实现“完成”的回调函数,但无法解决。奇怪的是,如果我按照所有3个测试用例通过的顺序重新排列测试用例。例如,请参见下面的代码。

app.po.ts

import { browser, by, element } from 'protractor';

export class TestEngine {
  navigateTo() {
    browser.get('/');
    var script = "window.localStorage.setItem('isAccepted', 'true')";
    return browser.executeScript(script);
  }

  getParagraphText() {
    return element(by.css('page-welcome p')).getText();
    }

  getButtons() { 
      return element(by.buttonText('Login')).getText();
  }

  getButtonsClick() {
      return  browser.actions().mouseMove(element(by.tagName('b'))).click();
        }

}

test-e2e.spec.ts

    import { TestEngine } from './app.po';

    describe('Test Engine App', () => {
      let page: TestEngine;

      beforeEach(function (done) {
        setTimeout(function () {
          page = new TestEngine();
          done();
        }, 1);
      });

//1. Promise included

      it('should display the question for Validation', function (done) {
        page.navigateTo();
        page.getParagraphText()
          .then((text) => {
            expect(text).toEqual('Want to validate an engine?');
            done();
          });
      });

// 2. Promise included

      it('should display a button which is used for Validation', function (done) {
        page.navigateTo();
        page.getButtons().
          then((text) => {
            expect(text).toEqual('Login');
            done();
          });
      });

 //3. Promise not included   

      it('should click on the button which is used for Login', function (done) {
        page.navigateTo();
        page.getButtonsClick()
        done();
      });

    });

场景 上面的测试用例1,2,3出现错误时指出

Test Engine App
    √ should display the question for Validation
    √ should display a button which is used for Validation
    × should click on the button which is used for Login
      - Failed: timeout
        (Session info: chrome=69.0.3497.100)
        (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d6xgret43e5618de0x3a32ff6c19xx7e),platform=Windows NT 10.0.16299 x86_64)
        (Session info: chrome=69.0.3497.100)
        (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d6xgret43e5618de0x3a32ff6c19xx7e),platform=Windows NT 10.0.16299 x86_64)

      From asynchronous test:
      Error
          at Suite.<anonymous> (D:\TESTING CLONE\e2e\e2e\test.e2e-spec.ts:33:3)
          at Object.<anonymous> (D:\TESTING CLONE\e2e\e2e\test.e2e-spec.ts:5:1)
          at Module._compile (module.js:649:30)
          at Module.m._compile (D:\VSTS TESTING CLONE\e2e\node_modules\ts-node\src\index.ts:439:23)
          at Module._extensions..js (module.js:660:10)
          at Object.require.extensions.(anonymous function) [as .ts] (D:\TESTING CLONE\e2e\node_modules\ts-node\src\index.ts:442:12)

**************************************************
*                    Failures                    *
**************************************************

1) Test Engine App should click on the button which is used for Login
  - Failed: timeout
    (Session info: chrome=69.0.3497.100)
    (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.16299 x86_64)

Executed 3 of 3 specs (1 FAILED) in 5 mins 17 secs.
[16:56:48] I/launcher - 0 instance(s) of WebDriver still running
[16:56:48] I/launcher - chrome #01 failed 1 test(s)
[16:56:48] I/launcher - overall: 1 failed spec(s)
[16:56:48] E/launcher - Process exited with error code 1

但是,如果我使用 fit xit 分别运行所有3个,则每种情况都会通过,并且如果我以1-> 3-> 2的顺序通过交换来运行第三个测试用例带有2nd,然后全部通过。

我在这里做错了什么?回调函数done();是否放置在正确的位置?因为在这个规范文件中,我计划有100多个测试用例。所有都会包括涉及的承诺。

0 个答案:

没有答案