Robot Framework 运行关键字和预期错误

nhr*_*cpt 1 python python-2.7 robotframework

在 Robot Framework 中执行关键字“运行关键字并期望错误”时,我面临以下问题。

首先我试过这个:

run keyword and expect error    InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated  Input Text  ${indFNPatientHealth Link}  RCIGM_FN
Run Code Online (Sandbox Code Playgroud)

它失败了。回溯是:

17:44:01.894    FAIL    InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated
  (Session info: chrome=60.0.3112.101)
  (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)
17:44:01.894    FAIL    Expected error 'InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated' but got 'InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated
  (Session info: chrome=60.0.3112.101)
  (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)
'.
Run Code Online (Sandbox Code Playgroud)

所以我修改了复制全文的预期错误,包括会话信息和驱动程序信息。更新后的代码是:

run keyword and expect error    InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated \ \ (Session info: chrome=60.0.3112.101) \ \ (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)    Input Text    ${indFNPatientHealth Link}    RCIGM_FN
Run Code Online (Sandbox Code Playgroud)

它又失败了。

17:31:59.291    FAIL    InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated
  (Session info: chrome=60.0.3112.101)
  (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)
17:31:59.291    FAIL    Expected error 'InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated   (Session info: chrome=60.0.3112.101)   (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)' but got 'InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated
  (Session info: chrome=60.0.3112.101)
  (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)
Run Code Online (Sandbox Code Playgroud)

在此先感谢您对解决此问题的支持。

Ver*_*erv 5

您尝试捕获的字符串很长,可变且包含行跳过。此外,调试数据与您的测试无关。如果我是你,我只会捕获整个消息,传递*Run Keyword And Expect Error然后使用部分字符串匹配关键字来确保我捕获到InvalidElementStateException异常。您也可以将您的消息添加到部分检查中,但删除变量调试数据。

请参阅运行关键字和预期错误

像这样的东西

${msg}=    Run Keyword And Expect Error    *    Input Text    ${indFNPatientHealth Link}    RCIGM_FN
Should Contain    ${msg}    InvalidElementStateException
Run Code Online (Sandbox Code Playgroud)