量角器按钮 单击并在新选项卡中打开页面 [英] Protractor Button Click and open page in new tab

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

问题描述

我对 Protractor 还很陌生.我正在尝试自动化一个场景,即我单击一个按钮并在新选项卡中打开一个页面,然后我们需要在新页面中填充表单并提交.

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.

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

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天全站免登陆