import time

import pytest

from common.cutils import get_text
from common.untils import DriverTools
from config import user_name, password
from paga.CodePage import Code
from paga.CreatePage import Create
from paga.DelPage import Del
from paga.GivePage import Give
from paga.LoginPage import Login


class TestCreate:
    # 类前置
    def setup_class(self):
        self.login = Login()
        self.create = Create()
        self.code = Code()
        self.give = Give()
        self.delete = Del()

    def setup_method(self):
        self.driver = DriverTools.get_driver().get('https://rays7.5rs.me/login')

    # 类后置
    def teardown_class(self):
        DriverTools.quit_driver()

    # 创建书刊流程
    def test_test1(self):
        self.login.login(user_name, password)
        time.sleep(3)
        self.create.create()
        self.code.code()
        self.give.give()
        self.delete.delete()
        result = get_text(self.delete.person_name)
        expect = "RAYS现代纸书"
        assert expect == result
        print(expect)

    @pytest.mark.parametrize("user,password,result",
                             [("黑泽爽子", "Rmb11111", "密码错误"), ("鉴湖分社1", "Rmb88888", "账号不存在")])
    def test_add(self, user, password, result):
        self.login.login(user, password)
        time.sleep(1)
        a = get_text(self.login.login_info)
        assert result == a
        print(a)
