Come far funzionare Selenium con PHP / Firefox3 su Linux
Domanda
Sto cercando di far Selenium RC lavorare con Firefox 3 su Linux con PHP / Apache ma sto riscontrando problemi. Ecco cosa ho fatto:
- Ho installato l'estensione Selenium-IDE di Firefox.
- Sul server Web (che nel mio caso è effettivamente la stessa macchina che esegue Firefox), ho avviato il server Selenium con: java -jar selenium-server.jar -interactive
- Ho uno script PHP come segue:
PHP:
require_once 'Testing/Selenium.php';
$browser = new Testing_Selenium("*custom /usr/lib/firefox-3.0.3/firefox", "https://www.example.com");
$browser->start();
Quando eseguo lo script PHP, viene avviata una nuova scheda Firefox, ma viene visualizzato questo messaggio di errore :
The requested URL /selenium-server/core/RemoteRunner.html was not found on this server.
Ho avuto più successo con Firefox 2 (usando " * firefox "
invece di " * custom "
ma non voglio usarlo per il mio progetto corrente.
Soluzione
Non sono sicuro dell'etichetta di rispondere alla tua domanda ... ma avendo sperimentato in modo da tentativi ed errori, ecco come sono riuscito a far funzionare Selenium con PHP / Firefox3 su Ubuntu.
- Ho scaricato RC e copiato la directory del client php in / usr / share / php come 'Selenium'
- Sono passato alla directory del server Selenium durante il download e ho avviato il selenio con
java -jar selenium-server.jar
- Ho creato un nuovo profilo Firefox (eseguendo firefox -ProfileManager). Ho chiamato il nuovo profilo "Selenium"
- All'interno di quel profilo, ho modificato le preferenze della rete Firefox per eseguire il proxy di tutti i protocolli tramite la porta 4444 dell'host locale.
-
Ho creato il mio script php e l'ho eseguito con questo comando:
php -d include_path = ".: / usr / share / php: / usr / share / php / Selenium / PEAR " test.php
Di seguito ho elencato il mio primo script di test (di base, non PHPUnit, non OO) come riferimento.
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();
Altri suggerimenti
Uso phpunit, selenium RC php api per eseguire i miei test. La mia testcase sembra
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
Questo si connetterà ai browser in esecuzione all'interno di macchine virtuali