我试图将一个Web驱动程序元素作为参数传递给一个关键字,并在执行日志中得到了一个exeption:
public class Main {
public static void main(String[] args) {
Operator op = OperatorCreator.getInstance("1-2");
System.out.println(op.getOperatorResult());
}
}
测试仍然通过,所以这不会影响结果,但在日志中看到这个并不好。此外,我不明白,为什么在将所有关键字参数传递给实际的Python代码之前将它们序列化,并且这个参数不可序列化时,它的工作原理。
问题:我可以在RobotFramework中传递不可序列化的参数吗?现在我正在尝试不发送元素,而是发送元素标识符的命名元组。
我使用的代码:
[ ERROR ] Calling listener method 'start_keyword' of listener '/usr/local/lib/python2.7/dist-packages/robotide/contrib/testrunner/TestRunnerAgent.py' failed: TypeError: <selenium.webdriver.remote.webelement.WebElement object at 0x7f686eb02390> is not JSON serializable
[ ERROR ] Calling listener method 'end_keyword' of listener '/usr/local/lib/python2.7/dist-packages/robotide/contrib/testrunner/TestRunnerAgent.py' failed: TypeError: <selenium.webdriver.remote.webelement.WebElement object at 0x7f686eb02390> is not JSON serializable
测试用例代码:
class ElementKeywords(object):
def has_text(self, element):
return bool(self.get_element_property(element, 'text'))
def wait_until_result(self, timeout, poll_period, func, *args):
time_spent = 0
timeout = convert_time(timeout)
poll_period = convert_time(poll_period)
result = False
thrown_exception = None
while True:
try:
result = func(*args)
thrown_exception = None
except Exception as exc:
result = False
thrown_exception = exc
if result or poll_period > timeout or time_spent > timeout:
break
time_spent += poll_period
time.sleep(poll_period)
if result:
return True
if thrown_exception:
raise thrown_exception
msg = 'Failed to receive positive result from {func} in {timeout} ' \
'seconds'.format(func=func.__name__, timeout=str(timeout))
raise TimeoutError(msg)
答案 0 :(得分:1)
问题不在您的代码中。您可以传递不可序列化的对象。 RIDE测试运行器似乎有一个错误。尝试从命令提示符运行您的测试用例,问题应该消失。