Skip to content

Commit 21f2108

Browse files
authored
Make input clear configurable (#1357)
Fixes #1330
1 parent beaf1ef commit 21f2108

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

atest/acceptance/keywords/textfields.robot

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,26 @@ Input Text and Input Password
1616
... LOG 2 Typing text 'username' into text field 'username_field'.
1717
... LOG 3 Typing password into text field 'password_field'.
1818
[Setup] Go To Page "forms/login.html"
19-
Input Text username_field username
19+
Input Text username_field username
2020
Input Password password_field password
21+
${username} = Get Value username_field
22+
${password} = Get Value password_field
23+
Should Be Equal ${username} username
24+
Should Be Equal ${password} password
2125
Submit Form
2226
Verify Location Is "forms/submit.html"
2327

28+
Input Text and Input Password No Clear
29+
[Setup] Go To Page "forms/login.html"
30+
Input Text username_field user clear=False
31+
Input Password password_field pass False
32+
Input Text username_field name clear=False
33+
Input Password password_field word False
34+
${username} = Get Value username_field
35+
${password} = Get Value password_field
36+
Should Be Equal ${username} username
37+
Should Be Equal ${password} password
38+
2439
Input Non-ASCII Text
2540
[Documentation]
2641
... LOG 2 Typing text 'Yrjö Ärje' into text field 'name'.

src/SeleniumLibrary/keywords/formelement.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from SeleniumLibrary.base import LibraryComponent, keyword
2020
from SeleniumLibrary.errors import ElementNotFound
21-
from SeleniumLibrary.utils import is_noney
21+
from SeleniumLibrary.utils import is_noney, is_truthy
2222

2323

2424
class FormElementKeywords(LibraryComponent):
@@ -213,11 +213,11 @@ def choose_file(self, locator, file_path):
213213
self.find_element(locator).send_keys(file_path)
214214

215215
@keyword
216-
def input_password(self, locator, password):
216+
def input_password(self, locator, password, clear=True):
217217
"""Types the given password into text field identified by ``locator``.
218218
219219
See the `Locating elements` section for details about the locator
220-
syntax.
220+
syntax. See `Input Text` for ``clear`` argument details.
221221
222222
Difference compared to `Input Text` is that this keyword does not
223223
log the given password on the INFO level. Notice that if you use
@@ -235,22 +235,29 @@ def input_password(self, locator, password):
235235
be seen there. Additionally Robot Framework logs all arguments using
236236
the TRACE level. Tests must thus not be executed using level below
237237
INFO if password should not be logged in any format.
238+
239+
The `clear` argument is new in SeleniumLibrary 4.0
238240
"""
239241
self.info("Typing password into text field '%s'." % locator)
240-
self._input_text_into_text_field(locator, password)
242+
self._input_text_into_text_field(locator, password, clear)
241243

242244
@keyword
243-
def input_text(self, locator, text):
245+
def input_text(self, locator, text, clear=True):
244246
"""Types the given ``text`` into text field identified by ``locator``.
245247
246-
Use `Input Password` if you do not want the given ``text`` to be
247-
logged.
248+
When ``clear`` is true, the input element is cleared before
249+
text is typed to the element. When false, the previous text
250+
is not cleared from the element. Use `Input Password` if you
251+
do not want the given ``text`` to be logged.
248252
249253
See the `Locating elements` section for details about the locator
250-
syntax.
254+
syntax. See the `Boolean arguments` section how Boolean values are
255+
handled.
256+
257+
The `clear` argument is new in SeleniumLibrary 4.0
251258
"""
252259
self.info("Typing text '%s' into text field '%s'." % (text, locator))
253-
self._input_text_into_text_field(locator, text)
260+
self._input_text_into_text_field(locator, text, clear)
254261

255262
@keyword
256263
def page_should_contain_textfield(self, locator, message=None, loglevel='TRACE'):
@@ -405,7 +412,8 @@ def _get_value_from_radio_buttons(self, elements):
405412
return element.get_attribute('value')
406413
return None
407414

408-
def _input_text_into_text_field(self, locator, text):
415+
def _input_text_into_text_field(self, locator, text, clear):
409416
element = self.find_element(locator)
410-
element.clear()
417+
if is_truthy(clear):
418+
element.clear()
411419
element.send_keys(text)

0 commit comments

Comments
 (0)