Php Codeception-关闭弹出窗口中断selemium测试
我正在使用Codeception和Selenium/FacebookWebdriver测试一个简单的流,其中一个弹出窗口在最后关闭,导致整个测试中断 代码已完成(测试将运行),并将重现错误。 我真的很绝望,任何建议都将不胜感激 以下是我得到的错误: Codeception错误消息:Php Codeception-关闭弹出窗口中断selemium测试,php,selenium,testing,codeception,Php,Selenium,Testing,Codeception,我正在使用Codeception和Selenium/FacebookWebdriver测试一个简单的流,其中一个弹出窗口在最后关闭,导致整个测试中断 代码已完成(测试将运行),并将重现错误。 我真的很绝望,任何建议都将不胜感激 以下是我得到的错误: Codeception错误消息: [Facebook\WebDriver\Exception\NoSuchWindowException] 找不到窗口。浏览器窗口可能已关闭。 Selenium服务器输出消息: 警告-异常:未找到窗口。浏览器窗口可能已
[Facebook\WebDriver\Exception\NoSuchWindowException]
找不到窗口。浏览器窗口可能已关闭。
Selenium服务器输出消息:
警告-异常:未找到窗口。浏览器窗口可能已关闭。
这段代码再现了这个问题。
它由3.html文件(main.html、intermediate.html、popup.html)、测试文件(PopupCest.php)和配置文件(selenium.suite.yml)组成
PopupCest.php
<?php
class PopupCest
{
public function popup(SeleniumTester $I)
{
$I->expectTo('Start on main page and click a link that opens a popup');
$I->amOnPage('/main.html');
$I->click('#main-link');
$I->expectTo('Interact with the popup window and click the final confirmation button');
$I->switchToNextTab();
$I->click('#final-confirmation-button');
$I->expectTo('Go back to intermediate window and let it do its magic');
$I->switchToPreviousTab();
$I->see('contents of this intermediate page');
$I->seeInCurrentUrl('intermediate.html');
}
}
main.html
class_name: SeleniumTester
modules:
enabled:
- WebDriver:
url: http://localhost
browser: firefox
- \Helper\Selenium
<html>
<head>
<meta charset="utf-8">
<title>Main page - under my control</title>
<meta name="description" content="Main page - under my control">
</head>
<body>
<h1>Main</h1>
<p>
After clicking this link, "intermediate page" url is received from a backend operation in reality.
</p>
<br>
<a href="intermediate.html" id="main-link">Click here to open the popup</a> <br>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>External - intermediate page</title>
<meta name="description" content="Intermediate page outside of my control">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<h1>Intermediate</h1>
<p>
In reality, contents of this intermediate page is fully controlled by other party - a payment processor. <br>
It only load a javascript that opens up a popup window where user enters his payment details.
</p>
<script type="text/javascript">
$(function() {
var settings = "height=400,width=500,status=yes,dependent=no,resizable=yes";
popup = window.open('popup.html', 'dont_know_the_name_here', settings);
if (popup != null) {
popup.focus();
}
});
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>External - popup</title>
<meta name="description" content="Popup page outside of my control">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<h1>Popup</h1>
<p>
Contents of this page is fully controlled by other party - a payment processor. <br>
This is where user enters his payment details.
</p>
<p>
e.g. <i>"After you have finished your data input, click here to:"</i> <br>
<a href="" id="final-confirmation-button">Confirm your payment</a>
</p>
<script type="text/javascript">
$(function() {
$('#final-confirmation-button').on('click', function(e) {
e.preventDefault();
window.close(); // <-- this breaks it all
});
});
</script>
</body>
</html>
主页-在我的控制下
主要
单击此链接后,实际上会从后端操作接收“中间页”url。
intermediate.html
class_name: SeleniumTester
modules:
enabled:
- WebDriver:
url: http://localhost
browser: firefox
- \Helper\Selenium
<html>
<head>
<meta charset="utf-8">
<title>Main page - under my control</title>
<meta name="description" content="Main page - under my control">
</head>
<body>
<h1>Main</h1>
<p>
After clicking this link, "intermediate page" url is received from a backend operation in reality.
</p>
<br>
<a href="intermediate.html" id="main-link">Click here to open the popup</a> <br>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>External - intermediate page</title>
<meta name="description" content="Intermediate page outside of my control">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<h1>Intermediate</h1>
<p>
In reality, contents of this intermediate page is fully controlled by other party - a payment processor. <br>
It only load a javascript that opens up a popup window where user enters his payment details.
</p>
<script type="text/javascript">
$(function() {
var settings = "height=400,width=500,status=yes,dependent=no,resizable=yes";
popup = window.open('popup.html', 'dont_know_the_name_here', settings);
if (popup != null) {
popup.focus();
}
});
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>External - popup</title>
<meta name="description" content="Popup page outside of my control">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<h1>Popup</h1>
<p>
Contents of this page is fully controlled by other party - a payment processor. <br>
This is where user enters his payment details.
</p>
<p>
e.g. <i>"After you have finished your data input, click here to:"</i> <br>
<a href="" id="final-confirmation-button">Confirm your payment</a>
</p>
<script type="text/javascript">
$(function() {
$('#final-confirmation-button').on('click', function(e) {
e.preventDefault();
window.close(); // <-- this breaks it all
});
});
</script>
</body>
</html>
外部-中间页
中间的
实际上,这个中间页面的内容完全由另一方(支付处理方)控制
它只加载一个javascript,该javascript打开一个弹出窗口,用户在其中输入其支付详细信息。
$(函数(){
var settings=“高度=400,宽度=500,状态=yes,从属=no,可调整大小=yes”;
popup=window.open('popup.html'、'not\u know\u name\u here',settings);
如果(弹出!=null){
popup.focus();
}
});
popup.html
class_name: SeleniumTester
modules:
enabled:
- WebDriver:
url: http://localhost
browser: firefox
- \Helper\Selenium
<html>
<head>
<meta charset="utf-8">
<title>Main page - under my control</title>
<meta name="description" content="Main page - under my control">
</head>
<body>
<h1>Main</h1>
<p>
After clicking this link, "intermediate page" url is received from a backend operation in reality.
</p>
<br>
<a href="intermediate.html" id="main-link">Click here to open the popup</a> <br>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>External - intermediate page</title>
<meta name="description" content="Intermediate page outside of my control">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<h1>Intermediate</h1>
<p>
In reality, contents of this intermediate page is fully controlled by other party - a payment processor. <br>
It only load a javascript that opens up a popup window where user enters his payment details.
</p>
<script type="text/javascript">
$(function() {
var settings = "height=400,width=500,status=yes,dependent=no,resizable=yes";
popup = window.open('popup.html', 'dont_know_the_name_here', settings);
if (popup != null) {
popup.focus();
}
});
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>External - popup</title>
<meta name="description" content="Popup page outside of my control">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<h1>Popup</h1>
<p>
Contents of this page is fully controlled by other party - a payment processor. <br>
This is where user enters his payment details.
</p>
<p>
e.g. <i>"After you have finished your data input, click here to:"</i> <br>
<a href="" id="final-confirmation-button">Confirm your payment</a>
</p>
<script type="text/javascript">
$(function() {
$('#final-confirmation-button').on('click', function(e) {
e.preventDefault();
window.close(); // <-- this breaks it all
});
});
</script>
</body>
</html>
外部-弹出窗口
弹出窗口
本页面的内容完全由另一方(支付处理方)控制
这是用户输入其付款详细信息的地方。
e、 g.“完成数据输入后,单击此处:”
$(函数(){
$(“#最终确认按钮”)。在('click',函数(e)上{
e、 预防默认值();
window.close();//测试代码似乎是正确的,我怀疑问题与过时的版本或可能是Firefox驱动程序有关
我使用chrome+chromedriver测试了您的代码,它似乎可以正常工作。下面是一个测试报告,其中说明了如何使用chromedriver+所需的配置更改:
一般来说,我建议使用Chrome进行这种类型的测试,除非您专门测试Firefox,或者这是一项要求。谢谢您,Henri,感谢您花时间提供帮助。老版本的Firefox似乎确实存在问题。我使用的是Mozilla Firefox 44.0.2与selenium-server-standalone-2.53.1.jar和xvfb结合使用ubuntu 14.04。chrome+chromedriver现在也可以进行同样的测试。