Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Selenium working with PHP/Firefox3 on Linux

I am trying to get Selenium RC working with Firefox 3 on Linux with PHP/Apache but am experiencing problems. Here's what I've done:

  • I have installed the Firefox Selenium-IDE extension.
  • On the web server (which in my case is actually the same machine running Firefox), I've started the Selenium server with: java -jar selenium-server.jar -interactive
  • I have a PHP script as follows:

PHP:

require_once 'Testing/Selenium.php';

$browser = new Testing_Selenium("*custom /usr/lib/firefox-3.0.3/firefox", "https://www.example.com");
$browser->start();

When I run the PHP script, it does launch a new Firefox tab, but I get this error message:

The requested URL /selenium-server/core/RemoteRunner.html was not found on this server.

I have had more success with Firefox 2 (by using "*firefox" instead of "*custom" but don't want to use that for my current project.

like image 378
Peter Howe Avatar asked Oct 03 '08 13:10

Peter Howe


People also ask

How do I run Selenium in Firefox?

Step 1: Navigate to the official Selenium website. Under third-party drivers, one will find all the drivers. Just click on the Mozilla GeckoDriver documentation as shown below. Now, it will navigate to the GeckoDriver downloads link, where one can download the suitable driver based on the OS as it is platform agnostic.

Which version of Firefox is compatible with Selenium?

Selenium users must update to version 3.11 or later to use geckodriver. Other clients that follow the W3C WebDriver specification are also supported.

Can I run Selenium without GUI?

We can run Selenium (Firefox) webdriver without a GUI. This means that the execution has to be kicked in headless mode. The headless execution is popular now since it results in less consumption of resources.


2 Answers

I'm not sure of the etiquette of answering your own question... but having experimented in a trial-and-error way, here's how I've managed to get Selenium working with PHP/Firefox3 on Ubuntu.

  1. I downloaded RC and copied the php client directory to /usr/share/php as 'Selenium'
  2. I navigated to the Selenium Server directory in the download, and started selenium with java -jar selenium-server.jar
  3. I created a new Firefox profile (by running firefox -ProfileManager). I called the new Profile 'Selenium'
  4. Within that profile, I editing the Firefox Network preferences to proxy all protocols via localhost port 4444.
  5. I created my php script and ran it with this command:

    php -d include_path=".:/usr/share/php:/usr/share/php/Selenium/PEAR" test.php

I've listed my (basic, non-PHPUnit, non-OO) first test script below for reference.

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();
like image 127
Peter Howe Avatar answered Sep 18 '22 02:09

Peter Howe


I use phpunit, selenium RC php api to run my testcases. My testcase looks like



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", "[email protected]");
    $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

This will connect to browsers running inside virtual machines

like image 40
Deepan Chakravarthy Avatar answered Sep 20 '22 02:09

Deepan Chakravarthy