dalailomo / behato
使用 behat 的快速 QA 工具
dev-master
2017-08-18 16:04 UTC
Requires
- php: >=5.6
- behat/behat: ^3.3
- behat/mink-extension: ^2.2
- behat/mink-goutte-driver: ^1.2
- behat/mink-selenium2-driver: ^1.3
- devinci/devinci-behat-extension: dev-master
- react/child-process: dev-master
This package is not auto-updated.
Last update: 2024-09-18 21:15:16 UTC
README
使用 behat 和 vvo/selenium-standalone 的快速行为测试工具。
要求
- PHP >= 5.6
- NodeJS >= 7.10
安装
创建一个 composer.json 文件,内容如下
{ "config": { "bin-dir": "bin/" }, "minimum-stability": "dev", "require": { "dalailomo/behato": "dev-master" } }
所需依赖
$ composer install
然后,安装 selenium 服务器
$ bin/installSeleniumStandalone
在项目的根目录下创建一个名为 behat.yml 的配置文件,内容如下
# behat.yml default: suites: default: contexts: - BaseContext - Devinci\DevinciExtension\Context\DebugContext: asset_dump_path: '<THE PATH YOU WANT TO DUMP ASSETS>' - Devinci\DevinciExtension\Context\JavascriptContext: maximum_wait: 30 extensions: Behat\MinkExtension: base_url: '<THE BASE URL YOU WANT>' browser_name: chrome sessions: default: #goutte: ~ selenium2: ~
然后运行 bin/behat --init
测试示例
在配置文件中设置参数
- 将 asset_dump_path 键更改为 %paths.base%/asset(确保在项目的根路径上创建一个名为 asset 的目录)。
- 将 base_url 键更改为 http://wikipedia.org
创建一个功能文件
现在,在 features 文件夹下创建一个名为 search.feature 的文件(这已在运行 bin/behat --init 时创建)。
Feature: Search In order to see a word definition As a website user I need to be able to search for a word Scenario: Searching for a page that does exist Given I am on "/wiki/Main_Page" When I fill in "search" with "Behavior Driven Development" And I press "searchButton" Then I should see "agile software development" Scenario: Searching for a page that does NOT exist Given I am on "/wiki/Main_Page" When I fill in "search" with "Glory Driven Development" And I press "searchButton" Then I should see "Search results"
现在,打开文件 features/bootstrap/BaseContext.php 并将其内容更改为以下内容
<?php use Behat\MinkExtension\Context\MinkContext; /** * Defines application features from the specific context. */ class BaseContext extends MinkContext { /** * Initializes context. * * Every scenario gets its own context instance. * You can also pass arbitrary arguments to the * context constructor through behat.yml. */ public function __construct() { } }
现在,在另一个控制台中运行服务器
$ bin/runServer
然后运行测试!
$ bin/behat
如果某个步骤失败,你将在 asset/ 文件夹内看到一个截图和失败步骤的 HTML 输出。非常实用,不是吗?