import time

from selenium.webdriver.common.by import By

from Base.BasePage import BasePage
from common.untils import DriverTools
from config import user_name, password
from paga.CodePage import Code
from paga.CreatePage import Create
from paga.LoginPage import Login


class Give(BasePage):
    def __init__(self):
        super().__init__('web')
        # 添加服务
        self.reader_increase = (By.XPATH, "/html/body/div[1]/div/section/div[1]/div[2]/div/div[2]/div[2]/div["
                                          "2]/div/div[1]/div[1]/div/button[1]/span")
        # AI能力
        self.reader_AI = (By.ID, "rc-tabs-2-tab-9")
        # 全选
        self.reader_all = (By.XPATH, "//div[@class='ant-table-selection']//input[@class='ant-checkbox-input']")
        # 第2页
        self.reader_page1 = (By.XPATH, "//a[contains(text(),'2')]")
        # 第3页
        self.reader_page2 = (By.XPATH, "//a[contains(text(),'3')]")
        # 第4页
        self.reader_page3 = (By.XPATH, "//a[contains(text(),'4')]")
        # 第5页
        self.reader_page4 = (By.XPATH, "//a[contains(text(),'5')]")
        # 确定按钮
        self.reader_determine = (By.XPATH, "/html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/div[2]/div[3]/button["
                                           "2]/span[1]")
        # 保存按钮
        self.reader_save = (By.XPATH, "//button[@class='ant-btn ant-btn-primary ant-btn-lg save-btn']//span")

    def give(self):
        self.find_ele(self.reader_increase).click()
        time.sleep(1)
        self.find_ele(self.reader_AI).click()
        time.sleep(1)
        self.find_ele(self.reader_all).click()
        time.sleep(1)
        self.find_ele(self.reader_page1).click()
        time.sleep(1)
        self.find_ele(self.reader_all).click()
        time.sleep(1)
        self.find_ele(self.reader_page2).click()
        time.sleep(1)
        self.find_ele(self.reader_all).click()
        time.sleep(1)
        self.find_ele(self.reader_page3).click()
        time.sleep(1)
        self.find_ele(self.reader_all).click()
        time.sleep(1)
        self.find_ele(self.reader_page4).click()
        time.sleep(1)
        self.find_ele(self.reader_all).click()
        time.sleep(1)
        self.find_ele(self.reader_determine).click()
        time.sleep(1)
        self.find_ele(self.reader_save).click()


if __name__ == '__main__':
    DriverTools.get_driver().get('https://rays7.5rs.me/login')
    Login().login(user_name,password)
    time.sleep(3)
    Create().create()
    Code().code()
    Give().give()
