适合初学者的 Selenium RC 和 PHP
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
启动 Selenium RC 非常简单(如果您已经有桌面环境),请确保安装了 JRE 并运行命令
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
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-)
我对 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.
您可以使用 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
尝试 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"
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.
我上周开始使用
Selenium IDE
进行测试,现在我将使用Selenium RC
。实际上你需要selenium-server-standalone
并且你需要用pear安装phpunit。查一下谷歌,有很好的教程。当
phpunit
准备就绪后,您需要在Selenium IDE
安装一个名为Selenium IDE PHP Formaters
的插件,然后您就可以继续>Selenium IDE->文件->导出
php (phpunit)中的文件。如果可以的话,您可以通过执行 : 从 cmd 控制台启动测试
,它会告诉您测试是否正常。
I started last week doing test with
Selenium IDE
and now i'm going toSelenium RC
. Actually you need theselenium-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 toSelenium IDE
which his namedSelenium IDE PHP Formaters
and then you can go onSelenium IDE->file->export
file in php (phpunit).When it's okay you can launch your test from your cmd consol by doing :
and it'll tell you if the test is ok or not.
我使用 phpQuery 来做这种事情,它是一个 jQuery 端口。
I use phpQuery for this kind of thing, it's a jQuery port.