在进行身份验证的场景步骤中,Mink无法找到要填充的字段。
我正在使用behat 3.5和PHP 5.6.38。 包括Mink在内的整个作曲家堆栈都是最新的。
behat.yml文件:
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
Behat\MinkExtension:
goutte: ~
selenium2: ~
base_url: 'localhost'
Drupal\DrupalExtension:
blackbox: ~
api_driver: 'drush'
drush:
alias: 'local'
root: 'C:\xampp2\htdocs\project'
drupal:
alias: 'local'
drupal_root: 'C:\xampp2\htdocs\project'
local:
extensions:
Behat\MinkExtension:
base_url: 'localhost'
Drupal\DrupalExtension:
api_driver: 'drush'
drush:
alias: '@self'
root: 'C:\xampp2\htdocs\project'
drupal:
drupal_root: 'c:\xampp2\htdocs\project'
my.feature文件:
Feature: Login
In order to login
Authenticate as administrator
Submit form sucessfully.
@api
Scenario: Login and join community.
Given I am on "/user"
# Given I am logged in as a user with the "administrator" role
When I fill in the following:
| edit-name | bddtest |
| edit-pass | Behattest101 |
featureContext.php:
<?php
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\Behat\Tester\Exception\PendingException;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct() {
}
}
当我奔跑时> behat ... 当我填写以下内容时: #Drupal \ DrupalExtension \ Context \ MinkContext :: fillFields()
| edit-name | myusername |
| edit-pass | mypassword |
Form field with id|name|label|value|placeholder "edit-name" not found. (Behat\Mink\Exception\ElementNotFoundException)
1 scenario (1 failed)
5 steps (1 passed, 1 failed, 3 skipped)
I also tried "Username" and "Password" but with the same result.
答案 0 :(得分:0)
我还遇到了Behat找不到字段的问题。我只是使用Javascript作为解决方法。 (Behat/Mink doesn't find field by id)
my.feature文件:
@javascript
Scenario Outline: Login with JS
When I fill in "<field>" with "<value>" with javascript
Examples:
|field |value |
|edit-name| myusername |
|edit-pass| mypassword |
featureContext.php
/**
* @When I fill in :field with :value with javascript
*/
public function loginWithJavascript($field, $value){
$javascript = "window.onload = function () {var e = document.getElementById('$field').value='$value';}";
$this->getSession()->executeScript($javascript);
}
尽管这不是最干净的解决方案,但它对我有用。希望它也对您有用。我仍在寻找更好的解决方案。