
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep


#username & password for login
login_data = {"name": "mani@aaho.in", "password": "whvc.1900"}


def get_browser():
    #browser = webdriver.Chrome()
    browser = webdriver.Safari()
    browser.maximize_window()
    return browser


def login(browser):
    #login url
    browser.get("http://127.0.0.1:8000/login/")
    #finding login fields
    userNameElem = browser.find_element_by_css_selector("input[type='text']")
    passwordElem = browser.find_element_by_css_selector("input[type='password']")
    #filling login credentials
    userNameElem.send_keys(login_data["name"])
    userNameElem.send_keys(Keys.ENTER)
    sleep(1)
    passwordElem.send_keys(login_data["password"])
    passwordElem.send_keys(Keys.ENTER)
    sleep(1)
    #clicking login button
    logInButton = browser.find_element_by_tag_name("button")
    logInButton.click()
    sleep(5)
    return browser
