【问题标题】:Angular could not be found on the page with angular application while running test for angular app in iFrame在 iFrame 中运行 Angular 应用程序测试时,无法在具有 Angular 应用程序的页面上找到 Angular
【发布时间】:2017-07-01 01:09:01
【问题描述】:

我有一个在 iFrame 中运行的 Angular 应用程序。我必须启动父应用程序 URL,因为它提供了一些标志,使 Angular 应用程序按预期工作。现在我需要在 iFrame 中为 Angular 应用程序编写量角器测试。

这里是代码。

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

重试寻找角度超出范围

【问题讨论】:

    标签: protractor


    【解决方案1】:

    问题解决了

    browser.ignoreSynchronization = true;

    之前 browser.get(PAGE_URL);

    【讨论】:

      【解决方案2】:

      几件事:

      1. 参数IFRAME传入: browser.driver.switchTo().frame(IFRAME); 需要是 ID 元素的属性,而不是元素的标签名,例如:

        您的 iframe 元素

        <iframe id="myIframeId" name="frame3">...</iframe>

        在这种情况下你会这样做

        browser.diver.switchTo().frame("myIframeId");

      2. 不要在非角页面上调用browser.waitForAngular();。由于只有您的 iframe 元素是 Angular,因此我建议在继续之前执行以下操作以确保存在特定元素: browser.driver.wait(function() { return browser.driver.isElementPresent(by.css("your_selector")).then(function(present) { return present; }); }, 20000);

        这将等待一个元素出现 20 秒,无论页面是否为 Angular,然后继续。

      3. 切换到 iframe 元素后,您应该调用 browser.driver.ignoreSynchronization = false; 重新打开 Angular 同步。由于 iframe 中的代码是 Angular。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-24
        • 1970-01-01
        • 2018-03-17
        • 1970-01-01
        • 1970-01-01
        • 2020-06-05
        • 1970-01-01
        • 2021-03-19
        相关资源
        最近更新 更多