php Behat测试checkout css属性

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Behat测试checkout css属性相关的知识,希望对你有一定的参考价值。

<?php  
 /**
   * @Given /^The element "(?P<selector>[^"]*)" should have a css property "(?P<property>[^"]*)" with a value of "(?P<value>[^"]*)"$/
   *
   * @TODO Need to find a way to test for css styles on elements.
   * Or possibly we should just be checking the markup, and not the styling... Research this more.
   */
  public function assertElementHasCssValue($selector, $property, $value)
  {
    $page = $this->getSession()->getPage();
    $element = $page->find('css', $selector);

    if (empty($element)) {
      $message = sprintf('Could not find element using the selector "%s"', $selector);
      throw new \Exception($message);
    }
    $style = $this->elementHasCSSValue($element, $property, $value);
    if (empty($style)) {
      $message = sprintf('The property "%s" for the selector "%s" is not "%s"', $property, $selector, $value);
      throw new \Exception($message);
    }
  }

  /**
   * Determine if a Mink NodeElement contains a specific css rule attribute value.
   *
   * @param NodeElement $element
   *   NodeElement previously selected with $this->getSession()->getPage()->find().
   * @param string $property
   *   Name of the CSS property, such as "visibility".
   * @param string $value
   *   Value of the specified rule, such as "hidden".
   *
   * @return NodeElement|bool
   *   The NodeElement selected if true, FALSE otherwise.
   */
  protected function elementHasCSSValue($element, $property, $value)
  {
    $exists = FALSE;
    $style = $element->getAttribute('style');
    if ($style) {
      if (preg_match("/(^{$property}:|; {$property}:) ([a-z0-9]+);/i", $style, $matches)) {
        $found = array_pop($matches);
        if ($found == $value) {
          $exists = $element;
        }
      }
    }

    return $exists;
  }

以上是关于php Behat测试checkout css属性的主要内容,如果未能解决你的问题,请参考以下文章

php 将此定义添加到FeatureContext.php,以获取Behat / Selenium2测试失败步骤的屏幕截图。它创建一个目录c

php 将此定义添加到FeatureContext.php,以获取Behat / Selenium2测试失败步骤的屏幕截图。它创建一个目录c

在 Behat 中分离测试套件

如何让Mink Selenium 2 Driver等待页面加载Behat

php Behat + Mink等待模态可见

php Behat + Mink等待模态可见