SeleniumRC つかってみた
データの大量登録とかは SeleniumIDE を使ったりとかしていたんですが、たとえば URL の id 部分だけ変えるとかだとちょっと面倒だなということで、 SeleniumRC と PHPUnit を使ってみました。
以下インストール手順。
SeleniumRCインストール
$ wget http://archiva.openqa.org/repository/releases/org/openqa/selenium/selenium-remote-control/1.0-beta-1/selenium-remote-control-1.0-beta-1-dist.zip $ unzip selenium-remote-control-1.0-beta-1-dist.zip $ cp selenium-remote-control-1.0-beta-1/selenium-server-1.0-beta-1/selenium-server.jar /usr/local/bin
Selenium のサーバ起動
$ java -jar /usr/local/bin/selenium-server.jar
PHPUnit_Extensions_SeleniumTestCase とかインストール
$ sudo pear install -a Testing_Selenium-beta $ sudo pear channel-discover pear.phpunit.de $ sudo pear install -a phpunit/PHPUnit
target_c_diary_id=40までの日記にコメントつけまくるスクリプトを書く。
<?php require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class test extends PHPUnit_Extensions_SeleniumTestCase { function setUp() { $this->setBrowser("*firefox"); $this->setBrowserUrl("http://example.com/"); } function testMyTestCase() { $this->open("/sns/210x/"); $this->type("username", "ebihara@example.com"); $this->type("password", "ebiebi"); $this->click("is_save"); $this->click("button_login"); $this->waitForPageToLoad("30000"); for ($i = 1; $i < 40; $i++) { $this->open("/sns/210x/?m=pc&a=page_fh_diary_comment_confirm&target_c_diary_id=" . $i . '&body=aaad'); $this->waitForPageToLoad("30000"); $this->click("//input[@value=' 書き込み ']"); $this->waitForPageToLoad("30000"); } } }
テストの実行
$ phpunit test.php
個人的には SeleniumIDE より断然こっちの方が好みだなと思うので、今後はこっちを使うよ(といっても、SeleniumIDEはSeleniumRC向けのテストも出力してくれるので併用とかはすると思うけどメインは完全にこっち)。
大量データの登録だけでなく、テストとかもこれで書きたい。