Linux上でSeleniumをPHP / Firefox3と連携させる方法
質問
PHPを使用するLinux上のFirefox 3で Selenium RC を使用しようとしています。 / Apacheが、問題が発生しています。これが私がやったことです:
- Firefox Selenium-IDE拡張機能をインストールしました。
- Webサーバー(私の場合は実際にはFirefoxを実行しているのと同じマシン)で、java -jar selenium-server.jar -interactiveを使用してSeleniumサーバーを起動しました
- 次のようなPHPスクリプトがあります:
PHP:
require_once 'Testing/Selenium.php';
$browser = new Testing_Selenium("*custom /usr/lib/firefox-3.0.3/firefox", "https://www.example.com");
$browser->start();
PHPスクリプトを実行すると、新しいFirefoxタブが起動しますが、このエラーメッセージが表示されます:
The requested URL /selenium-server/core/RemoteRunner.html was not found on this server.
Firefox 2で成功しました(" * custom"
の代わりに" * firefox"
を使用しましたが、これを使用したくない)現在のプロジェクト。
解決
あなた自身の質問に答えるエチケットについては確信がありません...しかし試行錯誤の方法で実験を行ったので、SeleniumをUbuntuでPHP / Firefox3と連携させる方法を以下に示します。
- RCをダウンロードし、phpクライアントディレクトリを/ usr / share / phpに「Selenium」としてコピーしました
- ダウンロードでSelenium Serverディレクトリに移動し、
java -jar selenium-server.jar
でseleniumを開始しました
- Firefox -ProfileManagerを実行して、新しいFirefoxプロファイルを作成しました。新しいプロファイルを「Selenium」と呼びました
- そのプロファイル内で、Firefoxネットワーク設定を編集して、localhostポート4444経由ですべてのプロトコルをプロキシします。
-
phpスクリプトを作成し、次のコマンドで実行しました:
php -d include_path ="。:/ usr / share / php:/ usr / share / php / Selenium / PEAR" test.php
参照用に、私の(基本、非PHPUnit、非OO)最初のテストスクリプトを以下にリストしました。
require_once 'Testing/Selenium.php';
$oSelenium = new Testing_Selenium(
"*custom /usr/lib/firefox-3.0.3/firefox -P Selenium",
"https://www.example.com");
$oSelenium->start();
$oSelenium->open("/");
if (!$oSelenium->isElementPresent("id=login_button")) {
$oSelenium->click("logout");
$oSelenium->waitForPageToLoad(10000);
if (!$oSelenium->isElementPresent("id=login_button")) {
echo "Failed to log out\n\n";
exit;
}
}
$oSelenium->type("login", "my_username");
$oSelenium->type("password", "my_password");
$oSelenium->click("login_button");
$oSelenium->waitForPageToLoad(10000);
$oSelenium->click("top_nav_campaigns");
$oSelenium->stop();
他のヒント
テストケースを実行するには、phpunit、selenium RC php apiを使用します。私のテストケースは
のように見えます
1235$Deepan@Newton~/selenium/ide_scripts$
cat mytest.php
'FF on linux',
'browser' => '*firefox',
'host' => '10.211.55.8',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'FF on windows',
'browser' => '*firefox',
'host' => '10.211.55.5',
'port' => 4444,
'timeout' => 30000,
),
*/
array(
'name' => 'Google Chrome on windows',
'browser' => '*googlechrome',
'host' => '10.211.55.5',
'port' => 4444,
'timeout' => 30000,
),
/*
array(
'name' => 'IE on windows',
'browser' => '*iexplore',
'host' => '10.211.55.5',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Safari on MacOS X',
'browser' => '*safari',
'host' => 'localhost',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Firefox on MacOS X',
'browser' => '*chrome',
'host' => 'localhost',
'port' => 4444,
'timeout' => 30000,
),
*/
array(
'name' => 'Google Chrome on MacOS X',
'browser' => '*googlechrome',
'host' => 'localhost',
'port' => 4444,
'timeout' => 30000,
)
);
protected function setUp()
{
//$this->setBrowser("*chrome");
$this->setBrowserUrl("http://www.facebook.com/");
}
public function testMyTestCase()
{
$this->open("/index.php?lh=94730c649368393b6954cb9fc0802e0a&eu=iKjrC7Q2aC-8tcU7PVLilg");
$this->type("email", "myemail@domain.com");
$this->type("pass", "mypassword");
$this->click("persistent");
$this->click("//input[@type='submit']");
$this->waitForPageToLoad("30000");
sleep(10);
$this->open("http://apps.facebook.com/myapp/");
sleep(4);
$this->click("link=Play");
$this->waitForPageToLoad("30000");
sleep(4);
$this->click("navAccountLink");
sleep(4);
$this->click("link=Logout");
$this->waitForPageToLoad("30000");
sleep(4);
}
}
?>
1332$Deepan@Newton~/selenium/ide_scripts$
phpunit mytest.php
これにより、仮想マシン内で実行されているブラウザに接続します
所属していません StackOverflow