How to get Selenium working with PHP/Firefox3 on Linux

后端 未结 2 2041
青春惊慌失措
青春惊慌失措 2021-02-09 14:54

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
2条回答
  •  Happy的楠姐
    2021-02-09 15:11

    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();
    

提交回复
热议问题