*** Settings ***

Documentation    Generally useful keywords for Bika tests.
...              To include this file, use this:
...              *** settings ***
...              Resource  keywords.txt


*** Keywords ***

Log in
    [Arguments]  ${userid}  ${password}

    Go to                          http://localhost:55001/plone/login_form

    # cheeky but I want, so sneaked in here
    Maximize Browser Window

    Page should contain element     __ac_name
    Page should contain element     __ac_password
    Page should contain button      Log in
    Input text                      __ac_name      ${userid}
    Input text                      __ac_password  ${password}
    Click Button  Log in
    sleep     3

Log out
    Go to                          http://localhost:55001/plone/logout
    Wait until page contains       You are now logged out


Select from dropdown
    [Arguments]        ${locator}
    ...                ${search_text}=
    ...                ${item_number}=1
    Input text         ${locator}  ${search_text}
    sleep    1
    Click Element      xpath=//div[contains(@class,'cg-colItem')][${item_number}]
    sleep    1


SelectDate
    [Arguments]  ${Element}=
    ...          ${Date}=
    ${Date} =            Convert To Integer    ${Date}
    ${Date} =            Convert To String     ${Date}
    sleep                0.5
    Click Element  ${Element}
    Wait Until Page Contains Element  ui-datepicker-div
    sleep                0.5
    Click Link  ${Date}


SelectPrevMonthDate
    [Arguments]  ${Element}=
    ...          ${Date}=
    Click Element        ${Element}
    Wait Until Page Contains Element  ui-datepicker-div
    Click Element        xpath=//div[@id='ui-datepicker-div']//a[@title='Prev']
    sleep                0.5
    ${Date} =            Convert To Integer    ${Date}
    ${Date} =            Convert To String     ${Date}
    Click Link           ${Date}
    sleep                0.5

SelectNextMonthDate
    [Arguments]  ${Element}=
    ...          ${Date}=
    Click Element        ${Element}
    Wait Until Page Contains Element  ui-datepicker-div
    Click Element        xpath=//div[@id='ui-datepicker-div']//a[@title='Next']
    sleep                0.5
    ${Date} =            Convert To Integer    ${Date}
    ${Date} =            Convert To String     ${Date}
    Click Link           ${Date}
    sleep                0.5

Execute transition ${transition} on items in form_id ${form_id}
    Select checkbox     xpath=//input[@id='${form_id}_select_all']
    Set Selenium Timeout        30
    Click Element       ${transition}_transition
    Set Selenium Timeout        10

Shleep
    [Arguments]  ${amount}=
    ...          ${comment}=
    Log  Sleeping ${amount}: ${comment}  WARN
    sleep  ${amount}

Wait For Ajax
    Wait for Condition   return window.jQuery.active == 0;
