Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

debugging - How to stop Behat tests in the middle to run element inspector?

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 # CWTestContextHelperContext::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 (WebDriverExceptionUnknownError)

Is there any better way of doing that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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, "33[s    33[93m[Breakpoint] Press 33[1;93m[RETURN]33[0;93m to continue...33[0m");
        while (fgets(STDIN, 1024) == '') {}
        fwrite(STDOUT, "33[u");
        return;
    }

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

As an alternative you could enable debugging in your IDE.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...