简体   繁体   中英

How to dynamic path for screenshot in Setting section of robot framework

i want to create one path for 1 time for save screenshot from testing Example 1st my path is

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

2nd my path is

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

How to set dynamic path

my robot code

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

*** Keywords ***

*** Test Cases ***

thank you

First specify the directory which you want the screen shot to be saved in - and set persist to False as it is a one time thing - for one particular test:

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

Then complete the the Screenshot - and check it exists:

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

Then, change the direcotry for the other Screenshot:

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

And then complete the same process you did above:

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

You could also just set the path, every time you create the screenshot:

${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

All this was found within the Selenium2Library Documentation:

Keyword: Capture Page Screenshot
Keyword: Set Screenshot Directory

@Goralight and me on the same page but i create global variable for saving path in Keyword

*** 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

my folder result is

click

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM