如何在中间停止Behat测试以运行元素检查器?

时间:2017-07-31 19:11:23

标签: debugging webdriver selenium-chromedriver behat

我正在使用Chrome驱动程序,目前我正在测试中暂停浏览器:

And I ...
And I wait for 3600 seconds
And I ...

给出以下方法:

/**
 * @Given I wait for :number seconds
 */
public function iWaitForSeconds($number) {
  $this->getSession()->wait($number * 1000);
}

所以我可以自由地使用 DevTools 来检查我测试中特定位置的给定页面的对象。

问题是当打开 DevTools 时,脚本会因错误而停止:

And I wait for 3600 seconds # CWTest\Context\HelperContext::iWaitForSeconds()
  disconnected: not connected to DevTools
    (Session info: chrome=59.0.3071.115)
    (Driver info: chromedriver=2.31.488774,platform=Mac OS X 10.12.0 x86_64) (WARNING: The server did not provide any stacktrace information)
  Command duration or timeout: 605 milliseconds
  Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
  Driver info: org.openqa.selenium.chrome.ChromeDriver
  Session ID: d429c9a3fdac50fcaed852d9f094d535 (WebDriver\Exception\UnknownError)

有没有更好的方法呢?

3 个答案:

答案 0 :(得分:3)

您可以使用这样的断点:

    /**
     * adds a breakpoints
     * stops the execution until you hit enter in the console
     * @Then /^breakpoint/
     */
    public function breakpoint()
    {
        fwrite(STDOUT, "\033[s    \033[93m[Breakpoint] Press \033[1;93m[RETURN]\033[0;93m to continue...\033[0m");
        while (fgets(STDIN, 1024) == '') {}
        fwrite(STDOUT, "\033[u");
        return;
    }

您也可以将其声明为ClassName::breakpoint();

作为替代方案,您可以在IDE中启用调试。

答案 1 :(得分:0)

使用Behat step through extension,这是一个模块,可以让您轻松地逐步完成某个功能,而不必为其添加特定的代码。这是GitHub概述:

  

在调试特定方案时,请在CLI上使用dependencies { compile 'com.amazonaws:aws-java-sdk-s3' compile group: 'com.amazonaws', name: 'aws-java-sdk-polly', version: '1.11.67' 标志:

--step-through
  

每一步之后,您将看到消息

     

bin/behat --step-through features/my-failing-feature

     

Behat测试套件将一直处于暂停状态,直到收到回车符为止,以便您进行必要的检查。

答案 2 :(得分:-1)

我们可以为此使用 sleep 命令。

sleep(500);