量角器:测试报告不一致?

时间:2015-07-27 09:34:33

标签: protractor

测试角度应用,测试有时会通过,有时会失败...

我的测试用例如下:

it('test-1: should has main button', function () {
    expect(page.demoButton).not.toBeUndefined();
});

it('test-2: should open modal on click secondary button', function () {
    page.demoButton.click().then(function () {
        page.SecondaryButton.click().then(function() {
            expect(page.Modal).not.toBeUndefined();
        });
    });
});

it('test-3: should open modal with correct text', function () {
    page.demoButton.click().then(function () {
        page.SecondaryButton.click().then(function() {
            expect(page.Modal.text.getText()).toEqual('Are you sure to cancel 
this?');
        });
    });
});

如果我运行测试,有时会通过测试,有时会有一些测试失败。 大多数时候错误就像:找不到使用定位器的元素:By.cssSelector(“。myButton”)。或者无法读取未定义的属性'getText'

提前谢谢!

1 个答案:

答案 0 :(得分:0)

我使用以下方法解决了这个问题:

browser.waitForAngular(); 

正如我看到getText和点击事件一起出现问题,所以:

it('test-2: should open modal on click secondary button', function () {
    page.demoButton.click().then(function () {
        browser.waitForAngular();
        page.SecondaryButton.click().then(function() {
            browser.waitForAngular();
            expect(page.Modal.text.getText()).toEqual('Are you sure to cancel 
            this?');
        });
    });
});

是解决方案。

相关问题