import pytest
import time
import sys

sys.path.append('..')
from basepage.read_config import ReadConfig
from basepage.browser_engine import BrowserEngine
from basepage.logger import Logger
from basepage import get_engine

project_name = "TestLogin"
logger = Logger(project_name).get_logger()
'''
def setup_function():
    print('setup_function:每个用例开始前都会执行')

def teardown_function():
    print('teardown_function:每个用例结束后都会执行')
'''


@pytest.mark.login
@get_engine(__file__,'LOGIN')
def test_login(engine):
    # engine.init()
    username = engine.get_userInfo('username')
    password = engine.get_userInfo('password')
    url = engine.get_testUrl('URL')
    print(username, password, url)
    logger.info("username: %s" % username)
    logger.info("password :%s" % password)
    logger.info("Open url: %s" % url)

    driver = engine.driver

    tags = driver.find_element_by_xpath('//*[@id="root"]/div/div/div[2]/form/div[1]/div/div/span/span/span')
    # print(tags.text)
    logger.info("tags.text:%s" % tags.text)
    tags.click()
    time.sleep(1)

    driver.find_element_by_xpath('//*[@id="rc-tree-select-list_1"]/ul/li/ul/li[3]/span[1]').click()

    tags2 = driver.find_element_by_xpath('//*[@id="rc-tree-select-list_1"]/ul/li/ul/li[3]/ul/li[3]/span[2]/span')
    # print(tags2.text)
    logger.info("tags2.text:%s" % tags2.text)
    tags2.click()
    time.sleep(1)

    driver.find_element_by_xpath('//*[@id="username"]').send_keys(username)
    driver.find_element_by_xpath('//*[@id="password"]').send_keys(password)
    driver.find_element_by_xpath('//*[@id="root"]/div/div/div[2]/form/div[4]/div/div/span/button').click()

    time.sleep(10)
    driver.quit()




