webforge/behat-css-extension

Behat 测试中用于 CSS 选择器的辅助工具

v3.1.0 2022-05-27 18:42 UTC

This package is auto-updated.

Last update: 2024-08-27 23:44:23 UTC


README

(还不是扩展,但可用)
它扩展了 Mink 扩展,使其成为实际的、可链式使用的 CSS 表达式

你需要

  • behat
  • behat/mink-extension
  • behat/mink-selenium2-driver
  • symfony/css-selector
  • hamcrestphp

安装

compose require --dev webforge/behat-css-extension

你需要安装(除了你的正常 Behat 设置外)

"behat/behat": "^3.5",
"behat/mink-extension": "^2.3",
"behat/mink-selenium2-driver": "^1.3",

在你的 dev-dependencies 中使用这些依赖。

用法

在你的 BehatFeatureContext 中使用

use Behat\MinkExtension\Context\MinkContext;
use Behat\Behat\Context\Context;
use Webforge\Behat\CssUtilitiesTrait;

class MyFeatureContext extends MinkContext implements Context
{
    use CssUtilitiesTrait;

    /**
     * @Given /^I wait for the page to load$/
     */
    public function iWaitForThePageToLoad()
    {
        $this->context = $this->css('.v-dialog--active')->exists();
        $this->context('.container .headline:contains("Wähle dein Fotobuch-Format")')->waitForVisible(5000);
    }


   /**
     * @When /^I click on the position button$/
     */
    public function iClickOnThePositionButton()
    {
        $this->css('.v-btn:contains("Position")')->exists()->click();
    }

    /**
     * @Given /^I click on the undock headline icon$/
     */
    public function iClickOnTheUndockHeadlineIcon()
    {
        $this->context('.v-btn:contains("Überschrift ablösen")')->exists()->click();
    }
    
    /**
     * @Given /^the headline is displayed in text$/
     */
    public function theHeadlineIsDisplayedInText()
    {
        $this->css('.pb-container.headline')->waitForExist() // selector is:  .pb-container.headline
            ->css('.headline.visible')->notExists()->end() // selector is: .pb-container.headline .headline.visible 
            ->css('.headline h1')->isNotVisible(); // selector is now: .pb-container.headline .headline h1 
    }
}
  • 使用 $this->css($selector) 从文档开始,$selector 是一个有效的 CSS3 选择器(由 symfony/css-selector 支持)
  • 将 $this->context 设置为你想要选择元素的对话框/页面/子区域
  • 使用 $this->context() 从上下文开始
  • 使用 $this->resetContext() 将上下文重置为文档
  • 使用 wait*、exists、isVisible、isNotVisible 对所选元素进行断言
  • 使用 ->css() 向下移动以找到子选择器
  • 使用 ->end() 返回链,回到最后的 css() 调用
  • 使用 all()、getElements()、get* 获取元素、属性或其他内容以断开链