Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Codeception和WebDriver测试文本光标位置_Php_Selenium_Webdriver_Bdd_Codeception - Fatal编程技术网

Php 使用Codeception和WebDriver测试文本光标位置

Php 使用Codeception和WebDriver测试文本光标位置,php,selenium,webdriver,bdd,codeception,Php,Selenium,Webdriver,Bdd,Codeception,使用Codeception和Gherkin,我试图找出如何测试文本光标位置的自动更新: When I click "New post" Then the blinking text cursor should be in the "Title" field 代码如下所示: <a href="#" id="js-move-text-cursor-to-post-title-input"> New post </a> … <label> Title

使用Codeception和Gherkin,我试图找出如何测试文本光标位置的自动更新:

When I click "New post"
Then the blinking text cursor should be in the "Title" field
代码如下所示:

<a href="#" id="js-move-text-cursor-to-post-title-input">
  New post
</a>

…

<label>
  Title
  <input type="text" name="title">
</label>

…

<!-- Some JavaScript to set the text cursor to the "Title" input field -->
测试/验收.suite.yml

actor: AcceptanceTester
modules:
    enabled:
        - Symfony:
            part: SERVICES
        - Doctrine2:
            depends: Symfony
        - WebDriver:
            url: http://localhost:8000
            browser: chrome
        - \Helper\Acceptance

您应该测试按下的键是否在预期字段中结束,而不是检查光标:

When I click "New post"
When I type "abcd"
Then the "Title" field has the value "abcd"
codeception的当前API似乎没有提供获取活动元素或在活动字段中键入内容的方法

因此,您可能必须使用底层API

使用
$webdriver->switchTo()->activeElement()

,或使用
executeJS

// click "New post"
$I->click('#js-move-text-cursor-to-post-title-input');

// type "abcd" in the focused field
$I->executeJS('return document.activeElement')->sendKeys('abcd');

// assert that the value "abcd" is in the expected field
$I->seeInField('input[name="title"]', 'abcd');
,或使用底层键盘界面:

// click "New post"
$I->click('#js-move-text-cursor-to-post-title-input');

// type "abcd" in the focused field
$I->executeInSelenium(function($webdriver) {
  $webdriver->getKeyboard()->sendKeys('abcd');
});

// assert that the value "abcd" is in the expected field
$I->seeInField('input[name="title"]', 'abcd');

这似乎与被问到的另一个问题非常相似:

也许这个问题的答案会对你有所帮助

// click "New post"
$I->click('#js-move-text-cursor-to-post-title-input');

// type "abcd" in the focused field
$I->executeJS('return document.activeElement')->sendKeys('abcd');

// assert that the value "abcd" is in the expected field
$I->seeInField('input[name="title"]', 'abcd');
// click "New post"
$I->click('#js-move-text-cursor-to-post-title-input');

// type "abcd" in the focused field
$I->executeInSelenium(function($webdriver) {
  $webdriver->getKeyboard()->sendKeys('abcd');
});

// assert that the value "abcd" is in the expected field
$I->seeInField('input[name="title"]', 'abcd');