# author:qinguanglei
# ddate:2023/11/14 16:47
# 购买多个序列号商品
import os
import time

from pip._internal.commands import inspect
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

from guke.common.logger import log

from guke.common.read_yaml import get_value_by_filed_from_yaml


def test_buy_nonseq_commodities():
    option = webdriver.ChromeOptions()
    # option.add_experimental_option("detach", True) # 设置不要自动关闭浏览器
    # 获取驱动器
    driver = webdriver.Chrome(options=option)
    # 最大化页面
    driver.maximize_window()
    driver.get("http://scdev.cmic.com.cn:8088/beta/")
    driver.implicitly_wait(10)
    # 获取公共信息，注意公共信息的内容在案例的同级目录下
    # 获取本案例的绝对路径，绝对路径的目录就是该案例的同级目录
    # 需要知道哪个文件名
    direction = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data.yaml')
    # 取文件中的user栏位
    account = get_value_by_filed_from_yaml(direction, 'account')
    # 取文件中的password栏位
    password = get_value_by_filed_from_yaml(direction, 'password')
    log.info('获取的密码为%s',  password)



    root_dir = os.path.abspath(os.sep)
    print(root_dir)


    # BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    # user =
    driver.find_element(By.ID, 'input1').clear()
    driver.find_element(By.ID, 'input1').send_keys(account)
    driver.find_element(By.ID, 'input2').clear()
    driver.find_element(By.ID, 'input2').send_keys(password)
    driver.find_element(By.ID, 'input2').send_keys(Keys.ENTER)
    time.sleep(1)
