*** Settings ***
Library SeleniumLibrary
Library OperatingSystem
Suite Setup Suite Setup Tasks
Suite Teardown Close All Browsers
*** Variables ***
${URL} https://www.chase.com
${OUTPUTDIR} results
*** Test Cases ***
Login To Chase
[Documentation] Log in to Chase using environment variables for credentials.
Click Sign In
Input Username
Input Password
Submit Login
Wait For Account Dashboard
*** Keywords ***
Suite Setup Tasks
Log Debug Variables
Open Browser To Chase
Log Debug Variables
${debug_pause}= Get Environment Variable DEBUG_PAUSE 0
Set Suite Variable ${DEBUG_PAUSE} ${debug_pause}
${username}= Get Environment Variable CHASE_USER
${password}= Get Environment Variable CHASE_PASS
Set Suite Variable ${USERNAME} ${username}
${pw_list}= Create List ${password}
Set Suite Variable ${PASSWORD_LIST} ${pw_list}
Run Keyword If '${USERNAME}' == '' Fail Environment variable CHASE_USER is not set
Run Keyword If '${PASSWORD}' == '' Fail Environment variable CHASE_PASS is not set
Log To Console DEBUG_PAUSE=${DEBUG_PAUSE}
Log DEBUG_PAUSE=${DEBUG_PAUSE} INFO
Log To Console USERNAME=${USERNAME}
Run Keyword If '${PASSWORD}' == '' Log To Console PASSWORD is empty
Run Keyword Unless '${PASSWORD}' == '' Log To Console PASSWORD is set
Open Browser To Chase
Open Browser ${URL} chrome
Maximize Browser Window
Wait Until Page Contains Element id=signin-button timeout=20s
Click Sign In
${clicked}= Run Keyword And Return Status Click Element id=signin-button
Run Keyword If '${clicked}' == 'False' Execute JavaScript var el=document.getElementById('signin-button'); if(el){el.click();}
Wait Until Element Is Visible xpath=//input[contains(@id,'user') or contains(@name,'user') or contains(@placeholder,'Username')] timeout=20s
Wait For Input
Input Username
Input Text xpath=//input[contains(@id,'user') or contains(@name,'user') or contains(@placeholder,'Username')] ${USERNAME}
Capture Page Screenshot ${OUTPUTDIR}/after_username.png
Wait For Input
Input Password
${pw_to_use}= Set Variable ${PASSWORD_LIST}[0]
Input Text xpath=//input[contains(@id,'pass') or contains(@name,'pass') or contains(@placeholder,'Password')] ${pw_to_use}
Capture Page Screenshot ${OUTPUTDIR}/after_password.png
Wait For Input
Click Remember Me
Submit Login
Click Button xpath=//button[contains(., 'Sign in') or contains(., 'Sign In')]
# Adjust the post-login wait condition to a reliable page element for your account
Wait Until Page Contains Account overview timeout=15s
Wait For Input
Wait For Account Dashboard
# Fallback check; update selector/text as needed
Run Keyword And Ignore Error Wait Until Page Contains Element xpath=//h1 | //div[contains(., 'Account') or contains(., 'Overview')] timeout=15s
Wait For Input
Run Keyword If '${DEBUG_PAUSE}' == '1' Sleep 5s
Click Remember Me
${clicked}= Run Keyword And Return Status Click Element xpath=//input[@type='checkbox' and (contains(@id,'remember') or contains(@name,'remember') or contains(@aria-label,'Remember') or contains(@placeholder,'Remember') or contains(@data-testid,'remember'))]
Run Keyword If '${clicked}' == 'False' Click Element xpath=//label[contains(., 'Remember') or contains(., 'Remember me')]
Run Keyword If '${clicked}' == 'False' Execute JavaScript var el=document.querySelector("input[type='checkbox']"); if(el && (el.id.indexOf('remember')>-1 || el.name.indexOf('remember')>-1)){el.click();}