Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 51ef9da

Browse files
committed
Rename textToBePresentInElementValue expected condition to make its name systematic with other conditions
1 parent 48b9c7a commit 51ef9da

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/).
77
- Cookies retrieved using `getCookieNamed()` and `getCookies()` methods of `WebDriverOptions` are now encapsulated in `Cookie` object instead of an plain array. The object implements `ArrayAccess` interface to provide backward compatibility.
88
- `ext-zip` is now specified as required dependency in composer.json (but the extension was already required by the code, though).
99
- Deprecate `WebDriverCapabilities::isJavascriptEnabled()` method.
10+
- Deprecate `textToBePresentInElementValue` expected condition in favor of `elementValueContains`.
1011

1112
### Fixed
1213
- Do not throw fatal error when `null` is passed to `sendKeys()`.

lib/WebDriverExpectedCondition.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,25 @@ function (WebDriver $driver) use ($by, $regexp) {
292292
/**
293293
* An expectation for checking if the given text is present in the specified elements value attribute.
294294
*
295+
* @codeCoverageIgnore
296+
* @deprecated Use WebDriverExpectedCondition::elementValueContains() instead
295297
* @param WebDriverBy $by The locator used to find the element.
296298
* @param string $text The text to be presented in the element value.
297299
* @return WebDriverExpectedCondition<bool> Condition returns whether the text is present in value attribute.
298300
*/
299301
public static function textToBePresentInElementValue(WebDriverBy $by, $text)
302+
{
303+
return self::elementValueContains($by, $text);
304+
}
305+
306+
/**
307+
* An expectation for checking if the given text is present in the specified elements value attribute.
308+
*
309+
* @param WebDriverBy $by The locator used to find the element.
310+
* @param string $text The text to be presented in the element value.
311+
* @return WebDriverExpectedCondition<bool> Condition returns whether the text is present in value attribute.
312+
*/
313+
public static function elementValueContains(WebDriverBy $by, $text)
300314
{
301315
return new static(
302316
function (WebDriver $driver) use ($by, $text) {

tests/unit/WebDriverExpectedConditionTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,41 @@ public function testShouldDetectElementTextMatchesCondition()
292292
$this->assertTrue($this->wait->until($condition));
293293
}
294294

295+
public function testShouldDetectElementValueContainsCondition()
296+
{
297+
// Set-up the consecutive calls to apply() as follows:
298+
// Call #1: throws NoSuchElementException
299+
// Call #2: return Element, but getAttribute will throw StaleElementReferenceException
300+
// Call #3: return Element, getAttribute('value') will return not-matching text
301+
// Call #4: return Element, getAttribute('value') will return matching text
302+
303+
$element = $this->createRemoteWebElementMock();
304+
305+
$element->expects($this->at(0))
306+
->method('getAttribute')
307+
->with('value')
308+
->willThrowException(new StaleElementReferenceException(''));
309+
310+
$element->expects($this->at(1))
311+
->method('getAttribute')
312+
->with('value')
313+
->willReturn('wrong text');
314+
315+
$element->expects($this->at(2))
316+
->method('getAttribute')
317+
->with('value')
318+
->willReturn('matching text');
319+
320+
$this->setupDriverToReturnElementAfterAnException($element, 4);
321+
322+
$condition = WebDriverExpectedCondition::elementValueContains(
323+
WebDriverBy::cssSelector('.foo'),
324+
'matching'
325+
);
326+
327+
$this->assertTrue($this->wait->until($condition));
328+
}
329+
295330
public function testShouldDetectNumberOfWindowsToBeCondition()
296331
{
297332
$this->driverMock->expects($this->any())

0 commit comments

Comments
 (0)