Skip to content

Commit 13b3724

Browse files
committed
Respect base element with fillField()/seeInField()/dontSeeInField()
Fixes #79
1 parent 085c554 commit 13b3724

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/Codeception/Module/WebDriver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ protected function findFields($selector): array
12551255
}
12561256

12571257
if (is_array($selector) || ($selector instanceof WebDriverBy)) {
1258-
$fields = $this->match($this->webDriver, $selector);
1258+
$fields = $this->match($this->getBaseElement(), $selector);
12591259

12601260
if (empty($fields)) {
12611261
throw new ElementNotFound($selector);
@@ -1272,20 +1272,20 @@ protected function findFields($selector): array
12721272
".//label[contains(normalize-space(string(.)), {$locator})]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]"
12731273
// @codingStandardsIgnoreEnd
12741274
);
1275-
$fields = $this->webDriver->findElements(WebDriverBy::xpath($xpath));
1275+
$fields = $this->getBaseElement()->findElements(WebDriverBy::xpath($xpath));
12761276
if (!empty($fields)) {
12771277
return $fields;
12781278
}
12791279

12801280
// by name
12811281
$xpath = ".//*[self::input | self::textarea | self::select][@name = {$locator}]";
1282-
$fields = $this->webDriver->findElements(WebDriverBy::xpath($xpath));
1282+
$fields = $this->getBaseElement()->findElements(WebDriverBy::xpath($xpath));
12831283
if (!empty($fields)) {
12841284
return $fields;
12851285
}
12861286

12871287
// try to match by CSS or XPath
1288-
$fields = $this->match($this->webDriver, $selector, false);
1288+
$fields = $this->match($this->getBaseElement(), $selector, false);
12891289
if (!empty($fields)) {
12901290
return $fields;
12911291
}

tests/data/app/view/form/bug79.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html>
3+
<head><title></title></head>
4+
<body>
5+
<form>
6+
<label for="title-1">Title</label>
7+
<input id="title-1">
8+
9+
<div class="nested">
10+
<label for="title-2">Title</label>
11+
<input id="title-2">
12+
</div>
13+
</form>
14+
</body>
15+
</html>

tests/unit/Codeception/Module/TestsForWeb.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Codeception\Module\WebDriver;
66
use Codeception\Test\Unit;
7+
use Codeception\Util\ActionSequence;
78

89
/**
910
* Author: davert
@@ -1745,4 +1746,27 @@ public function testPasswordArgument()
17451746
$data = data::get('form');
17461747
$this->assertEquals('thisissecret', $data['password']);
17471748
}
1749+
1750+
/**
1751+
* @see https://github.com/Codeception/module-webdriver/issues/79
1752+
*/
1753+
public function testFieldActionsWithPerformOn()
1754+
{
1755+
$this->module->amOnPage('/form/bug79');
1756+
$this->module->performOn(
1757+
['class' => 'nested'],
1758+
ActionSequence::build()
1759+
->fillField('Title', 'Test')
1760+
->seeInField('Title', 'Test')
1761+
);
1762+
1763+
$this->module->dontSeeInField('Title', 'Test');
1764+
$this->module->dontSeeInField('#title-1', 'Test');
1765+
$this->module->seeInField('#title-2', 'Test');
1766+
1767+
$title1Value = $this->module->grabValueFrom('#title-1');
1768+
$this->assertEmpty($title1Value);
1769+
$title2Value = $this->module->grabValueFrom('#title-2');
1770+
$this->assertEquals('Test', $title2Value);
1771+
}
17481772
}

0 commit comments

Comments
 (0)