4

セレンテストを実行するために 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:\selenium に配置する必要があります。これは、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 にスクリーンショットがありません。ただし、 $selenium->captureScreenshot("C:/selenium/image.png"); でスクリーンショットを取得できます。

アイデアや提案は大歓迎です。

ありがとう

4

3 に答える 3

2

これらのコード行を追加してみてください

    試す {
        $ this-> assertTrue($ this-> isTextPresent( "あなたは\"ブレーキ\"を検索しました(2件の一致)"));
    } catch(PHPUnit_Framework_AssertionFailedError $ e){
        array_push($ this-> verificationErrors、$ e-> toString());
        $ this-> drivers [0]-> captionEntirePageScreenshot($ this->screenshotPath。DIRECTORY_SEPARATOR。rawurlencode($ this-> getLocation())。'.png');
    }

于 2010-05-29T02:35:26.460 に答える
2

これのエラー処理は、phpunit 側ではかなり貧弱です。すべてが完璧でない場合、警告なしに他のオプションを黙って無視します。

Dave が述べたように、変数のいずれかのスペルが間違っていると、暗黙のうちに機能しなくなります。セットアップ内のインスタンスに変数を割り当ててみることもできます。

また、すべての条件がスクリーンショットをトリガーするわけではありません。健全性チェックのために、$selenium->fail() の代わりに $selenium->assertTextPresent("foobarbaz") を試してください。

于 2010-05-24T20:22:57.950 に答える