-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate keyPress, keyDown, keyUp in favor of pressKey. #831
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,37 +305,52 @@ public function blur() | |
$this->getDriver()->blur($this->getXpath()); | ||
} | ||
|
||
/** | ||
* Press one or more keyboard keys on an element. | ||
* | ||
* @param string|int|array $keys a string to type ('PHP Hypertext Preprocessor'), a integer key code (88), or an array of keys to press in sequence (e.g.: ["\u{E008}", 'H', "\u{E001}", 'ello']). See https://w3c.github.io/webdriver/#keyboard-actions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our own API should not be based on the Webdriver representation of modifier keys, as that might not fit other drivers. |
||
*/ | ||
public function pressKey($keys) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing an interface is a BC break. |
||
$this->getDriver()->pressKey($this->getXpath(), $keys); | ||
} | ||
|
||
/** | ||
* Presses specific keyboard key. | ||
* | ||
* @param string|int $char could be either char ('b') or char-code (98) | ||
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') | ||
* | ||
* @deprecated use pressKey($keys) instead. | ||
*/ | ||
public function keyPress($char, $modifier = null) | ||
{ | ||
$this->getDriver()->keyPress($this->getXpath(), $char, $modifier); | ||
$this->pressKey($this->wrapCharWithModifier($char, $modifier)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a The same goes for other similar places in this class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
/** | ||
* Pressed down specific keyboard key. | ||
* | ||
* @param string|int $char could be either char ('b') or char-code (98) | ||
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') | ||
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta')' | ||
* | ||
* @deprecated use pressKey($keys) instead. | ||
*/ | ||
public function keyDown($char, $modifier = null) | ||
{ | ||
$this->getDriver()->keyDown($this->getXpath(), $char, $modifier); | ||
$this->pressKey($this->wrapCharWithModifier($char, $modifier)); | ||
} | ||
|
||
/** | ||
* Pressed up specific keyboard key. | ||
* | ||
* @param string|int $char could be either char ('b') or char-code (98) | ||
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') | ||
* | ||
* @deprecated use pressKey($keys) instead. | ||
*/ | ||
public function keyUp($char, $modifier = null) | ||
{ | ||
$this->getDriver()->keyUp($this->getXpath(), $char, $modifier); | ||
$this->pressKey($this->wrapCharWithModifier($char, $modifier)); | ||
} | ||
|
||
/** | ||
|
@@ -347,4 +362,27 @@ public function submit() | |
{ | ||
$this->getDriver()->submitForm($this->getXpath()); | ||
} | ||
|
||
/** | ||
* Polyfill to convert from deprecated keyPress(), keyDown(), keyUp() parameters to pressKey() parameters. | ||
* | ||
* @param string|int $char could be either char ('b') or char-code (98) | ||
* @param string|null $modifier keyboard modifier (could be 'ctrl', 'alt', 'shift' or 'meta') | ||
* @return string|int|array a $keys parameter that pressKey() can parse | ||
*/ | ||
private function wrapCharWithModifier($char, $modifier = null) | ||
{ | ||
switch ($modifier) { | ||
case 'ctrl': | ||
return ["\u{E009}", $char, "\u{E001}"]; | ||
case 'alt': | ||
return ["\u{E00A}", $char, "\u{E001}"]; | ||
case 'shift': | ||
return ["\u{E008}", $char, "\u{E001}"]; | ||
case 'meta': | ||
return ["\u{E03D}", $char, "\u{E001}"]; | ||
default: | ||
return $char; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is triggering a deprecation notice from a method, that throws an exception a good idea?
Maybe we should trigger a deprecation notice in driver sub-classes, where this method is completely replaced?
The same goes for other similar places.