【问题标题】:How can I make my protractor test pass?我怎样才能使我的量角器测试通过?
【发布时间】:2016-03-25 05:25:13
【问题描述】:

我为我的 Angular 应用创建了一个简单的量角器测试。当我单击一个按钮时,会设置一个输入值:

 $scope.fillForm=function(){
        console.log('fillform');
        $scope.myText='hoera';
    };

e2e 测试期望输入填充“hoera”:

describe('fill in form e2e test', function () {
    it('should test  form', function () {
        browser.get('http://localhost:63342/protractor_new/index.html');
        element(by.buttonText('go')).click().then(function () {
            var el = element(by.model('myText')).getText();
            expect(el).toEqual('hoera');
        });
    });
});

当我使用“protractor conf”运行测试时,我得到:

Expected '' to equal 'hoera'.

我希望类似:预期的 'hoera' 等于 'hoera'?我怎样才能让它通过也许在角度设置值之前有延迟?这是代码的链接:https://github.com/dimitri-a/protractor_new

【问题讨论】:

    标签: angularjs protractor


    【解决方案1】:

    你很亲密。您的getclick 应添加到controlFlow,因此无需点击then。但是您的getText 上确实需要then。这应该工作......

    describe('fill in form e2e test', function () {
        it('should test  form', function () {
            browser.get('http://localhost:63342/protractor_new/index.html');
            element(by.buttonText('go')).click();
            element(by.model('myText')).getText().then(function(el) {
                expect(el).toEqual('hoera');
            });
        });
    });
    

    【讨论】:

    • 仍然得到相同的结果?如果我尝试将它绑定到 {{myText}} 那么它会奇怪地工作:而不是 by.model('myText') 使用 by.binding('myText')
    • 我无法与您的定位器策略交谈,因为您没有提供代码,但这将解决您的测试结构问题。祝你好运!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    相关资源
    最近更新 更多