我试图让Selenium RC使用PHP / Apache在Linux上使用Firefox 3,但遇到了问题。这就是我所做的:
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上取得了更大的成功(使用"*firefox"
代替"*custom"
,但不想将其用于我当前的项目。
答案 0 :(得分:12)
我不确定回答你自己的问题的礼仪......但是经过试错法的尝试,这就是我如何让Selenium在Ubuntu上使用PHP / Firefox3。
java -jar selenium-server.jar
我创建了我的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();
答案 1 :(得分:1)
我使用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
这将连接到虚拟机内运行的浏览器