*** Settings ***

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


*** Keywords ***

Start browser
#    Open browser  ${PLONEURL}/login_form
    Open browser  ${PLONEURL}/login_form   browser=chrome
    Set selenium speed  ${SELENIUM_SPEED}
    # A large window, so that debug screenshots are sensibly sized
    set window size   1920    1080

Log in
    [Arguments]  ${userid}  ${password}
    Go to                          http://localhost:55001/plone/login_form
    sleep   0.1
    Input text                      __ac_name      ${userid}
    sleep   0.1
    Input text                      __ac_password  ${password}
    Click Button  Log in


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
    wait until page contains element    ${locator}
    Input text                          ${locator}   \
    Press Key                           ${locator}   \\9
    sleep           0.3
    Input text                          ${locator}  ${search_text}
    wait until page contains element    xpath=//div[contains(@class,'cg-colItem')][${item_number}]
    sleep           0.5
    Click Element                       xpath=//div[contains(@class,'cg-colItem')][${item_number}]
    sleep           0.5


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


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

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

Execute transition ${transition} on item ${ar_id} in ARList
    [Documentation]  Tranistion the specific ar from an AR List.
    Select checkbox     xpath=//input[@item_title="${ar_id}"]
    Set Selenium Timeout        30
    Click Element       ${transition}_transition
    Set Selenium Timeout        10

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

Execute transition ${transition} inside ClientARView/ManageResults
    [Documentation]  Tranistion the element using the right-up label
    ...              tranistion could be-> sample, receive, verify, publish
    Click Element  css=a[title="Change the state of this item"]
    Click Element  workflow-transition-${transition}

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

Create a contact
    [Documentation]  Function to create a contact from a client.
    [Arguments]  ${Client}
    ...          ${FirstName}
    ...          ${Surname}
    Go to             ${PLONEURL}/clients/
    click link                  ${Client}
    Wait until page contains element    css=body.portaltype-client
    click link                  link=Contacts
    click link                  link=Add
    Input text                  Firstname  ${FirstName}
    Input text                  Surname    ${Surname}
    Click Button                Save
    Wait until page contains    Changes saved

Enable Sampling Workflow
    Go to               ${PLONEURL}/bika_setup/edit
    Click Link          id=fieldsetlegend-analyses
    Select Checkbox     id=SamplingWorkflowEnabled
    Click Button        Save
    Wait until page contains    Changes saved.

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

Disable stickers
    [Documentation]  Disable the print page after create an AR.
    Go to            ${PLONEURL}/bika_setup/edit
    click element    fieldsetlegend-stickers
    Select from list   AutoPrintStickers  None
    Click Button                Save
