etsy / pigeon-webkit
此包最新版本(0.1.5)没有可用的许可证信息。
0.1.5
2016-04-04 23:55 UTC
Requires
- php: >=5.3
- behat/mink: 1.5.*@stable
Requires (Dev)
- crysalead/kahlan: ^2.4
This package is not auto-updated.
Last update: 2024-09-11 12:55:32 UTC
README
基于capybara-webkit构建的PHP功能测试工具
安装
以下说明使用Composer进行安装。如果您没有Composer,可以从中下载 https://getcomposer.org.cn/
- 按照以下[说明]安装QT (https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit)。
- 安装capybara-webkit
$ gem install capybara-webkit -v "1.8.0"
或者
$ sudo gem install capybara-webkit -v "1.8.0"
- 运行以下命令
$ php composer.phar global require etsy/pigeon-webkit:dev-master
如何工作
capybara-webkit提供了一个基于QT Webkit的无头浏览器。当浏览器启动时,它会打开一个端口以接受命令。Pigeon Webkit启动浏览器,打开一个TCP连接到该端口并向浏览器发送命令以“驾驶”它并运行断言。
FunctionalPigeon扩展了CapybaraWebkitDriver,这是Behat Mink的[DriverInterface]的实现。因此,接口定义的大部分方法都是可用的。未实现的方法会抛出UnsupportedException异常。
CSS到XPath的转换由[Symfony CssSelector组件]处理 (https://symfony.ac.cn/doc/current/components/css_selector.html)
使用方法
$pigeon = new PigeonWebkit\FunctionalPigeon(); $pigeon->visit("https://etsy.com"); print_r($pigeon->body()); // HTML content of etsy.com $pigeon->click("a#sign-in"); // opens the sign in modal // ...etc
默认情况下,Pigeon Webkit接受CSS选择器。但它还有一个XPath模式。
$pigeon->setXPathMode(true); $pigeon->visit("https://etsy.com"); $pigeon->click("//a[@id='sign-in']");
使用[kahlan]测试框架的示例用法 (https://github.com/crysalead/kahlan)
<?php use PigeonWebkit\FunctionalPigeon; describe("Visiting a URL", function() { before(function() { $this->p = new FunctionalPigeon(); }); it("loads the page", function() { $this->p->visit("https://etsy.com"); expect($this->p->body())->toContain("Shop directly from people around the world."); }); });
更多示例,请参阅FunctionalPigeon及其基类CapybaraWebkiDriver的规范。
一些可用方法
reset
visit
getCurrentUrl
reload
forward
back
setRequestHeader
getResponseHeaders
setCookie
getCookie
getStatusCode
getContent
find
getTagName
getText
getHtml
getOuterHtml
getAttribute
getValue
setValue
check
uncheck
isChecked
selectOption
isSelected
submitForm
click
isVisible
executeScript
evaluateScript
getScreenshot