2016-07-11 1 views
1

У меня есть тест поведения, который нажимает кнопку, которая обычно открывает URL-адрес на новой вкладке.обнаружить новую вкладку открыта с помощью behat и норки PHP

Я могу проверить, была ли открыта новая вкладка после нажатия кнопки?

это корнишоны:

Scenario: Open document in a new tab 
    Given I am a "Project Admin" for project "x" 
    And Project "x" has document type "orbitron" with editor "none" 
    And I create a new orbeon form "orbitron" for project "x" from fixture "OrbitronFilePicker.xhtml" 
    Then I visit the orbeon new content form for document type "orbitron" in project "x" 
    And I can see the "file-picker" control 
    When I enter a valid file picker reference "urn:isite:x:mickeyMouse" 
    Then I can see the card with "mickeyMouse" header 
    When I click "Open In New Tab" in the Dropdown Action Menu for "#section-1-control≡xf-383" 
    Then The document should open in a new tab 
+0

Вы пытались использовать метод/шаг, который переключится на th e новое окно? вызывается switchToWindow. – lauda

+0

У меня пока нет. Теперь я буду смотреть в switchToWindow (я очень новичок в BDD) – chinds

ответ

3

Вы можете попробовать что-то вроде этого:

/** 
* @When /^The document should open in a new tab$/ 
*/  
public function documentShouldOpenInNewTab() 
{ 
    $session  = $this->getSession(); 
    $windowNames = $session->getWindowNames(); 
    if(sizeof($windowNames) < 2){ 
     throw new \ErrorException("Expected to see at least 2 windows opened"); 
    } 

    //You can even switch to that window 
    $session->switchToWindow($windowNames[1]); 
} 

ПРИМЕЧАНИЕ: Возможно окна можно открыть с некоторой задержкой, и в этом случае вам нужно ждать это:

$ttw  = 40; 
    while ((sizeof($session->getWindowNames()) < 2 && $ttw > 0) == true) { 
     $session->wait(1000); 
     $ttw--; 
    } 
Смежные вопросы