我在iFrame中运行了一个角度应用程序。我必须启动父应用程序URL,因为它提供了一些标志,使角度应用程序按预期工作。现在我需要在iFrame中为angular app编写量角器测试。
这是代码。
describe('French page', function() {
var IFRAME = "iframe",
TITLE_FR = 'Découverte automatique',
PAGE_URL = '/SAAS/admin/app/page',
pagePaths = browser.params.paths;;
beforeEach(function (done) {
LOGIN_PAGE.goToPageAndLogin().then(function (){
browser.driver.ignoreSynchronization = true;
browser.get(PAGE_URL); // application has angular app in iFrame
browser.sleep(5000);
browser.waitForAngular();
done();
});
});
afterEach(function (done) {
demoPause();
LOGIN_PAGE.logout().then(done);
});
it('should be able to launch with fr-FR locale', function (done) {
browser.driver.switchTo().frame(IFRAME); //Switch to angular app in iFrame
// Check if element text is in french
browser.driver.findElement(by.css('.app-menu li:nth-child(1) p')).then(function (elem) {
elem.getText().then(function (text) {
expect(text).toBe(TITLE_FR); // I can see that both texts are same here while debugging
browser.driver.ignoreSynchronization = true;
done();
});
});
});
});
测试条件已通过,但退出时出现以下错误。 消息:
失败:在页面上找不到Angular https://host/abcd/admin/app/page
重试寻找角度超过
答案 0 :(得分:1)
通过添加
解决了这个问题browser.ignoreSynchronization = true;
前 browser.get(PAGE_URL);
答案 1 :(得分:0)
少数事情:
参数 IFRAME 传入:
browser.driver.switchTo().frame(IFRAME);
必须是 ID
元素的属性,而不是元素的标记名称,例如:
您的iframe元素
<iframe id="myIframeId" name="frame3">...</iframe>
在这种情况下你会做
browser.diver.switchTo().frame("myIframeId");
请勿在非角度页面上调用browser.waitForAngular();
。由于只有你的iframe元素是Angular,我建议在继续之前做以下操作以确保存在特定元素:
browser.driver.wait(function() {
return browser.driver.isElementPresent(by.css("your_selector")).then(function(present) {
return present;
});
}, 20000);
这将等待元素出现20秒,无论页面是否为Angular,然后继续。
browser.driver.ignoreSynchronization = false;
重新打开Angular同步。由于您在iframe中的代码是Angular。