适合初学者的 Selenium RC 和 PHP

发布于 2024-09-26 14:59:10 字数 1132 浏览 1 评论 0原文

我正在使用 apache/php/mysql 运行 ubuntu 服务器。我想在我的一个 php 项目中使用 selenium。基本上,我想要一个设置,我可以或多或少地将代码从 Firefox Selenium IDE(格式设置为 php)复制粘贴到我的 php 项目中,如下所示:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://www.google.com/");
  }

  public function testMyTestCase()
  {
    $this->type("q", "stack overflow");
    $this->click("link=2");
    $this->waitForPageToLoad("30000");
    $this->click("btnG");
    $this->waitForPageToLoad("30000");
    $this->type("q", "stack overflow php");
    $this->click("btnG");
    $this->waitForPageToLoad("30000");
  }
}
?>

我试图弄清楚如何使用 Selenium RC 在 PHP 中执行此操作,但文档令人困惑且过时。

我将非常感谢为初学者提供有关如何开始使用 PHP 和 Selenium RC 的说明。

非常感谢。

编辑:

感谢您的反馈。我已经在 Ubuntu/firefox 上启动并运行了 Selenium,很明显这不是我想要的。事实上,它运行一个 java 服务器并依赖于一个成熟的浏览器,这使得它变得非常轻量级。

如果有人知道类似的解决方案,只需加载 php 库即可与 dom/html 交互,请告诉我。

I am running a ubuntu server with apache/php/mysql. I want to use selenium on one of my php projects. Basically, I want a setup where I can more or less copy paste code from the Firefox Selenium IDE (format set to php) into my php project, like this:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://www.google.com/");
  }

  public function testMyTestCase()
  {
    $this->type("q", "stack overflow");
    $this->click("link=2");
    $this->waitForPageToLoad("30000");
    $this->click("btnG");
    $this->waitForPageToLoad("30000");
    $this->type("q", "stack overflow php");
    $this->click("btnG");
    $this->waitForPageToLoad("30000");
  }
}
?>

I have tried to figure out how to do this in PHP using Selenium RC, but the documentation is confusing and outdated.

I would be very grateful for instructions for beginners on how to get started with PHP and Selenium RC.

Thank you very much.

EDIT:

Thanks for the feedback. I have got Selenium up and running on Ubuntu/firefox and it is obvious that this is not what I am looking for. The fact that it runs a java server and is dependent on a full blown browser makes it anything than lightweight.

If anyone knows a similar solution where you can just load a php library to interact with dom/html, please tell me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

南风几经秋 2024-10-03 14:59:11

启动 Selenium RC 非常简单(如果您已经有桌面环境),请确保安装了 JRE 并运行命令

java -jar selenium-server.jar

Selenium RC 将在 localhost(端口 4444)侦听,并且您可以使用 PHP 客户端(Pear ), 例如。

顺便说一句,Testing_Selenium(Pear) 客户端已经过时,例如不支持 HTTP POST,您可能有兴趣修补它 (http://github.com/tszming/Testing_Selenium--Patch-)

Starting up Selenium RC is quite straight forward (if you already have a desktop environment), make sure you have JRE installed and run the command

java -jar selenium-server.jar

Selenium RC will listen at localhost(port 4444), and you can connect it using the PHP client (Pear), for example.

By the way, the Testing_Selenium(Pear) client is outdated, e.g. does not support HTTP POST, you might be interested in patching it (http://github.com/tszming/Testing_Selenium--Patch-)

绅士风度i 2024-10-03 14:59:11

我对 Selenium 的了解不多,但我的理解是,如果您只有 Selenium IDE,那么除了在浏览器中运行它之外没有其他办法 - 不同的语言输出本质上是不相关的。

如果您想将 Selenium 合并到任何语言的程序中,您需要 Selenium RC。

I haven't done much with Selenium, but my understanding is that if you only have Selenium IDE, there is no way to do more than run it in your browser - the different language outputs are essentially irrelevant.

If you want to incorporate Selenium into your program, in any language, you need Selenium RC.

迷离° 2024-10-03 14:59:11

您可以使用 SauceLabs onDemand 使用 PHP 进行 Selenium 测试。而且您不必自己设置 Selenium RC。如果您想查看的话,他们有 30 天的免费试用期。

http://saucelabs.com/ondemand

You could use SauceLabs onDemand for Selenium testing using PHP. And you won't have to setup Selenium RC yourself. They have a 30-day free trial if you want to check it out.

http://saucelabs.com/ondemand

不疑不惑不回忆 2024-10-03 14:59:11

尝试 simpletest webtester:

它是一个非常简单的库,适合您的“类似解决方案,您只需加载 php 库即可与 dom/html 交互”的要求

Try simpletest webtester:

Its a very simple library which fits your requirements of "similar solution where you can just load a php library to interact with dom/html"

动次打次papapa 2024-10-03 14:59:11

Selenium RC 服务器已弃用且已过时。 selenium webdriver 是您所需要的,但正如您提到的,它需要有服务器侦听,并且可能会消耗资源。在 Nearsoft,我们创建了一个库来通过 JSON Wire 协议与 Web 服务器交互,但我们的目标是使其与 selenium 网站上的示例尽可能相似,因此 Java 中的任何示例在 PHP 中都将具有非常相似的语法。
这是链接,希望有帮助: https://github.com/Nearsoft/PHP-SeleniumClient

如果你喜欢它,分享它,参与其中,分叉它或做你想做的事:)

问候,马克。

Selenium RC Server is deprecated and out of date. The selenium webdriver is the one that you need but as you mention it requires to have a server listening and could be resources consuming. At Nearsoft, we created a library to interact with the web server via the JSON Wire protocol but we aimed to make it as similar as possible with the examples from selenium website so any example in Java would have a very similar syntax in PHP.
Here's the link, hope it helps: https://github.com/Nearsoft/PHP-SeleniumClient

If you like it, share it, get involved, fork it or do as you please :)

Regards, Mark.

烙印 2024-10-03 14:59:11

我上周开始使用 Selenium IDE 进行测试,现在我将使用 Selenium RC。实际上你需要selenium-server-standalone并且你需要用pear安装phpunit。查一下谷歌,有很好的教程。

phpunit 准备就绪后,您需要在 Selenium IDE 安装一个名为 Selenium IDE PHP Formaters 的插件,然后您就可以继续>Selenium IDE->文件->导出 php (phpunit)中的文件。

如果可以的话,您可以通过执行 : 从 cmd 控制台启动测试

phpunit c:\path\to\myfile.php

,它会告诉您测试是否正常。

I started last week doing test with Selenium IDE and now i'm going to Selenium RC. Actually you need the selenium-server-standalone and you need to install phpunit with pear. Check on Google there are good tutorials.

When phpunit is ready, you need to install a plugin to Selenium IDE which his named Selenium IDE PHP Formaters and then you can go on Selenium IDE->file->export file in php (phpunit).

When it's okay you can launch your test from your cmd consol by doing :

phpunit c:\path\to\myfile.php

and it'll tell you if the test is ok or not.

思念绕指尖 2024-10-03 14:59:11

我使用 phpQuery 来做这种事情,它是一个 jQuery 端口。

I use phpQuery for this kind of thing, it's a jQuery port.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文