Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vccw-team/wordpress-mink-extension
WordPress extension for the Behat
https://github.com/vccw-team/wordpress-mink-extension
behat mink phantomjs wordpress
Last synced: 3 days ago
JSON representation
WordPress extension for the Behat
- Host: GitHub
- URL: https://github.com/vccw-team/wordpress-mink-extension
- Owner: vccw-team
- License: mit
- Created: 2016-10-29T09:28:33.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-20T17:15:39.000Z (about 7 years ago)
- Last Synced: 2024-04-28T13:21:15.287Z (7 months ago)
- Topics: behat, mink, phantomjs, wordpress
- Language: PHP
- Size: 311 KB
- Stars: 12
- Watchers: 3
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# WordPress Extension for the Behat/Mink
[![Build Status](https://travis-ci.org/vccw-team/wordpress-mink-extension.svg?branch=master)](https://travis-ci.org/vccw-team/wordpress-mink-extension)
[![Latest Stable Version](https://poser.pugx.org/vccw-team/wordpress-extension/v/stable)](https://packagist.org/packages/vccw-team/wordpress-extension)
[![Total Downloads](https://poser.pugx.org/vccw-team/wordpress-extension/downloads)](https://packagist.org/packages/vccw-team/wordpress-extension)
[![Latest Unstable Version](https://poser.pugx.org/vccw-team/wordpress-extension/v/unstable)](https://packagist.org/packages/vccw-team/wordpress-extension)
[![License](https://poser.pugx.org/vccw-team/wordpress-extension/license)](https://packagist.org/packages/vccw-team/wordpress-extension)## Requires
* WordPress 4.6 or later
* PHP 5.6 or later## Getting Started
### Install dependencies
The recomended way to install is by using Composer.
```
$ composer require vccw-team/wordpress-extension:@stable
```### Initialize Behat
After that you will be able to initialize the project.
```
$ vendor/bin/behat --init
```### Configuration
Place the `behat.yml` like following.
```
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: ~```
* Add user accounts of your WordPress site into `VCCW\Behat\Mink\WordPressExtension > roles`.
* Update value of the `Behat\MinkExtension > base_url` to your hostname.
* You can add multiple user like following.```
extensions:
VCCW\Behat\Mink\WordPressExtension:
roles:
administrator:
username: admin
password: admin
editor:
username: editor
password: editor
```See:
https://github.com/vccw-team/wordpress-extension/blob/master/behat.yml.dist### Write features
You can write features with Gherkin language.
https://github.com/cucumber/cucumber/wiki/Gherkin
Example `*.feature` are in the following.
https://github.com/vccw-team/wordpress-extension/tree/master/features
#### Examples
Login as the administrator role and I should see "Dashboard".
```
Feature: I login as the specfic roleScenario: Login as the "administrator" role
When I login as the "administrator" role
Then I should see "Welcome to WordPress!"
```Selenium2 driver can't retrieve the HTTP response.
So you have to use `@mink::goutte` tag like following in your `*.feature`.
But goutte driver can't exec JavaScript.```
Feature: HTTP response@mink:goutte
Scenario: Check http status codeWhen I am on "/"
Then the HTTP status should be 200When I am on "/the-page-not-found"
Then the HTTP status should be 404
```Run to see contexts.
```
$ vendor/bin/behat -di --lang=en
```### Install headless browser
Following is an exmaple for PhantomJS.
```
$ npm install phantomjs-prebuilt --save
$ node_modules/.bin/phantomjs --webdriver=4444 --ignore-ssl-errors=yes --cookies-file=/tmp/webdriver_cookie.txt
```### Run tests
```
$ vendor/bin/behat
```### Running tests as npm-scripts
Following is an example to run phantomjs and tests automatically.
Save following as `bin/run-tests.js`.
```
const phantomjs = require( 'phantomjs-prebuilt' )
const spawn = require( 'child_process' ).spawnconst 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 );
} )
} )
```Add it to `package.json`.
```
{
"scripts": {
"test": "/usr/bin/env node bin/run-tests.js"
},
}
```Then just run:
```
$ npm test
```