vccw-team / wordpress-extension
Behat 的 WordPress 扩展
1.2.4
2017-10-20 17:15 UTC
Requires
- behat/behat: ~3.2
- behat/mink: ~1.7
- behat/mink-extension: ~2.2
- behat/mink-goutte-driver: ^1.2
- behat/mink-selenium2-driver: ~1.3.1
Requires (Dev)
- phpspec/phpspec: ^3.1
This package is not auto-updated.
Last update: 2024-09-14 19:09:34 UTC
README
需求
- WordPress 4.6 或更高版本
- PHP 5.6 或更高版本
入门指南
安装依赖项
推荐的安装方法是使用 Composer。
$ composer require vccw-team/wordpress-extension:@stable
初始化 Behat
之后,您将能够初始化项目。
$ vendor/bin/behat --init
配置
将 behat.yml
放置如下。
default:
suites:
default:
paths:
- %paths.base%/features
contexts:
- FeatureContext
- VCCW\Behat\Mink\WordPressExtension\Context\WordPressContext
- Behat\MinkExtension\Context\MinkContext
extensions:
VCCW\Behat\Mink\WordPressExtension:
roles:
administrator:
username: admin
password: admin
editor:
username: editor
password: editor
Behat\MinkExtension:
base_url: http://127.0.0.1:8080
default_session: default
sessions:
default:
selenium2:
wd_host: http://127.0.0.1:4444/wd/hub
goutte:
goutte: ~
- 将您的 WordPress 网站的用户账户添加到
VCCW\Behat\Mink\WordPressExtension > roles
中。 - 将
Behat\MinkExtension > base_url
的值更新为您的主机名。 - 您可以像以下这样添加多个用户。
extensions:
VCCW\Behat\Mink\WordPressExtension:
roles:
administrator:
username: admin
password: admin
editor:
username: editor
password: editor
查看:https://github.com/vccw-team/wordpress-extension/blob/master/behat.yml.dist
编写功能
您可以使用 Gherkin 语言编写功能。
https://github.com/cucumber/cucumber/wiki/Gherkin
以下是一些 *.feature
示例。
https://github.com/vccw-team/wordpress-extension/tree/master/features
示例
以管理员角色登录,我应该看到“仪表盘”。
Feature: I login as the specfic role
Scenario: Login as the "administrator" role
When I login as the "administrator" role
Then I should see "Welcome to WordPress!"
Selenium2 驱动程序无法检索 HTTP 响应。因此,您必须在您的 *.feature
中使用类似以下的 @mink::goutte
标签。但是 goutte 驱动程序无法执行 JavaScript。
Feature: HTTP response
@mink:goutte
Scenario: Check http status code
When I am on "/"
Then the HTTP status should be 200
When I am on "/the-page-not-found"
Then the HTTP status should be 404
运行以查看上下文。
$ vendor/bin/behat -di --lang=en
安装无头浏览器
以下是一个 PhantomJS 的示例。
$ npm install phantomjs-prebuilt --save
$ node_modules/.bin/phantomjs --webdriver=4444 --ignore-ssl-errors=yes --cookies-file=/tmp/webdriver_cookie.txt
运行测试
$ vendor/bin/behat
作为 npm-scripts 运行测试
以下是一个自动运行 phantomjs 和测试的示例。
将其保存为 bin/run-tests.js
。
const phantomjs = require( 'phantomjs-prebuilt' )
const spawn = require( 'child_process' ).spawn
const argv = process.argv
argv.shift()
argv.shift()
phantomjs.run(
'--webdriver=4444',
'--ignore-ssl-errors=yes',
'--cookies-file=/tmp/webdriver_cookie.txt'
).then( program => {
const behat = spawn( 'vendor/bin/behat', argv, { stdio: "inherit" } )
behat.on( 'exit', ( code ) => {
program.kill()
process.exit( code );
} )
} )
将其添加到 package.json
中。
{
"scripts": {
"test": "/usr/bin/env node bin/run-tests.js"
},
}
然后只需运行
$ npm test