php - Selenium 2 (WebDriver) 和 Phpunit?

标签 php selenium phpunit selenium-webdriver

有人知道如何将 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/

相关文章:

javascript - 如何让DataTable绘制新的结果?

javascript - 使用 Ajax 将 JavaScript 传递到 PHP

python - 使用selenium脚本测试URL,但浏览器打开后,它没有指向请求的URL

python - Selenium 抓取在前几个元素后返回空字符串

Phpunit 测试 Laravel Controller

php - Mockery 和 Laravel 构造函数注入(inject)

javascript - 需要 Dropdown 使用 AJAX 在我的页面上填写数据库信息

php - 查询后数据库未更新

css - XPATH 或 CSS I 我在 span 标签中有一个复选框列表。我正在尝试选择一个特定的复选框

php - 如何在 WebTestCase 上进行 JSON 请求