我的测试目标页面有 SSO 集成登录。一旦我点击该页面,SSO 集成 Windows 身份验证将发生,然后定向到主页。
我尝试关闭同步,第一次测试检查标题时它工作,但第二次测试时,它会返回无法定位元素的错误,当我打开同步时,它会返回不同步错误和未定义错误。
describe('Test area to ', function () {
var menuObjects = require('../page/MenuObjects.js');
it('Verify Page Title', function () {
menuObjects.setSyncOff();
browser.get('/home/');
expect(browser.getTitle()).toEqual('Home');
browser.driver.sleep(3000);
});
it('Navigate ', function () {
menuObjects.setSyncOn();
menuObjects.menuButton.click();
});
});
导航的错误消息 - 使用 menuObjects.setSyncOn();
Error while waiting for Protractor to sync with the page: "Cannot read property 'get' of undefined"
导航的错误消息 - 使用 menuObjects.setSyncOff();
NoSuchElementError: No element found using locator: By.id("menu-link")
ng-app
包含在 body 内的 div 中:
<body style="width: 100%">
<div class="frame" style="width: 100%">
<div class="container-fluid" style="width: 100%">
<div class="" style="width: 100%">
<div style="width: 100%">
<!--_AngularBaseLayout: BEGIN-->
<div ng-app="myHomeApp" ng-cloak class="ng-cloak">
<div ng-view id="ng-view"> </div>
</div>
有什么建议吗?
最佳答案
如果 ng-app
没有定义在 html
或 body
上,你需要让 protractor
知道通过设置 rootElement
configuration setting :
exports.config = {
seleniumAddress: env.seleniumAddress,
baseUrl: env.baseUrl,
...
// Selector for the element housing the angular app.
rootElement: 'div#nested-ng-app'
};
这将使玩弄开关同步变得没有必要 - Protractor 将等待 Angular “稳定下来”,然后再继续执行进一步的测试。
如果这对 NoSuchElementError
错误没有帮助,您可以在 presenceOf
"Expected Condition" 的帮助下显式等待元素出现。 :
var EC = protractor.ExpectedConditions;
var elm = browser.wait(EC.presenceOf($('#menu-link')), 5000);
关于angularjs - 等待 Protractor 与页面同步时出错 : "Cannot read property ' get' of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29910130/