# -*- coding:utf-8 -*-
import unittest
from selenium import webdriver
from PublicScript import *
import json

with open(file='./config.json', mode="r") as f:
    params = json.load(f)
    username = params["user"]
    password = params["pwd"]
    weburl = params["webUrl"]
    print(username)
    print(password)
    print(weburl)
f.close()


class basepage(unittest.TestCase):
    @classmethod
    def set_driver(cls):
        options = webdriver.ChromeOptions()

        options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
        options.add_argument('disable-infobars')

        driver = webdriver.Chrome()
        driver.maximize_window()
        cls.driver = driver
        driver.get(weburl)
        driver.maximize_window()

        present_wait(driver, By.CSS_SELECTOR, '[placeholder="用户名"]').send_keys(username)
        present_wait(driver, By.CSS_SELECTOR, '[placeholder="密码"]').send_keys(password)
        present_wait(driver, By.ID, 'login-button').click()

        # sleep(3)
        # if is_element_load(driver, '//button[@id="vc-messagebox-confirm"]'):
        #     present_wait(driver, By.XPATH, '//button[@id="vc-messagebox-confirm"]').click()

    @classmethod
    def get_driver(cls):
        return cls.driver
