6

私はBehatが初めてです。私は現在、Mink 拡張機能と Selenium2 ドライバーを使用しています。シナリオの一部として、テストが要素の上に移動するように指定する方法を知りたいです。

たとえば、これが私のシナリオです。

Scenario: Testing that the Contact Us submenu appears
    Given I am on "/"
    When I hover over "About"
    Then I should see "Contact Us"
4

4 に答える 4

11

この回答https://stackoverflow.com/a/17217598に基づいて、私はそれを理解し、click()をmouseOver()に置き換えました。

これが私のFeatureContextコードです:

/**
 * @When /^I hover over the element "([^"]*)"$/
 */
public function iHoverOverTheElement($locator)
{
        $session = $this->getSession(); // get the mink session
        $element = $session->getPage()->find('css', $locator); // runs the actual query and returns the element

        // errors must not pass silently
        if (null === $element) {
            throw new \InvalidArgumentException(sprintf('Could not evaluate CSS selector: "%s"', $locator));
        }

        // ok, let's hover it
        $element->mouseOver();
}

使用するときに css セレクターを渡す必要があるため、使用法は次のようになります。

...
When I hover over the element ".about"
...
于 2013-08-29T20:36:59.757 に答える
0
/**
 * works better with css, uses different method for css than xpath
 * @Then /^I mouse over "(?P<selector>[^"]*)"$/
 */



 public function iMouseOver($selector){
        $element = $this->find($selector);
        if($element == null){
            throw new Exception('Element '.$selector.' NOT found');
        }
        $this->iFocusOn($selector);
        if (strstr($selector, '//')) {
            $element->mouseOver();
        } else {
            $this->mouseOver($selector, '1');
        }
    }
于 2015-07-14T13:08:10.403 に答える