This commit is contained in:
Daniel Schadt 2016-03-29 21:02:54 +02:00
parent 3007fbf5c2
commit bd5b1f207d
2 changed files with 10 additions and 8 deletions

View File

@ -259,7 +259,8 @@ class QuteProc(testprocess.Process):
Return: Return:
The LogLine. The LogLine.
""" """
return self.wait_for(category='js', function='javaScriptConsoleMessage', return self.wait_for(category='js',
function='javaScriptConsoleMessage',
message='[*] {}'.format(message)) message='[*] {}'.format(message))
def _is_error_logline(self, msg): def _is_error_logline(self, msg):
@ -429,8 +430,8 @@ class QuteProc(testprocess.Process):
def click_element(self, text): def click_element(self, text):
"""Click the element with the given text.""" """Click the element with the given text."""
# Use Javascript and XPath to find the right element, use console.log to # Use Javascript and XPath to find the right element, use console.log
# return an error (no element found, ambiguous element) # to return an error (no element found, ambiguous element)
script = ( script = (
'var _es = document.evaluate(\'//*[text()={text}]\', document, ' 'var _es = document.evaluate(\'//*[text()={text}]\', document, '
'null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);' 'null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);'
@ -469,12 +470,12 @@ def _xpath_escape(text):
The string "escaped" as a concat() call. The string "escaped" as a concat() call.
""" """
# Shortcut if at most a single quoting style is used # Shortcut if at most a single quoting style is used
if not "'" in text or not '"' in text: if "'" not in text or '"' not in text:
return repr(text) return repr(text)
parts = re.split('([\'"])', text) parts = re.split('([\'"])', text)
# Python's repr() of strings will automatically choose the right quote type. # Python's repr() of strings will automatically choose the right quote
# Since each part only contains one "type" of quote, no escaping should be # type. Since each part only contains one "type" of quote, no escaping
# necessary. # should be necessary.
parts = [repr(part) for part in parts if part] parts = [repr(part) for part in parts if part]
return 'concat({})'.format(', '.join(parts)) return 'concat({})'.format(', '.join(parts))

View File

@ -190,7 +190,8 @@ class TestClickElement:
('Test', "'Test'"), ('Test', "'Test'"),
("Don't", '"Don\'t"'), ("Don't", '"Don\'t"'),
# This is some serious string escaping madness # This is some serious string escaping madness
('"Don\'t", he said', "concat('\"', 'Don', \"'\", 't', '\"', ', he said')"), ('"Don\'t", he said',
"concat('\"', 'Don', \"'\", 't', '\"', ', he said')"),
]) ])
def test_xpath_escape(string, expected): def test_xpath_escape(string, expected):
assert quteprocess._xpath_escape(string) == expected assert quteprocess._xpath_escape(string) == expected