如何使用 Mink、Selenium 2 和 Behat 与弹出窗口交互? [英] How do I interact with a popup window with Mink, Selenium 2, and Behat?

查看:25
本文介绍了如何使用 Mink、Selenium 2 和 Behat 与弹出窗口交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与 Behat 一起浏览一个内部站点,并且大部分情况下进展顺利.但问题是在网站的某些部分,我们有弹出窗口来完成一个动作.在这种情况下,我们点击撤销"按钮,然后弹出一个窗口让您选择原因并保存.

I am running through an internal site with Behat and for the most part it is going really well. But the problem is that on certain parts of the site we have popup windows that come up to complete an action. In this case we hit a "Withdraw" button and a popup comes up to have you select a reason and save it.

在理想情况下,如果我真的设计了这个应用程序,该网站将不会使用任何弹出窗口.但我是应该实施自动化功能测试的新人(我正在从头开始学习如何做到这一点).所以我现在对网站设计没有任何发言权(尽管随着时间的推移我会推动很多改变).

In an ideal world, and if I had actually designed this app, the site wouldn't be using any popup windows. But I am the new guy who is supposed to implement automated functional tests (and I am learning how to do that from the ground up). So I don't really have any say over the site design at this point (though I will push for a lot of changes as time goes by).

我在 Ubuntu 12.10 系统上使用 Mink 和 Selenium 2 驱动程序运行 Behat(最终必须在 Windows 环境中运行一些测试以在 IE 中进行测试).我还在使用 PhantomJS 进行我设置的一些测试.

I am running Behat with Mink and the Selenium 2 driver on an Ubuntu 12.10 system (will eventually have to run some tests on a Windows environment for testing in IE). I am also using PhantomJS for some of the tests I have setup.

无论如何,Behat/Mink 是否支持通过 Selenium 2 驱动程序(或通过 PhantomJS)以某种方式处理弹出窗口?我在所有这些自动化设置中处于早期阶段,实际上我只是在尝试使用工具.如果有更好的工具可以处理这个问题,请告诉我.

Anyway, does Behat/Mink support working with popup windows somehow through the Selenium 2 driver (or through PhantomJS)? I am early in all of this automation setup and really I am just experimenting with tools. If there is a better tool that can handle this then please let me know.

我的主要问题是如何让 Behat/Mink 使用弹出窗口、选中一个框、填写一个字段并单击保存按钮?我知道如何做所有事情,除了让它直接与新弹出的窗口交互.欢迎任何想法/建议.

My primary question is how do I get Behat/Mink to work with the popup window, check a box, fill in a field, and click the save button? I know how to do everything except get it to interact directly with the newly popped up window. Any ideas/suggestions would be welcome.

谢谢!

推荐答案

原来Mink包含一些窗口切换功能,但无法识别这些窗口.所以我写了两个函数 getWindowName() 和 getWindowNames() 分别标识当前窗口和所有打开的窗口.我将这些更改提交给 GitHub 中的项目,看来我的修复将很快在代码库中实现.

So it turns out that Mink includes some window switching features, but no way to identify said windows. So I wrote two functions getWindowName() and getWindowNames() that identify the current window and all open windows respectively. I committed these changes to the project in GitHub it seems that my fixes will get implemented soon into the code base.

但是通过这些更改,我可以毫无问题地切换窗口.

But with these changes I am able to switch windows no problem.

链接:https://github.com/Behat/Mink/pull/341

这篇关于如何使用 Mink、Selenium 2 和 Behat 与弹出窗口交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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