*** Settings ***
Documentation       A resource file containing the application specific keywords
...                 that create our own domain specific language. This resource
...                 implements keywords for testing HTML version of the test
...                 application.
Library             Selenium2Library

*** Keywords ***
Unique name
    [Arguments]    ${name}
    ${unique}      Get Time    epoch
    [Return]       ${name}_${unique}

Log In As
    [Arguments]                  ${username}    ${password}        ${server_id}
    Select From List By Value    id_server      ${server_id}
    Input Text                   username       ${username}
    Input Text                   password       ${password}
    Click Button                 Login

Log In As Root
    Log In As       ${ROOT USERNAME}        ${ROOT PASSWORD}        ${SERVER_ID}

Open Browser To Login Page
    [Arguments]                 ${main url}     ${login url}
    Open Browser                ${main url}     ${BROWSER}          remote_url=${REMOTE_URL}    desired_capabilities=${DC}
    Set Selenium Speed          ${DELAY}
    Page Should Be Open         ${login url}    OMERO.web - Login

Open Browser And Log In As User
    Open Browser To Login Page      ${LOGIN URL}          ${LOGIN URL}
    Log In As                       ${USERNAME}             ${PASSWORD}         ${SERVER_ID}
    Page Should Be Open             ${WELCOME URL}          Webclient

Open Browser To Webadmin And Log In As Root
    Open Browser To Login Page      ${WEBADMIN WELCOME URL}     ${WEBADMIN LOGIN URL}
    Log In As Root
    Page Should Be Open             ${USERS URL}                OMERO Users

Log Out
    Click Element                   xpath=//div[@id='show_user_dropdown']/span
    Click Link                      link=Logout
    Page Should Be Open             ${LOGIN URL}                OMERO.web - Login

Logout and Teardown
    Log Out
    Close all browsers

Page Should Be Open
    [Arguments]         ${page url}         ${title}=${None}
    Location Should Be  ${page url}
    Run Keyword If      '${title}'!='None'  Title Should Be     ${title}

Page Should Contain Input Field
    [Arguments]                     ${label}  ${value}
    Page Should Contain             ${label}
    Page Should Contain Textfield   name=${value}

Page Should Contain Choice Field
    [Arguments]                     ${label}  ${name}
    Page Should Contain             ${label}
    Page Should Contain Textfield   ${name}

Page Should Contain Password Field
    [Arguments]                     ${label}  ${name}
    Page Should Contain             ${label}
    Page Should Contain Element     name=${name}

Page Should Contain Checkbox Field
    [Arguments]                     ${label}        ${name}                             ${selected}=${False}
    Page Should Contain             ${label}
    Page Should Contain Checkbox    ${name}
    Run Keyword If                  ${selected}     Checkbox Should Be Selected         ${name}
    ...                             ELSE            Checkbox Should Not Be Selected     ${name}

Page Should Contain Radio Field
    [Arguments]                         ${label}    ${name}     ${value}
    Page Should Contain                 ${label}
    Page Should Contain Radio Button    ${name}
    Radio Button Should Be Set To       ${name}     ${value}
