量角器按钮点击打开网页在新标签 [英] Protractor Button Click and open page in new tab

查看:140
本文介绍了量角器按钮点击打开网页在新标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的量角器。
我想,我点击一个按钮及其在新标签中打开一个页面自动一个场景,然后我们需要来填充新的一页表格并提交。

I am fairly new to Protractor. I am trying to automate a scenario where I click on a button and its opens up a page in new tab and then we need to populate form in new page and submit.

问题:当我点击按钮,打开新的一页。我的测试不会等待新的​​页面加载和说测试完成并成功消息。

Issue: when i click on button to open new page. My tests does not wait for new page to load and say test completed and success message.

我使用的按钮,简单的点击事件单击按钮。

I am using simple click event of that button to click the button.

元素(by.id(newPlan的))。点击()

element(by.id("newPlan")).click()

我缺少的东西吗?我需要做一些事情,使我的测试中等待新的页面加载,然后我可以执行某些功能?

Am I missing something ? Do i need to do something so that my tests wait for new page to load and then I can perform some functions ?

推荐答案

您需要等到页面通过回调打开。尝试在这个意义上说了一句:

You need to wait until the page opens by using callbacks. Try something in this sense:

    element(by.id("newPlan")).click().then(function () {
        browser.getAllWindowHandles().then(function (handles) {
            newWindowHandle = handles[1]; // this is your new window
            browser.switchTo().window(newWindowHandle).then(function () {
                // fill in the form here
                expect(browser.getCurrentUrl()).toMatch(/\/url/);
            });
        });
    });

这篇关于量角器按钮点击打开网页在新标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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