How to stop Behat tests in the middle to run eleme

2019-03-05 00:05发布

I'm using Chrome driver and currently to pause the browser in the middle of the tests I do:

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

given the following method:

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

so I can freely use DevTools to inspect the objects of the given page at specific place in my tests.

The problem is that when opening DevTools, the script stops with error:

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)

Is there any better way of doing that?

2条回答
虎瘦雄心在
2楼-- · 2019-03-05 00:25

Use Behat step through extension which is a module that will allow you to easily to step through a certain feature without having to add specific code for it. This is the GitHub overview:

When debugging a particular scenario, use the --step-through flag at the CLI:

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

After each step you will see the message

[Paused after "<step text>" - press enter to continue]

The Behat test suite will stay in this suspended state until a carriage return is received, to allow you to do any inspections necessary.

查看更多
The star\"
3楼-- · 2019-03-05 00:33

You can use a breakpoint like this:

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

You can also declare it static an call it like ClassName::breakpoint();

As an alternative you could enable debugging in your IDE.

查看更多
登录 后发表回答