2 new revisions:
Revision: 7f6be65cf49a
Branch: default
Author: Pekka Klärck
Date: Thu Jan 9 19:51:18 2014 UTC
Log: Dialogs: Doc enhancements.
http://code.google.com/p/robotframework/source/detail?r=7f6be65cf49a
Revision: bf13c953e692
Branch: default
Author: Pekka Klärck
Date: Thu Jan 9 20:00:25 2014 UTC
Log: Dialogs.Get Value From User: Support hiding the value...
http://code.google.com/p/robotframework/source/detail?r=bf13c953e692
==============================================================================
Revision: 7f6be65cf49a
Branch: default
Author: Pekka Klärck
Date: Thu Jan 9 19:51:18 2014 UTC
Log: Dialogs: Doc enhancements.
http://code.google.com/p/robotframework/source/detail?r=7f6be65cf49a
Modified:
/src/robot/libraries/Dialogs.py
=======================================
--- /src/robot/libraries/Dialogs.py Tue Jun 11 06:25:58 2013 UTC
+++ /src/robot/libraries/Dialogs.py Thu Jan 9 19:51:18 2014 UTC
@@ -21,7 +21,7 @@
Long lines in the provided messages are wrapped automatically since
Robot Framework 2.8. If you want to wrap lines manually, you can add
-newlines using \\n character sequence.
+newlines using the `\\n` character sequence.
The library has following two limitations:
- It is not compatible with IronPython.
@@ -59,8 +59,8 @@
def execute_manual_step(message, default_error=''):
"""Pauses test execution until user sets the keyword status.
- User can select 'PASS' or 'FAIL', and in the latter case an additional
- dialog is opened for defining the error message.
+ User can press either `PASS` or `FAIL` button. In the latter case
execution
+ fails and an additional dialog is opened for defining the error
message.
`message` is the instruction shown in the initial dialog and
`default_error` is the default value shown in the possible error
message
@@ -73,11 +73,12 @@
def get_value_from_user(message, default_value=''):
"""Pauses test execution and asks user to input a value.
- Input value is returned by the keyword.
+
+ Value typed by the user, or the possible default value, is returned.
+ Returning an empty value is fine, but pressing `Cancel` fails the
keyword.
`message` is the instruction shown in the dialog and `default_value` is
- the possible default value shown in the input field. Selecting 'Cancel'
- fails the keyword.
+ the possible default value shown in the input field.
Example:
| ${value} = | Get Value From User | Enter new value |
default_value=1 |
@@ -89,8 +90,13 @@
def get_selection_from_user(message, *values):
"""Pauses test execution and asks user to select a value.
+ The selected value is returned. Pressing `Cancel` fails the keyword.
+
`message` is the instruction shown in the dialog and `values` are
- the options given to the user. Selecting 'Cancel' fails the keyword.
+ the options given to the user.
+
+ Example:
+ | ${username} = | Get Selection From User | Select user name | user1 |
user2 | admin |
"""
return _validate_user_input(SelectionDialog(message, values))
==============================================================================
Revision: bf13c953e692
Branch: default
Author: Pekka Klärck
Date: Thu Jan 9 20:00:25 2014 UTC
Log: Dialogs.Get Value From User: Support hiding the value
Update issue 1620
Status: Review
Owner: pekka.klarck
This was trivial to implement with Python but needed a bit more thinking
with Jython.
This issue ought to be done otherwise but the feature needs to be manually
tested on different operating systems (Windows. Linux, OSX) both with
Python and Jython.
http://code.google.com/p/robotframework/source/detail?r=bf13c953e692
Modified:
/atest/robot/standard_libraries/dialogs/dialogs.txt
/atest/testdata/standard_libraries/dialogs/dialogs.txt
/src/robot/libraries/Dialogs.py
/src/robot/libraries/dialogs_ipy.py
/src/robot/libraries/dialogs_jy.py
/src/robot/libraries/dialogs_py.py
=======================================
--- /atest/robot/standard_libraries/dialogs/dialogs.txt Tue Jun 11 06:25:58
2013 UTC
+++ /atest/robot/standard_libraries/dialogs/dialogs.txt Thu Jan 9 20:00:25
2014 UTC
@@ -25,6 +25,9 @@
Get Empty Value From User
Check Test Case ${TESTNAME}
+
+Get Hidden Value From User
+ Check Test Case ${TESTNAME}
Get Value From User Cancelled
Check Test Case ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/dialogs/dialogs.txt Tue Jun 11
06:25:58 2013 UTC
+++ /atest/testdata/standard_libraries/dialogs/dialogs.txt Thu Jan 9
20:00:25 2014 UTC
@@ -29,6 +29,12 @@
Get Empty Value From User
${value} = Get Value From User Press OK.
Should Be Equal ${value} ${EMPTY}
+
+Get Hidden Value From User
+ ${value} = Get Value From User Type 'value' and press OK.
hide=yes
+ Should Be Equal ${value} value
+ ${value} = Get Value From User Press OK. initial value
hidden
+ Should Be Equal ${value} initial value
Get Value From User Cancelled
[Documentation] FAIL No value provided by user.
=======================================
--- /src/robot/libraries/Dialogs.py Thu Jan 9 19:51:18 2014 UTC
+++ /src/robot/libraries/Dialogs.py Thu Jan 9 20:00:25 2014 UTC
@@ -71,7 +71,7 @@
raise AssertionError(msg)
-def get_value_from_user(message, default_value=''):
+def get_value_from_user(message, default_value='', hide=False):
"""Pauses test execution and asks user to input a value.
Value typed by the user, or the possible default value, is returned.
@@ -80,11 +80,14 @@
`message` is the instruction shown in the dialog and `default_value` is
the possible default value shown in the input field.
+ If `hide` is given any true value, such as any non-empty string, the
value
+ typed by the user is hidden. This is a new feature in Robot Framework
2.8.4.
+
Example:
- | ${value} = | Get Value From User | Enter new value |
default_value=1 |
- | Do something | ${value} |
+ | ${username} = | Get Value From User | Input user name | default |
+ | ${password} = | Get Value From User | Input password | hide=yes |
"""
- return _validate_user_input(InputDialog(message, default_value))
+ return _validate_user_input(InputDialog(message, default_value, hide))
def get_selection_from_user(message, *values):
=======================================
--- /src/robot/libraries/dialogs_ipy.py Thu Jun 6 14:00:44 2013 UTC
+++ /src/robot/libraries/dialogs_ipy.py Thu Jan 9 20:00:25 2014 UTC
@@ -27,7 +27,7 @@
class InputDialog(_AbstractWinformsDialog):
- def __init__(self, message, default):
+ def __init__(self, message, default, hide=False):
_AbstractWinformsDialog.__init__(self)
=======================================
--- /src/robot/libraries/dialogs_jy.py Thu Jun 6 14:00:44 2013 UTC
+++ /src/robot/libraries/dialogs_jy.py Thu Jan 9 20:00:25 2014 UTC
@@ -13,7 +13,8 @@
# limitations under the License.
import time
-from javax.swing import JOptionPane
+from java.awt import GridLayout
+from javax.swing import JLabel, JOptionPane, JPanel, JPasswordField,
JTextField
from javax.swing.JOptionPane import PLAIN_MESSAGE, UNINITIALIZED_VALUE, \
YES_NO_OPTION, OK_CANCEL_OPTION, DEFAULT_OPTION
@@ -56,12 +57,18 @@
class InputDialog(_SwingDialog):
- def __init__(self, message, default):
- pane = WrappedOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION)
- pane.setWantsInput(True)
- pane.setInitialSelectionValue(default)
+ def __init__(self, message, default, hide=False):
+ self._input_field = JPasswordField() if hide else JTextField()
+ self._input_field.setText(default)
+ panel = JPanel(layout=GridLayout(2, 1))
+ panel.add(JLabel(message))
+ panel.add(self._input_field)
+ pane = WrappedOptionPane(panel, PLAIN_MESSAGE, OK_CANCEL_OPTION)
_SwingDialog.__init__(self, pane)
+ def _get_value(self, pane):
+ return self._input_field.getText()
+
class SelectionDialog(_SwingDialog):
=======================================
--- /src/robot/libraries/dialogs_py.py Tue Jun 11 06:21:49 2013 UTC
+++ /src/robot/libraries/dialogs_py.py Thu Jan 9 20:00:25 2014 UTC
@@ -22,12 +22,12 @@
_left_button = 'OK'
_right_button = 'Cancel'
- def __init__(self, message, value=None):
+ def __init__(self, message, value=None, **extra):
self._prevent_execution_with_timeouts()
self._parent = self._get_parent()
Toplevel.__init__(self, self._parent)
self._initialize_dialog()
- self._create_body(message, value)
+ self._create_body(message, value, **extra)
self._create_buttons()
self._result = None
@@ -60,10 +60,10 @@
self.attributes('-topmost', True)
self.attributes('-topmost', False)
- def _create_body(self, message, value):
+ def _create_body(self, message, value, **extra):
frame = Frame(self)
Label(frame, text=message, anchor=W, justify=LEFT,
wraplength=800).pack(fill=BOTH)
- selector = self._create_selector(frame, value)
+ selector = self._create_selector(frame, value, **extra)
if selector:
selector.pack(fill=BOTH)
selector.focus_set()
@@ -118,11 +118,11 @@
class InputDialog(_TkDialog):
- def __init__(self, message, default=''):
- _TkDialog.__init__(self, message, default)
+ def __init__(self, message, default='', hide=False):
+ _TkDialog.__init__(self, message, default, hide=hide)
- def _create_selector(self, parent, default):
- self._entry = Entry(parent)
+ def _create_selector(self, parent, default, hide):
+ self._entry = Entry(parent, show='*' if hide else '')
self._entry.insert(0, default)
self._entry.select_range(0, END)
return self._entry
--
---
You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.