【问题标题】:Protractor : Error: Error while waiting for Protractor to sync with the page: "window.angular is undefined. If i create new object of PageObject量角器:错误:等待量角器与页面同步时出错:“window.angular 未定义。如果我创建 PageObject 的新对象
【发布时间】:2017-02-24 13:10:15
【问题描述】:

我正在尝试将页面对象的对象创建到规范中,但出现错误。

dashboard.pageObject.js

/*global exports,console*/

module.exports = function(){

    this.dashboarurl = 'http://localhost:2525/ars-webapp/';    

        this.createNewReport_Clickhear = element(By.xpath("//a[contains(.,'Click Here')]"));
        this.reportInputModel = element(by.model('reportDefCntrl.reportDef.reportname'));
        this.reportDescriptionModel = element(by.model('reportDefCntrl.reportDef.reportdesc'));     
        this.templateListSelect = element(By.xpath("//select[@id='template-list-select']")).click();
        this.selectAlarmDashboarTemplate= element(By.xpath("//option[contains(@value,'number:2')]"));
        this.durationOfAlarmTemplate = element(By.xpath("//span[@class='ui-select-placeholder text-muted ng-binding']"));
        this.duration_Daily = element(By.xpath("//span[contains(.,'Daily')]"));
        this.addObject = element(By.xpath("//button[@data-ng-click='reportDefCntrl.addLogObjects()']"));
        this.searchInput = element(By.xpath("//input[@type='search']"));
        this.searchButton = element(By.xpath("//button[contains(.,'Search')]"));
        this.selectAllButton = element(By.xpath("//button[contains(.,'SelectAll')]"));
        this.addObjectButton = element(By.xpath("//button[@data-ng-click='addLogObjectsCntrl.submitObjects()']"));
        this.saveButton = element(By.xpath("//button[contains(.,'Save')]"));

}

规范文件是

/全局要求,控制台/

var Dashboard = require('../pageObjects/dashboard.pageObject.js');

var dashboard = new Dashboard();

describe('angularjs homepage todo list', function() {
  it('should add a todo', function() {
    browser.get(dashboard.dashboarurl);
    }

如果我跳过这一行

var dashboard = new Dashboard();

并提供

 browser.get('http://localhost:2525/ars-webapp/'); 

而不是

browser.get(dashboard.dashboarurl);

它正在工作。 但我不能使用页面对象的功能。

如果我使用

var dashboard = new Dashboard(); 

所以我出错了

E/launcher - 等待 Protractor 与页面同步时出错: “window.angular 未定义。这可能是因为这是一个 非角度页面或因为您的测试涉及客户端导航, 这可能会干扰量角器的引导。看 http://git.io/v4gXM了解详情"

【问题讨论】:

  • 您要测试的页面是 Angular 的吗?如果不是你不能使用'browser.get()'
  • 是的,这个页面是有角度的页面。但是为什么我不能初始化对象 new Dashboard();

标签: angularjs jasmine protractor


【解决方案1】:

哦,伙计..找到了!!..您的代码中一切都很好。你知道吗 .. 问题是 .. 你的文件中有 click() 在这一行 this.templateListSelect = element(By.xpath("")).click() - dashboard.pageObject.js

因为您首先有一个 require() .. 仪表板文件首先执行,click() 甚至在 browser.get() 之前被触发,这就是您看到该错误的原因

【讨论】:

    猜你喜欢
    • 2016-04-26
    • 2014-05-16
    • 2018-12-07
    • 1970-01-01
    • 2019-08-16
    • 2016-08-16
    • 2019-10-03
    • 2019-06-12
    • 1970-01-01
    相关资源
    最近更新 更多