量角器间歇性失败的测试-承诺执行订单吗? [英] Intermittently failing tests with Protractor - promise order execution?

查看:73
本文介绍了量角器间歇性失败的测试-承诺执行订单吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临一系列测试套件中间歇性的量角器测试失败,在失败案例中没有任何真实的模式来表明可能发生的情况,例如,与失败的测试不同的测试。有时候我会遇到很多失败,而在其他情况下,我只会遇到一个失败案例。

I am facing intermittent protractor test failures across a range of test suites without any real pattern in the fail cases to indicate what could be going on, for example it's not the same tests that are failing. Sometimes I will get many failures and on other occasions just a single fail case.

我应该指出,这种情况只会在Jenkins CI服务器上执行测试时才会发生我们已经配置(在linux下运行)。在Windows开发机上本地运行30-40次后,我们可能会遇到一个失败的案例,我可以忍受!

I should point out that this tends to only happen when performing test runs on a Jenkins CI server we have configured (running under linux). Locally on Windows dev machines we may get a single fail case after 30-40 runs which I can live with!

我们正在测试的应用程序当前是使用angular 1.5和我们使用的是角材料1.1.3

The application we are testing is currently built with angular 1.5 and we are using angular material 1.1.3

由于角材料中使用的动画及其性能可能会受到影响,我们已经尝试按照这种方法禁用动画此处,当然可以加快测试速度,但无济于事我们看到的失败案例/

Due to the animations used in angular material and the performance hit these can have, we have already tried disabling animations following this approach here which certainly make the tests quicker but dont help with the fail cases we are seeing/

我现在正在一次又一次地运行一个测试套件,在成功运行5次之后,它在第6次失败了尝试在我们的Jenkins CI环境的Linux机器上进行本地测试,我现在已经多次运行了该测试,并且还没有失败。

I am at a point now where I am running one test suite over and over, after 5 successful runs it then failed on it's 6th attempt on our Jenkins CI environment\linux box, locally I have run this test many times now and no failures yet.

所涉及的测试套件将在下面详细说明页面目标文件摘要:

The test suite in question is detailed below along with a page object file snippet:

//test suite
describe('Operators View', function () {
  var operatorPage = require('./operators.po.js'),
    loginView = require('../login/login.po.js'),
    page = new operatorPage();

  describe('Large screen tests', function () {
    beforeAll(function () {
      loginView.login();
    });

    afterAll(function () {
      loginView.logout();
    });

    it('should create an operator', function () {
      page.settlementBtn.click();
      page.operatorsBtn.click();
      page.fabBtn.click();
      page.createOperator();
      expect(page.headline.getText()).toEqual('Operators');
    });
    });
});

// operators.po.js
var operatorsSection = function() {
    this.helper = new Helpers();
    this.headline = element(by.css('.md-headline'));
    this.settlementBtn = element(by.css('[ui-sref="settlement"]'));
    this.operatorsBtn = element(by.css('[ui-sref="operators"]'));
    this.fabBtn = element(by.css('.md-fab'));

    // Form Elements
    this.licenceNumber = element(by.model('vm.transportOperator.licenceNumber'));
    this.tradingName = element(by.model('vm.tradingName'));
    this.name = element(by.model('vm.name'));
    this.operatorAddressFirstLine = element(by.model('vm.transportOperator.address.line1'));
    this.operatorAddressCityTown = element(by.model('vm.transportOperator.address.line5'));
    this.operatorAddressPostCode = element(by.model('vm.transportOperator.address.postcode'));
    this.payeeAddressFirstLine = element(by.model('vm.transportOperator.payee.address.line1'));
    this.payeeAddressCityTown = element(by.model('vm.transportOperator.payee.address.line4'));
    this.payeeAddressPostCode = element(by.model('vm.transportOperator.payee.address.postcode'));
    this.opID = element(by.model('vm.transportOperator.fields.opID'));
    this.spID = element(by.model('vm.transportOperator.fields.spID'));
    this.schemeSelect = element(by.model('reference.scheme'));
    this.schemeOptions = element(by.exactRepeater('scheme in vm.schemes').row('0'));
    this.alias = element(by.model('reference.alias'));
    this.reference = element(by.model('reference.reference'));
    this.saveBtn = element(by.css('.md-raised'));


    this.createOperator = function() {
      this.licenceNumber.sendKeys(this.helper.getRandomId(10));
      this.tradingName.sendKeys('Protractor Trade Name LTD');
      this.name.sendKeys('Protractor Trade Name');
      this.operatorAddressFirstLine.sendKeys('Protractor Town');
      this.operatorAddressCityTown.sendKeys('Cardiff');
      this.operatorAddressPostCode.sendKeys('PT4 4TP');
      this.payeeAddressFirstLine.sendKeys('Protractor Town');
      this.payeeAddressCityTown.sendKeys('Cardiff');
      this.payeeAddressPostCode.sendKeys('PT4 4TP');
      this.opID.sendKeys('177');
      this.spID.sendKeys('Protractor Spid');
      this.schemeSelect.click();
      this.schemeOptions.click();
      this.alias.sendKeys('PTAlias');
      this.reference.sendKeys('Protractor');
      this.saveBtn.click();
    }

  };
module.exports = operatorsSection;

在此测试套件中,调用 createOperator 从PO文件中调用并单击 savteBtn ,应用程序将过渡到显示已创建条目表的状态(当然是在成功创建之后)。我们也正在使用角度ui路由器,当前版本为0.2.18

In this test suite after the call to createOperator from the PO file is invoked and the savteBtn is clicked, the application will transition to a state that shows a table of created entries (after successful creation of course). We are using angular ui-router also, currently on version 0.2.18

期望失败,并显示以下内容:

The expectation fails with:


期望'创建一个操作员'等于'操作员'。

Expected 'Create An Operator' to equal 'Operators'.

但是所捕获的随附屏幕截图显示在带有运算符标题的表视图中,期望调用中对 page.headline.getText()的调用似乎被调用为时过早,因此在数据库操作之前创建项目并且页面更改是否有机会完成?

Yet the accompanying screenshot that was captured shows the table view with an 'Operators' heading, it seems the call to page.headline.getText() inside the expectation call is being invoked too soon, so before the database operation to create the item and the page change has had a chance to complete?

我开始怀疑这是否可以归因于量角器执行的承诺。我看过很多有关量角器中控制流的文章,为什么有时您应该使用 .then()来了解量角器调用的诺言的结果?

I have started wondering if this could be down to the order of promises executed by protractor. I have come across articles talking about control flow in protractor and why there may be occasions when you should hook into the result of a protractor call's promise using .then() - I found this

我想知道是否应该将调用移至 saveBtn.click(),即在页面对象的末尾调用将createOperator 函数添加到测试套件中,因此应执行以下操作:

It got me wondering if I should move the call to my saveBtn.click(), that's called at the end of my page object's createOperator function, into the test suite, so doing something like:

it('should create an operator', function () {
      page.settlementBtn.click();
      page.operatorsBtn.click();
      page.fabBtn.click();
      page.createOperator();
      page.saveBtn.click().then(function(){
        expect(page.headline.getText()).toEqual('Operators');
      });
    });

老实说,我开始在这里抓稻草,所以任何想法

I'm starting to clutch at straws here to be honest, so any thoughts\advice from the community here would be much appreciated.

谢谢!

推荐答案

请求,这是我用于等待URL保持原样的函数。

As requested, here is the function I use for waiting for URLs to be as they should.

public waitForUrlToBeLike (urlPart: string, timeout: number = 10000) {
    return browser.wait(() => {
        return browser.driver.getCurrentUrl().then((url) => {
            let regex = new RegExp(urlPart);
            return regex.test(url);
        });
    }, timeout);
}

在制作之前,我也经常使用以下内容来等待元素的出现对它们的断言:

I also use the following a lot to wait for elements to be present before making assertions on them:

public waitTillPresent (element: ElementFinder, timeout: number = 10000) {
    return browser.wait(() => {
        return element.isPresent();
    }, timeout);
}

这篇关于量角器间歇性失败的测试-承诺执行订单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆