硒2(WebDriver)和Phpunit? [英] Selenium 2 (WebDriver) and Phpunit?
问题描述
有人知道如何将硒2与Phpunit一起使用吗? PHP中有Selenium 2示例吗?
Any one know how to use Selenium 2 with Phpunit? Are there any Selenium 2 samples in PHP?
推荐答案
快速更新: phpunit现在支持Selenium 2
Quick update: phpunit does now support Selenium 2
- https://phpunit.de/manual/3.6/en/selenium.html
- https://phpunit.de/manual/4.8/en/selenium.html
在撰写本文时,PHPUnit不支持Selenium 2.
At the time of writing, PHPUnit does not support Selenium 2.
来自
php-webdriver from facebook allows the complete WebDriver API to be called from PHP in an elegant way. To quote:
大多数客户端要求您首先阅读协议以了解内容 可能的话,然后研究客户本身以了解如何调用它.这 希望消除后面的步骤.
Most clients require you to first read the protocol to see what's possible, then study the client itself to see how to call it. This hopes to eliminate the latter step.
它用于启动Selenium 2服务器,该服务器提供位于localhost:4444/wd/hub
的接口.
It is used by starting up the Selenium 2 server, which provides the interface at localhost:4444/wd/hub
.
/usr/bin/java -jar /path/to/selenium-server-standalone-2.7.0.jar
然后运行PHP测试代码,该代码将调用该接口.例如:
then running the PHP test code, which calls that interface. For example:
<?php
require '/path/to/php-webdriver/__init__.php';
$webdriver = new WebDriver();
$session = $webdriver->session('opera', array());
$session->open("http://example.com");
$button = $session->element('id', 'my_button_id');
$button->click();
$session->close();
WebDriver API 映射到PHP方法,比较调用element
上,在文档中具有element/click API调用.
The WebDriver API is mapped to PHP methods, compare calling click
on element
in the example with the element/click API call in the documentation.
然后可以将测试代码包装在常规phpUnit测试中.
The test code can then be wrapped in regular phpUnit tests.
这不是本机phpUnit支持,但这是一种非常可靠的方法.
This is not native phpUnit support, but it's a quite robust approach.
这篇关于硒2(WebDriver)和Phpunit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!