2017-03-06 56 views
0

我使用Selenium/FacebookWebdriver使用Codeception測試一個簡單流程,其中彈出窗口在最後關閉 - 導致整個測試中斷。Codeception - 關閉彈出突破selemium test

代碼已完成(測試將運行)並將重現錯誤。 我真的很絕望,任何建議將非常感激。

這些都是錯誤的,我得到:

Codeception錯誤消息: [Facebook\WebDriver\Exception\NoSuchWindowException] Window not found. The browser window may have been closed.

硒服務器輸出消息: WARN - Exception: Window not found. The browser window may have been closed.

此代碼重新產生問題。它由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'); 
    } 

} 

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> 

感謝你的幫助, 托馬斯

回答

0

測試代碼似乎是正確的,我懷疑問題是有關過時的版本或可能的Firefox驅動程序。

我用chrome + chromedriver測試了你的代碼,它看起來沒有問題。這裏有一個測試回購說明如何使用chromedriver +所需的配置更改:https://github.com/henrikauppinen/codeception-popup-chromedriver

通常我會建議使用Chrome進行此類型的測試,除非您專門測試Firefox或者它是需求。

+0

謝謝亨利,抽空幫忙。它確實似乎是舊版Firefox的一個問題。我在ubuntu 14.04上將Mozilla Firefox 44.0.2與selenium-server-standalone-2.53.1.jar和xvfb結合使用。同樣的測試現在可以使用鉻合金和鉻合金。 – tomolas