在等待量角器与具有基本量角器测试的页面同步时遇到错误 [英] Running into Error while waiting for Protractor to sync with the page with basic protractor test

查看:71
本文介绍了在等待量角器与具有基本量角器测试的页面同步时遇到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

describe('我的主页', function() {var ptor = protractor.getInstance();之前每个(功能(){//ptor.ignoreSynchronization = true;ptor.get('http://localhost/myApp/home.html');//ptor.sleep(5000);})描述('登录',功能(){var email = element.all(protractor.By.id('email')), pass = ptor.findElement(protractor.By.id('password')), loginBtn = ptor.findElement(protractor.By.css('#login button'));it('应该输入并登录', function(){//email.then(function(obj){//console.log('email', obj)//})email.sendKeys('josephine@hotmail.com');pass.sendKeys('shakalakabam');loginBtn.click();})})});

以上代码返回

 错误:等待 Protractor 与页面同步时出错:{}

我不知道为什么会这样,正确加载页面,似乎是选择失败的元素.

到SSHMSH:

谢谢,你几乎是对的,并给了我正确的哲学,所以关键是 ptor.sleep(3000) 让每个页面等待 ptor 与项目同步.

解决方案

我收到了同样的错误消息(Angular 1.2.13).我的测试过早开始,Protractor 似乎没有等待 Angular 加载.

看来我错误地配置了量角器配置文件.当 ng-app 指令未定义在 BODY 元素上,而是定义在后代元素上时,您必须将量角器配置文件中的 rootElement 属性调整为选择器定义您的角度根元素,例如:

//量角器-conf.jsrootElement: '.my-app',

当您的 HTML 是:

describe('my homepage', function() {
    var ptor = protractor.getInstance();
    beforeEach(function(){
        // ptor.ignoreSynchronization = true;
        ptor.get('http://localhost/myApp/home.html');
        // ptor.sleep(5000);
    })
    describe('login', function(){

        var email = element.all(protractor.By.id('email'))
            , pass = ptor.findElement(protractor.By.id('password'))
            , loginBtn = ptor.findElement(protractor.By.css('#login button'))
            ;

        it('should input and login', function(){
            // email.then(function(obj){
            //  console.log('email', obj)
            // })
            email.sendKeys('josephine@hotmail.com');
            pass.sendKeys('shakalakabam');
            loginBtn.click();

        })
    })

});

the above code returns

 Error: Error while waiting for Protractor to sync with the page: {}

and I have no idea why this is, ptor load the page correctly, it seem to be the selection of the elements that fails.

TO SSHMSH:

Thanks, your almost right, and gave me the right philosophy, so the key is to ptor.sleep(3000) to have each page wait til ptor is in sync with the project.

解决方案

I got the same error message (Angular 1.2.13). My tests were kicked off too early and Protractor didn't seem to wait for Angular to load.

It appeared that I had misconfigured the protractor config file. When the ng-app directive is not defined on the BODY-element, but on a descendant, you have to adjust the rootElement property in your protractor config file to the selector that defines your angular root element, for example:

// protractor-conf.js
rootElement: '.my-app',

when your HTML is:

<div ng-app="myApp" class="my-app">

这篇关于在等待量角器与具有基本量角器测试的页面同步时遇到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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