php - How can I write a Behat step that will capture a screenshot or HTML page? -
ideally opening screenshot automatically in image viewer.
edit: bishop tip on opening apps. still not sure how windows, though.
/** * works selenium , other real browsers support screenshots. * * @then /^show me screenshot$/ */ public function show_me_a_screenshot() { $image_data = $this->getsession()->getdriver()->getscreenshot(); $file_and_path = '/tmp/behat_screenshot.jpg'; file_put_contents($file_and_path, $image_data); if (php_os === "darwin" && php_sapi === "cli") { exec('open -a "preview.app" ' . $file_and_path); } } /** * works goutte driver , assume other html-only ones. * * @then /^show me html page$/ */ public function show_me_the_html_page_in_the_browser() { $html_data = $this->getsession()->getdriver()->getcontent(); $file_and_path = '/tmp/behat_page.html'; file_put_contents($file_and_path, $html_data); if (php_os === "darwin" && php_sapi === "cli") { exec('open -a "safari.app" ' . $file_and_path); }; }
Comments
Post a Comment