0

私はphpunitでseleniumを使用してWebのものの一部をテストしていますが、失敗したスクリーンショットでテストしているテキストを確認できても失敗するようです-私のテストは以下のとおりです

<?php
include('setupclass.php');
class AddNewPicStationTest extends setupclass
{


    protected function setUp()
    {
        parent::setUp();
    }

    public function testMyTestCase()
    {
        $this->open($this->apppath);
        $this->click("css=a > img");
        $this->waitForPageToLoad("30000");
        $this->type("name=username", "");
        $this->type("name=password", "");
        $this->click("name=submit");
        $this->waitForPageToLoad("30000");
        $this->click("link=ADD LIKESTATION");
        $this->waitForPageToLoad("30000");
        $this->click("link=HOME");
        $this->waitForPageToLoad("30000");
        $this->click("link=ADD PICSTATION");
        $this->waitForPageToLoad("30000");
        $this->type("id=title", "Test title 2");
        $this->type("id=message", "test description 2");
        $this->click("id=tip5");
        $this->type("id=album_title", "test album title 2");
        $this->type("id=album_description", "test album description 2");
        $this->click("//input[@value='Login']");
        $this->click("xpath=(//input[@name='group1'])[2]");
        $this->type("name=station_pic_upload", "C:\\Users\\chris laptop\\Desktop\\Logo.png");
        $this->click("name=g");
        $this->waitForPageToLoad("30000");

        **$this->assertTrue($this->isTextPresent("Test title 2"),"object created");**
        $this->assertFalse($this->isTextPresent("Error"),"Error is present");
        $this->assertFalse($this->isTextPresent("Profiler"),"PRofiler is running");

        $this->click("link=LOGOUT");
        $this->waitForPageToLoad("30000");
    }
}
?>

画面グラブにアスタリスク行が表示されていても失敗します。これは初めてです。助けていただければ幸いです。

これは、テストが探している以下の私のページです-ステーションタイトル

<table width="620px" align="left" style="text-align:left;">
        <tr style="font-weight:bold;background-color:#f1f1f1">
            <td colspan="5" STYLE="text-align:center;font-weight:bold">FACEBOOK PIC STATIONS</td>
        </tr>
        <tr style="font-weight:bold;background-color:#f1f1f1">
            <td width="15%">STATION ID</td>
            <td width="50%">STATION TITLE</td>
            <td width="10%">STATION STATS</td>
            <td width="15%">LAST POST</td>
            <td width="10%"></td>

        </tr>
        <?foreach($picstations->result() as $row){?>
            <tr>
                <td><?=anchor('socialmedia/edit_picstation/'.$row->station_id,$row->station_id);?> </td>
                <td><?=anchor('socialmedia/edit_picstation/'.$row->station_id,$row->title);?> </td>
                <td><?=anchor('stats/home/station_stats/'.$row->station_id,'STATS');?> </td>
                <td><?=$this->upd8r_date->get_last_post_from_station_time($row->station_id)?></td>
                <td><?=anchor('socialmedia/delete/'.$row->station_id,'delete');?></td>
            </tr>
        <?}?>
    </table>

そしてここに私のphpunit出力-

1) AddNewPicStationTest::testMyTestCase
Current URL: http://localhost/upd8r_new/socialmedia/add_picstation
Screenshot: http://localhost/upd8r_new/tests/screenshots/692eb179f8146d2a8491442
68dd2a99a.png

object created
Failed asserting that false is true.

C:\xampplite\php\phpunit:46

FAILURES!
Tests: 1, Assertions: 1, Errors: 1.
4

2 に答える 2

0

どのPHPバインディングを使用しているかはわかりませんが、通常は次のようにします(擬似コード)。

// if element is NOT present, try to wait a little more until timeout
var targetTime = currentTime() + 5000; // 5 seconds from now
while(currentTime() < targetTime) {
    if (!isElementPresent("someLocator")) {
        wait(250);
    } else {
        break;
    }
}

これは、要素が非同期で(AJAXを介して)ロードされる可能性が高く、それが発生してwaitForPageToLoad()いることを認識できないためです。それは単にページが常に完全にロードされていると考えています。バインディングに呼び出されたメソッドwaitForElementPresent()または類似のメソッドがあるかどうかを確認します。それ以外の場合は、上記の方法を実装します。

ちなみに、Selenium 2(WebDriver)には、これを自動的に行う暗黙の待機オプションがあります。要素が見つからない場合は、例外をスローする前に、指定された時間の間その要素を検索しようとします。


間違っている可能性があるもう1つのことは、検索されたテキストが実際には<iframe>要素に隠されていることです。その場合は、適切なフレームを選択する必要があります。

于 2012-04-30T11:01:36.107 に答える
0

いくつかのクロージャーを追加するだけです-この質問を見て同じ問題に苦しんでいる場合-私はWindows7でセレンとphpunitを使用しています。

変更waitForPageToload(1)しても何も起こらなかったのでsleep(1);、コードに追加しました。これにより、テストが正しく実行され、合格することができました。

于 2012-05-02T09:36:12.093 に答える