Search code examples
pythonpython-2.7robotframeworkweb-testingselenium2library

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


Solution

  • @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