phpunitセレンは、キャプチュクリーンショットンファイルを捕獲しませんか?
-
27-09-2019 - |
質問
私はPHPunit 3.4.12を使用して、セレンテストを駆動しています。テストが失敗したときに自動的にスクリーンショットを取得できるようにしたいと思います。これは、説明されているようにサポートする必要があります http://www.phpunit.de/manual/current/en/selenium.html#selenium.seleniumtestcase.examples.webtest2.php
class WebTest
{
protected $captureScreenshotOnFailure = true;
protected $screenshotPath = 'C:\selenium';
protected $screnshotUrl = 'http://localhost/screenshots';
public function testLandingPage($selenium)
{
$selenium->open("http://www.example.com");
$selenium->fail("fail");
...
}
}
ご覧のとおり、私はテストを失敗させています。理論的には、スクリーンショットを撮影してC:セレンに入れて、WindowsでSelenium RCサーバーを実行しているためです。
ただし、テストを実行すると、次のようになります。
[root@testbox selenium]$ sh run
PHPUnit 3.4.12 by Sebastian Bergmann.
F
Time: 8 seconds, Memory: 5.50Mb
There was 1 failure:
1) WebTest::testLandingPage
fail
/home/root/selenium/WebTest.php:32
FAILURES!
Tests: 1, Assertions: 0, Failures: 1.
C:セレンにスクリーンショットはありません。ただし、$ selenium-> capturescreenshot( "c:/selenium/image.png")でスクリーンショットを入手できます。
どんなアイデアや提案が大歓迎です。
ありがとう
解決
これのエラー処理は、phpunit側ではかなり貧弱です。すべてが完璧でない場合、警告なしに他のオプションを静かに無視します。
デイブが述べたように、変数のいずれかが間違っている場合、それは静かに機能しません。また、セットアップのインスタンスに割り当ててみることもできます。
また、すべての条件がスクリーンショットをトリガーするわけではありません。 $ selenium-> asserttextpresent( "foobarbaz")を$ selenium-> fail()の代わりに試してください。
他のヒント
これらのコードラインを追加してみてください
try { $this->assertTrue($this->isTextPresent("You searched for \"Brakes\" (2 matches)")); } catch (PHPUnit_Framework_AssertionFailedError $e) { array_push($this->verificationErrors, $e->toString()); $this->drivers[0]->captureEntirePageScreenshot($this->screenshotPath . DIRECTORY_SEPARATOR . rawurlencode($this->getLocation()) . '.png'); }
私はチュートリアルに従っていたので、最近このエラーがありました。
ドキュメントの最初の例は次のとおりです PHPUnit_Extensions_Selenium2TestCase
. 。ページ上の他のすべてが向けています PHPUnit_Extensions_SeleniumTestCase
.
おそらく変化します
extends PHPUnit_Extensions_Selenium2TestCase
に
extends PHPUnit_Extensions_SeleniumTestCase