Mink / Selenium找不到按钮

问题描述 投票:1回答:1

我正在尝试运行此方案

@javascript
Scenario: Greeting in an alert box
    Given I am on "/"
    And I get content
    When I press "say"
    And I wait for the greeting to appear
    Then I should see "Hello JavaScript!"

使用我的调试步骤

/**
 * @Given I get content
 */
public function iGetContent(){
    echo $this->getSession()->getPage()->getContent();
}

但是,它报告它找不到按钮,(我相信)应该能够找到

@javascript
  Scenario: Greeting in an alert box      # features/home.feature:11
    Given I am on "/"                     # FeatureContext::visit()
    And I get content                     # FeatureContext::iGetContent()
      │ <html lang="en"><head></head><body>
      │         <h1>Home</h1>
      │         <span id="js-greeting"></span>
      │         <button type="button" id="say" value="say">say</button>
      │     
      │ 
      │     <script>
      │         function showGreeting(){
      │             document.getElementById("js-greeting").innerHTML = "Hello JavaScript!"
      │         }
      │ 
      │         function delayedGreeting(){
      │             window.setTimeout(showGreeting, 1000);
      │         }
      │     </script>
      │ 
      │ </body></html>
    When I press "say"                    # FeatureContext::pressButton()
      Button with id|name|title|alt|value "say" not found. (Behat\Mink\Exception\ElementNotFoundException)
    And I wait for the greeting to appear # FeatureContext::iWaitForTheGreetingToAppear()
    Then I should see "Hello JavaScript!" # FeatureContext::assertPageContainsText()

Selenium启动Firefox,我可以看到页面成功加载,而且我可以实际看到该按钮。有什么我想念的吗?这是我的composer.json / behat .yml,以防万一我错过了。

{
    "name": "",
    "description": "",
    "keywords": [],

    "repositories": [
        {
            "type": "vcs",
            "url": "[email protected]:xxx.git"
        }
    ],
    "require": {
        "php": "^5.6 || ^7.0",
        "judgeservice/mvc": "dev-master",
        "php-amqplib/php-amqplib": ">=2.6.1",
        "behat/behat": "3.0.6",
        "behat/mink": "1.6.*",
        "behat/mink-extension": "*",
        "behat/mink-selenium2-driver": "*",
        "behat/mink-goutte-driver": "*",
        "laravel/framework": "4.2.*",
        "behat/mink-zombie-driver": "*"
    },
    "autoload": {
        "psr-4": {
            "Application\\": "module/Application/src/"
        }
    },

    "require-dev": {
        "phpunit/phpunit": "^5.7"
    }
}
default:
    extensions:
        Behat\MinkExtension:
            base_url: "http://api.example.com"
            browser_name: 'firefox'
            goutte: ~
            selenium2: ~
public function pressButton($button)
{
    $button = $this->fixStepArgument($button);
    $this->getSession()->getPage()->pressButton($button);
}


protected function fixStepArgument($argument)
{
    return str_replace('\\"', '"', $argument);
}

public function pressButton($locator)
{
    $button = $this->findButton($locator);

    if (null === $button) {
        throw $this->elementNotFound('button', 'id|name|title|alt|value', $locator);
    }

    $button->press();
}



public function findButton($locator)
{
    return $this->find('named', array(
        'button', $this->getSelectorsHandler()->xpathLiteral($locator),
    ));
}
/**
 * @Given I hit say
 */
public function iHitSay(){
    $button = $this->getSession()
            ->getPage()
            ->find('css', '#say');

    $button->press();
}
selenium mink
1个回答
0
投票

这些解决方案帮助了我:

© www.soinside.com 2019 - 2024. All rights reserved.