Created
December 4, 2019 09:01
-
-
Save romaricdrigon/1c2c3d3ab99644f61ba21f8334d6fc18 to your computer and use it in GitHub Desktop.
Reproducing crash caused by "clear()" in webdriver 1.8.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Facebook\WebDriver; | |
use Facebook\WebDriver\Remote\DesiredCapabilities; | |
use Facebook\WebDriver\Remote\RemoteWebDriver; | |
require_once('vendor/autoload.php'); | |
// Start Chrome in headless mode | |
// Chromedriver should already be running and listening. | |
$host = 'http://localhost:9515'; | |
$capabilities = DesiredCapabilities::chrome(); | |
$driver = RemoteWebDriver::create($host, $capabilities, 5000); | |
$driver->get('https://the-internet.herokuapp.com/login'); | |
// Check page | |
echo "The title is '" . $driver->getTitle() . "'\n"; | |
/* | |
* Fills in login form - we simulate typing. | |
* | |
* Comment out both "clear() line to make login works / fails. | |
* | |
* Clear makes "sendKeys" fails, the value is not entered correctly: | |
* either the whole string either some chars from end of string are "eaten". | |
* Adding a "sleep()" does not help, it does not seem to be a timing issue. | |
* The crash looks to be caused by lines 76-93 of RemoteWebElement::clear(). | |
* Replacing "WebDriverKeys::BACKSPACE" by "WebDriverKeys::DELETE" fixed it. | |
*/ | |
$username = $driver->findElement(WebDriverBy::name('username')); | |
$username->clear(); // Comment to fix | |
$username->sendKeys('tomsmith'); | |
// Password field | |
$password = $driver->findElement(WebDriverBy::name('password')); | |
$password->clear(); // Comment to fix | |
$password->sendKeys('SuperSecretPassword!'); | |
$driver->takeScreenshot('before_login.png'); | |
// We click on submit button | |
$driver->findElement(WebDriverBy::cssSelector('button[type="submit"]')) | |
->click(); | |
if (!assert('https://the-internet.herokuapp.com/secure' === $driver->getCurrentURL(), 'Login failed')) { | |
$driver->takeScreenshot('failure.png'); | |
} | |
// close the browser | |
$driver->quit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment