如何在Linux上让Selenium与PHP/Firefox3一起使用 [英] How to get Selenium working with PHP/Firefox3 on Linux

查看:107
本文介绍了如何在Linux上让Selenium与PHP/Firefox3一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 Selenium RC 在具有PHP的Linux上使用Firefox 3/Apache,但是遇到了问题.这是我所做的:

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:

  • 我已经安装了Firefox Selenium-IDE扩展.
  • 在Web服务器(在我的情况下实际上是运行Firefox的同一台计算机)上,我使用以下命令启动了Selenium服务器:java -jar selenium-server.jar -interactive
  • 我有一个如下的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选项卡,但是我收到此错误消息:

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.

我在Firefox 2上获得了更大的成功(通过使用"*firefox"而不是"*custom",但是不想在我当前的项目中使用它.

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.

推荐答案

我不确定回答您自己的问题的礼节...但是经过反复试验,这就是我的做法设法让Selenium在Ubuntu上使用PHP/Firefox3.

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. 我下载了RC,并将php客户端目录复制为/Selenium到/usr/share/php.
  2. 我导航到下载中的Selenium Server目录,并使用java -jar selenium-server.jar
  3. 启动selenium.
  4. 我创建了一个新的Firefox配置文件(通过运行firefox -ProfileManager).我将新的配置文件称为硒"
  5. 在该配置文件中,我编辑Firefox Network首选项以通过本地主机端口4444代理所有协议.
  6. 我创建了我的php脚本并使用以下命令运行它:

  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

我在下面列出了我的(基本,非PHPUnit,非OO)第一个测试脚本,以供参考.

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

这篇关于如何在Linux上让Selenium与PHP/Firefox3一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆