【发布时间】:2015-07-24 17:03:01
【问题描述】:
我创建了一个类似于Wait Until Keyword Succeeds 的关键字,所以我想向它发送另一个关键字:
def keyword_expecting_keyword(self, func, *args):
return func(*args)
def normal_keyword(self, arg):
return arg
现在我希望调用keyword_expecting_keyword 并将normal_keyword 作为参数传递:
Keyword Expecting Keyword Normal Keyword 123
但是当我这样做时,我得到了一个TypeError: 'unicode' object is not callable,所以不是普通关键字引用机器人发送一个函数名称。
注意:如果重要的话,我使用的是旧的 RobotFramework 1.2.3(机器人是 v2.8,所以没关系,骑行 GUI 是 v1.2.3)
用真实代码更新:
关键字代码
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)
测试用例
*** Settings ***
Test Setup Web Setup
Test Teardown Web Teardown
Resource web_resources.txt
*** Test Cases ***
Check Index
[Tags] US123456
Web Login
Clean Redis
${job_id}= Create Pool
Web Refresh
${data_pool_element}= Get Element By Xpath //div[@id="progress-pool"]/div[1]
Wait Until Result 20 1 Has Text ${data_pool_element}
Validate Pool ${job_id}
堆栈跟踪
20150723 14:42:02.293 : INFO :
//div[@id="progress-pki-pool"]/div[1]
(None, u'//div[@id="progress-pki-pool"]/div[1]')
20150723 14:42:02.293 : TRACE : Return: <selenium.webdriver.remote.webelement.WebElement object at 0x7f74173f2450>
20150723 14:42:02.294 : INFO : ${pki_pool_element} = <selenium.webdriver.remote.webelement.WebElement object at 0x7f74173f2450>
20150723 14:42:02.295 : TRACE : Arguments: [ u'20' | u'1' | u'Has Text' | <selenium.webdriver.remote.webelement.WebElement object at 0x7f74173f2450> ]
20150723 14:42:23.315 : FAIL : TypeError: 'unicode' object is not callable
20150723 14:42:23.316 : DEBUG :
Traceback (most recent call last):
File "/home/andrii/projects/automated-tests/library/keywords/element_keywords.py", line 88, in wait_until_result
raise thrown_exception
20150723 14:42:23.317 : TRACE : Arguments: [ ]
20150723 14:42:23.317 : DEBUG : DELETE http://127.0.0.1:50355/hub/session/ee7b5402-a2fc-47fc-ade3-38c2c28cc208 {"sessionId": "ee7b5402-a2fc-47fc-ade3-38c2c28cc208"}
20150723 14:42:23.323 : DEBUG : Finished Request
【问题讨论】:
-
你没有给我们所有的信息,我怀疑你有一个名为
normal_keyword的变量已经设置为unicode -
我试图简化代码,所以它只包含可调用部分。但我绝对没有变量 Normal 关键字(在我的情况下 - 没有与可调用变量同名的变量)。
-
@Minras 我认为如果您提供完整的回溯和您的代码会很好
-
@VigneshKalai,我在问题末尾添加了真实代码。
-
@Minras 你的完整追溯怎么样
标签: python robotframework