有人知道如何将 Selenium 2 与 Phpunit 一起使用吗? PHP 中有 Selenium 2 示例吗?
最佳答案
快速更新:phpunit 现在支持 Selenium 2
在撰写本文时,PHPUnit 不支持 Selenium 2。
php-webdriver来自 facebook允许以优雅的方式从 PHP 调用完整的 WebDriver API。引用:
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
提供接口(interface)。
/usr/bin/java -jar /path/to/selenium-server-standalone-2.7.0.jar
然后运行调用该接口(interface)的 PHP 测试代码。例如:
<?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
的调用 click
与文档中的 element/click API 调用进行比较。
然后可以将测试代码包装在常规的 phpUnit 测试中。
这不是 native phpUnit 支持,但它是一种非常可靠的方法。
关于php - Selenium 2 (WebDriver) 和 Phpunit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4206547/