gpt4 book ai didi

php - 使用 behat 和 mink PHP 检测新标签打开

转载 作者:行者123 更新时间:2023-12-05 01:46:01 26 4
gpt4 key购买 nike

我有一个 behat 测试,点击一个按钮通常会在新选项卡中打开一个 url。

我可以测试点击按钮后是否打开了一个新标签页吗?

这是小 cucumber :

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

最佳答案

你可以尝试这样的事情:

/**
* @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]);
}

注意:Windows 可能会延迟打开,在这种情况下您需要等待:

    $ttw     = 40;
while ((sizeof($session->getWindowNames()) < 2 && $ttw > 0) == true) {
$session->wait(1000);
$ttw--;
}

关于php - 使用 behat 和 mink PHP 检测新标签打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38302920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com