uuf6429 / behat-breakpoint
✋ 提供多种中断/阻止场景的方法。
v1.0.0
2018-10-28 01:03 UTC
Requires
- php: ^5.6 || ^7.0
- ext-json: *
- behat/behat: ^3.0
Requires (Dev)
- behat/mink-extension: ^2
- behat/mink-selenium2-driver: ^1.3
- crodas/phpunit-compat: ^1
- dg/bypass-finals: ^1.1
- phpdocumentor/reflection-docblock: ^3 || ^4
- phpunit/phpunit: ^5 || ^6 || ^7
- symfony/process: ^3.4
Suggests
- ext-xdebug: Required for Xdebug breakpoints.
This package is auto-updated.
Last update: 2024-08-29 04:20:14 UTC
README
✋ 在 Behat 中提供多种中断/阻止场景的方法。
安装
- 使用 Composer 在您的 Behat 项目中安装
composer require uuf6429/behat-breakpoint
- (可选) 安装上下文(在您的
behat.yml
中),以便您可以在测试中使用它default: extensions: Behat\MinkExtension: # ... suites: default: paths: features: "%paths.base%/features/" contexts: - Behat\MinkExtension\Context\MinkContext # ... - uuf6429\BehatBreakpoint\Context # <-- just add this line # ...
要求
您可以在 composer.json 中查看具体要求,但 PHP 5.6+ 和 Behat 3.0+ 总是必需的。此外,每种类型的断点都有特定的要求。
AlertBreakpoint
:需要 instaclick/php-webdriver(它是 behat/mink-selenium2-driver 的一部分)。ConsoleBreakpoint
:无。PopupBreakpoint
:需要 behat/mink(它是 behat/mink-extension 的一部分)。XdebugBreakpoint
:需要安装并启用 ext-xdebug。
上述任何包都不会自动安装;因为有人可能希望使用 Xdebug 扩展而无需 Mink(反之亦然)。
用法
在代码中
从以下列出的断点中构造所需的断点并调用 trigger()
。
- AlertBreakpoint - 在指定的浏览器会话中显示一个 JavaScript 警告,并等待它关闭。
new \uuf6429\BehatBreakpoint\Breakpoint\AlertBreakpoint( \Session $session, // The WebDriver session to work with. string $message = NULL // (Optional) A message to show to the operator. )
- ConsoleBreakpoint - 在当前终端显示一条消息,并等待按 [enter] 键。
new \uuf6429\BehatBreakpoint\Breakpoint\ConsoleBreakpoint( string $message = NULL, // (Optional) A message to show to the operator. null|resource $output = NULL, // (Optional) Output handle (defaults to PHP's STDOUT) null|resource $input = NULL // (Optional) Input handle (defaults to PHP's STDIN) )
- PopupBreakpoint - 显示一个带有一些 HTML 的新窗口,并等待用户关闭。
new \uuf6429\BehatBreakpoint\Breakpoint\PopupBreakpoint( \Session $session, // The Mink session to work with. It must support javascript. string $popupHtml, // The HTML of the popup page *body*. int $popupWidth = 500, // (Optional) The popup's default width. int $popupHeight = 300, // (Optional) The popup's default height. bool $popupIsScrollable = false, // (Optional) Enables scrollbars (and scrolling) within the popup. bool $popupIsResizeable = false // (Optional) Allows the popup to be resizeable. )
- XdebugBreakpoint - 暂停执行,直到连接的 xdebug 客户端恢复执行。
new \uuf6429\BehatBreakpoint\Breakpoint\XdebugBreakpoint()
在 Gherkin 中
首先将上下文添加到您的 behat 项目配置(behat.yml
)中,然后在您的功能文件中使用以下任何步骤
- 在当前打开的页面中显示一个 JavaScript 警告,并在它关闭之前暂停执行。定义
Given an alert breakpoint is triggered(?: with message "(?P<message>[^"]*)")? Then an alert breakpoint is triggered(?: with message "(?P<message>[^"]*)")? When an alert breakpoint is triggered(?: with message "(?P<message>[^"]*)")?
示例Then a console breakpoint is triggered with message "Breakpoint reached! Press [OK] to continue..."
- 在 Behat 控制台中显示一条消息,并在用户按下 "enter" 键之前等待继续执行。定义
Given a console breakpoint is triggered(?: with message "(?P<message>[^"]*)")? Then a console breakpoint is triggered(?: with message "(?P<message>[^"]*)")? When a console breakpoint is triggered(?: with message "(?P<message>[^"]*)")?
示例Then a console breakpoint is triggered with message "Breakpoint reached! Press [Enter] to continue..."
- 显示一个带有一些 HTML 的浏览器弹出窗口,并在用户关闭之前暂停执行。定义
Given a(?: (?P<width>\d+)x(?P<height>\d+))? popup breakpoint is triggered with the following content: Then a(?: (?P<width>\d+)x(?P<height>\d+))? popup breakpoint is triggered with the following content: When a(?: (?P<width>\d+)x(?P<height>\d+))? popup breakpoint is triggered with the following content:
示例Then a 300x200 popup breakpoint is triggered with the following content: """ <h1>Hello world</h1> """
- 使任何连接的 xdebug 会话中断到调试会话,并暂停执行。定义
Given an xdebug breakpoint is triggered Then an xdebug breakpoint is triggered When an xdebug breakpoint is triggered
示例Then an xdebug breakpoint is triggered