Skip to content

Commit

Permalink
Add a test for [Keys.ARROW_LEFT].
Browse files Browse the repository at this point in the history
keys_to_typing handles list of Keys.

keys_to_typing behavior was regressed by an
implementation change. This change reverts
keys_to_typing to its former behavior.

That is, element.send_keys([Keys.ENTER])
should result in the ENTER key being
pressed, not the unicode representation of
ENTER defined in common/keys.py to be
typed into a text field.

Fixes #1839

Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
  • Loading branch information
joshbruning authored and lukeis committed Mar 28, 2016
1 parent 9e9f099 commit 6094ebf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 10 additions & 8 deletions py/selenium/webdriver/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"""
The Utils methods.
"""

import socket
from selenium.webdriver.common.keys import Keys

try:
basestring
Expand Down Expand Up @@ -83,13 +85,13 @@ def keys_to_typing(value):
"""Processes the values that will be typed in the element."""
typing = []
for val in value:
# If it is a non-string object, make it a string
if not isinstance(val, basestring):
# This str() call enables for abstraction if one has a custom object that has some
# UI representation to implement __str__() to return the representation, making it
# possible to pass that object to the filling methods.
if isinstance(val, Keys):
typing.append(val)
elif isinstance(val, int):
val = str(val)
# Then just add the separate characters in the list
# ['e'].extend('asdf') => ['e', 'a', 's', 'd', 'f']
typing.extend(val)
for i in range(len(val)):
typing.append(val[i])
else:
for i in range(len(val)):
typing.append(val[i])
return typing
6 changes: 6 additions & 0 deletions py/test/selenium/webdriver/common/typing_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def testArrowKeysShouldNotBePrintable(self):
keyReporter.send_keys(Keys.ARROW_LEFT)
self.assertEqual(keyReporter.get_attribute("value"), "")

def testListOfArrowKeysShouldNotBePrintable(self):
self._loadPage("javascriptPage")
keyReporter = self.driver.find_element(by=By.ID, value="keyReporter")
keyReporter.send_keys([Keys.ARROW_LEFT])
self.assertEqual(keyReporter.get_attribute("value"), "")

def testShouldBeAbleToUseArrowKeys(self):
self._loadPage("javascriptPage")
keyReporter = self.driver.find_element(by=By.ID, value="keyReporter")
Expand Down

0 comments on commit 6094ebf

Please sign in to comment.