【问题标题】:protractor - "angular is not defined" when using `browser.setLocation('/')`量角器 - 使用 `browser.setLocation('/')` 时“未定义角度”
【发布时间】:2018-10-25 14:05:15
【问题描述】:

是不是因为 Angular v6 (like by.model and by.binding) 不支持 browser.setLocation

我尝试过await browser.waitForAngular(),但似乎没有任何改变。

我确实希望保持角度/量角器之间的同步(例如 browser.ignoreSynchronization = truebrowser.waitForAngularEnabled(true)

【问题讨论】:

    标签: angular protractor angular6 angular-e2e


    【解决方案1】:

    看来browser.setLocation 仅适用于 angular v1,我找不到 angular 2+ 的替代方案。

    我通过执行脚本来更改 URL 来让它工作,而 Angular 路由器将在不重新加载页面的情况下完成它(这是使用 useHash 来表示 RouterModule):

    const setLocation = url =>
      browser.executeScript(pUrl => window.location.href = `/#/${pUrl}`, url);
    

    那么它的工作原理类似于browser.setLocation:

     browser.get('http://angular.github.io/protractor/#/tutorial');
     setLocation('api');
     expect(browser.getCurrentUrl())
       .toBe('http://angular.github.io/protractor/#/api');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-30
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多