无棱角页面点击打开后, [英] Non-angular page opened after a click

查看:189
本文介绍了无棱角页面点击打开后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现以下测试方案:

I'm trying to implement the following test scenario:


  • 在页面上执行的一个标志点击

  • 断言没有打开(在Chrome标签)的新浏览器窗口,检查当前网址

问题是,在一个新的浏览器窗口中打开该页面是一个的无棱角页的,而我在执行点击主界面是一个的角页的。

The problem is that the page opened in a new browser window is a non-angular page while the main page I'm performing the click in is an angular page.

这是我第一次尝试:

it("should show logo", function () {
    var logo = scope.page.logo;
    expect(logo.isDisplayed()).toEqual(true);

    // opens a new page on click
    logo.click().then(function () {
        browser.getAllWindowHandles().then(function (handles) {
            browser.switchTo().window(handles[1]).then(function () {
                expect(browser.getCurrentUrl()).toEqual('http://myurl.com/');
            });

            // switch back to the main window
            browser.switchTo().window(handles[0]);
        });
    });
});

这失败:

错误:错误等待量角器与网页同步:
  角不能在窗口中找到

Error: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"

这是可以理解的。

我的第二次​​尝试玩弄 ignoreSynchronization 布尔标志:

My second attempt was to play around with ignoreSynchronization boolean flag:

browser.ignoreSynchronization = true;
logo.click().then(function () {
    browser.getAllWindowHandles().then(function (handles) {
        browser.switchTo().window(handles[1]).then(function () {
            expect(browser.getCurrentUrl()).toEqual('http://myurl.com/');
        });

        // switch back to the main window
        browser.switchTo().window(handles[0]);
    });

这实际上使这个特殊的测试通过没有任何错误,但它会影响这一块后执行每一项测试,因为浏览器是一个全局对象,并测试之间共享 - 量角器不再与角同步导致成各种错误的页面上。

This actually makes this particular test pass without any errors, but it affects every test executed after this one, because browser is a global object and is shared between tests - protractor no longer syncs with angular on a page which results into all sorts of errors.

我应该如何实现测试?

How should I implement the test?

作为一种变通方法,我可以改变<一href=\"https://github.com/angular/protractor/commit/167038499aacfd5def03472f9f548529b273e1e0\"><$c$c>restartBrowserBetweenTests设置以真正和变更 ignoreSynchronization 价值没有任何问题 - 但它会减慢测试显着

As a workaround, I can change the restartBrowserBetweenTests setting to true and change ignoreSynchronization value without any problems - but it slows down the tests dramatically.

推荐答案

您可以设置 ignoreSynchronization 一旦你验证做是错误的。但是,请注意ignoreSynchronization是同步的,而其他一切(点击/获取/等)是异步的,所以你必须要小心这一点。可能是最安全的方法是将其设置为在beforeEach真假afterEach,只是测试在测试单标识点击。

You can set ignoreSynchronization to be false once your verification is done. However, note that ignoreSynchronization is synchronous while everything else (click/get/etc) is asynchronous, so you need to be careful with that. Probably the safest way is to set it to true in beforeEach and false in afterEach, and just test that single logo click in that test.

这篇关于无棱角页面点击打开后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆