0

我想为 1 次创建一条路径以保存测试示例 1 中的屏幕截图我的路径是

*** Setting ***
Library        Selenium2Library   screenshot_root_directory=/Users/person/Documents/testrobot/screenshot30-01-2017 12-00-00

第二我的路是

*** Setting ***
Library        Selenium2Library screenshot_root_directory=/Users/person/Documents/testrobot/screenshot30-01-2017 12-30-00

如何设置动态路径

我的机器人代码

 *** Setting ***
Library        Selenium2Library   screenshot_root_directory=/Users/person/Documents/testrobot/screenshot
Library        DateTime
*** Variables ***

*** Keywords ***

*** Test Cases ***

谢谢你

4

2 回答 2

1

首先指定要保存屏幕截图的目录 - 并将 persist 设置为 False 因为它是一次性的 - 对于一个特定的测试:

Set Screenshot Directory    /Users/person/Documents/testrobot/screenshot30-01-2017 12-00-00    False

然后完成屏幕截图 - 并检查它是否存在:

${ScreenShotOne}    Capture Page Screenshot    Screenshot1.png
File Should Exist    /Users/person/Documents/testrobot/screenshot30-01-2017 12-00-00/Screenshot1.png

然后,更改另一个屏幕截图的目录:

Set Screenshot Directory    /Users/person/Documents/testrobot/screenshot30-01-2017 12-30-00

然后完成与上面相同的过程:

${ScreenShotTwo}    Capture Page Screenshot    Screenshot2.png
File Should Exist   /Users/person/Documents/testrobot/screenshot30-01-2017 12-30-00/Screenshot2.png

您也可以在每次创建屏幕截图时设置路径:

${ScreenShotTwo}    Capture Page Screenshot    /Users/person/Documents/testrobot/screenshot30-01-2017 12-30-00/Screenshot2.png    False
File Should Exist   /Users/person/Documents/testrobot/screenshot30-01-2017 12-30-00/Screenshot2.png

所有这些都可以在 Selenium2Library 文档中找到:

关键字:捕获页面截图
关键字:设置屏幕截图目录

于 2017-01-30T09:18:47.697 回答
1

@Goralight 和我在同一页面上,但我创建了全局变量以在关键字中保存路径

*** Setting ***
Library        Selenium2Library
Library        DateTime

*** Variables ***
${WEB}  xxx.xxxxx.xxxx
${BROWSER}  chrome
${TYPE OF FILE}  png
*** Keywords ***

Get DateTime
  ${date1}=  Get Current Date  result_format=%Y-%m-%d %H-%M-%S
  [Return]     ${date1}

Open Web
  Open Browser  ${WEB}   ${BROWSER}
  Maximize Browser Window
  ${Date}=  Get DateTime
  Set Global Variable  ${Path}  /Users/person/Documents/testrobot/screenshot/${Date}

Close Web
  Close Window

Screenshot
  [Arguments]  ${filename}
  Set Screenshot Directory  ${Path}
  Wait Until Page Contains  Element
  # ${datetime}=  Get DateTime
  Capture Page Screenshot  ${filename}.${TYPE OF FILE}
  Log To Console  ${\n}Screenshot


*** Test Cases ***

[1] Click Home
  Open Web

我的文件夹结果是

点击

于 2017-01-30T09:46:50.227 回答