*** Settings ***
Suite Setup     Run Keywords  Go To Front Page  Set Info Loglevel
Suite Teardown  Set Debug Loglevel
Test Teardown   Register Keyword to Run on Failure  Nothing
Resource        ../resource.txt

*** Variables ***
${FAILURE MESSAGE}  Page should not have contained text 'needle'
${FAILURE}  REGEXP: F+AIL ${FAILURE MESSAGE}  # This needs to be reqexp to prevent it to expect test to fail

*** Test Cases ***
Capture Screenshot On Failure
    [Documentation]  LOG 1 Capture Screenshot will be run on failure. LOG 2:2 NONE LOG 3.1:1 REGEXP: </td></tr><tr><td colspan="3"><a href="selenium-screenshot-\\d.png"><img src="selenium-screenshot-\\d.png" width="800px"></a> LOG 3.1:3 NONE
    Register Keyword to Run on Failure  Capture Screenshot
    Page Should Contain  needle
    Run Keyword And Expect Error  ${FAILURE MESSAGE}  Page Should Not Contain  needle  loglevel=None

Disable Run on Failure
    [Documentation]  LOG 1 No keyword will be run on failure. LOG 2.1:2 NONE
    Register Keyword to Run On Failure  Nothing
    Run Keyword And Expect Error  ${FAILURE MESSAGE}  Page Should Not Contain  needle  loglevel=None

Run on Failure Returns Previous Value
    ${old}=  Register Keyword to Run on Failure  log_source
    Should Be Equal  ${old}  No keyword
    ${old}=  Register Keyword to Run on Failure  Capture Screenshot
    Should Be Equal  ${old}  Log Source
    ${old}=  Register Keyword to Run on Failure  ${old}
    Should Be Equal  ${old}  Capture Screenshot

Run Only Once per Failure
    [Documentation]  LOG 3.1:2 REGEXP: </td></tr><tr><td colspan="3"><a href="selenium-screenshot-\\d.png"><img src="selenium-screenshot-\\d.png" width="800px"></a> LOG 3.1:4 NONE
    [Setup]  Go To Page "frames/frameset.html"
    Register Keyword to Run on Failure  Capture Screenshot
    Run Keyword And Expect Error  Page should have contained text 'Not found' but did not  Frame Should Contain  right  Not found  loglevel=NONE

