Codeception-封闭的弹出窗口打破了硒测试 [英] Codeception - closed popup breaks selemium test

查看:97
本文介绍了Codeception-封闭的弹出窗口打破了硒测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Selenium / FacebookWebdriver的Codeception测试一个简单的流程,其中最后一个弹出窗口被关闭-导致整个测试中断。

I'm testing a simple flow using Codeception with Selenium/FacebookWebdriver where a popup window gets closed at the end - causing entire test to break.

代码是完成(测试将运行)并将重现该错误。
我真的很绝望,任何建议将不胜感激。

The code is complete (the test will run) and will reproduce the error. I'm really desperate here, any suggestions will be very much appreciated.

这些是我得到的错误:

代码接收错误消息:
[Facebook\WebDriver\Exception\NoSuchWindowException]
找不到窗口。浏览器窗口可能已关闭。

硒服务器输出消息:
WARN-例外:窗口未找到。浏览器窗口可能已关闭。

此代码重现了该问题。
它包含3个.html文件(main.html,intermediate.html,popup.html),测试文件(PopupCest.php)和配置文件(selenium.suite.yml)。

This code reproduces the problem. It consits of 3 .html files (main.html, intermediate.html, popup.html), test file (PopupCest.php) and configuration file (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');
    }

}

selenium.suite。 yml

class_name: SeleniumTester
modules:
  enabled:
    - WebDriver:
        url: http://localhost
        browser: firefox
    - \Helper\Selenium

main.html

<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>

intermediate.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>

popup.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>

感谢您的帮助,
Tomas

Thank you for your help, Tomas

推荐答案

测试代码似乎正确,我怀疑问题与过时的版本或可能与Firefox驱动程序有关。

Test code seems to be correct, I suspect that problem is related to outdated versions or possibly Firefox driver.

我使用chrome + chromedriver测试了您的代码,它似乎可以正常工作。这是一个测试回购,其中包含有关如何使用chromedriver和必需的配置更改的说明: https://github.com / henrikauppinen / codeception-popup-chromedriver

I tested your code with chrome+chromedriver and it seems to work without problem. Here's a test repo with instructions how to use chromedriver + required config changes: https://github.com/henrikauppinen/codeception-popup-chromedriver

通常我建议使用Chrome进行此类测试,除非您专门测试Firefox或要求。

Generally I'd advise to use Chrome for this type of testing, unless you are testing Firefox specifically or if it's a requirement.

这篇关于Codeception-封闭的弹出窗口打破了硒测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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