我正在尝试运行此方案
@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": "git@bitbucket.org: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();
}
答案 0 :(得分:0)