当我对认证的情况下一步,水貂无法找到字段填写。
我使用贝哈特3.5和PHP 38年6月5日。整个作曲家堆栈进行更新,包括水貂。
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() {
}
}
当我运行>贝哈特......当我填写以下内容:#Drupal的\ DrupalExtension \背景\ 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.
我也有这样的贝哈特没有发现场的问题。我只是用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);
}
虽然它不是最干净的解决方案,它为我工作。希望它为你工作为好。我仍然在试图找到一个更好的解决方案。