Esempio n. 1
0
class TestLogin():
    def get_data(self):
        datas = ReadYaml("login.yaml").read_yaml()
        print(datas)
        arrs = []
        for data in datas.values():
            print(data)
            arrs.append((data.get("username"), data.get("password"), data.get("expext"), data.get("toast_except")))
        return arrs


    def setup_class(self):
        self.login= PageLogin(get_driver())

    def teardown_class(self):
        self.login.driver.quit()
    @pytest.mark.parametrize("username","password","expext","toast_expext",get_data())
    def test_login(self,username,password,expext,toast_expext):

        if expext:
            try:
                self.login.page_input_user(username)
                self.login.page_input_pwd(password)
                self.login.page_click_login_btn()
                assert expext in self.login.page_get_nickname()
                # 点击退出
                self.login.
Esempio n. 2
0
class TestLogin():
    def setup_class(self):
        # 实例化 登录页面类
        self.login = PageLogin(get_driver())
        # 点击我
        self.login.page_click_me()
        # 点击已有账户
        self.login.page_click_info()

    def teardown_class(self):
        # 退出driver驱动
        self.login.driver.quit()

    @pytest.mark.parametrize("username,password,expect,toast_expect",
                             get_data())
    def test_login(self, username, password, expect, toast_expect):
        if expect:
            try:
                # 输入用户名
                self.login.page_input_user(username)
                # 输入密码
                self.login.page_input_pwd(password)
                # 点击登录
                self.login.page_click_login_btn()
                # 断言
                assert expect in self.login.page_get_nickname()
                allure.attach("描述:", "登录成功")
                # 退出操作
                self.login.page_login_logout()
                # 点击我
                self.login.page_click_me()
                # 点击已有账户
                self.login.page_click_info()
            except:
                # 截图
                self.login.base_getImage()
                with open("./Image/faild.png", "rb") as f:
                    allure.attach("失败描述:", f.read(), allure.attach_type.PNG)
                # 抛异常
                raise

        else:
            try:
                # 输入用户名
                self.login.page_input_user(username)
                # 输入密码
                self.login.page_input_pwd(password)
                # 点击登录
                self.login.page_click_login_btn()
                # 断言
                assert toast_expect in self.login.base_get_toast(toast_expect)
                allure.attach("断言描述", "逆向断言成功")
            except:
                # 截图
                self.login.base_getImage()
                with open("./Image/faild.png", "rb") as f:
                    allure.attach("断言失败描述:", f.read(), allure.attach_type.PNG)
                # 抛异常
                raise
Esempio n. 3
0
class TestLogin():
    def setup_class(self):
        # 实例化 登录页面类
        self.login = PageLogin(get_driver())
        # 点击我的
        self.login.page_click_me()
        # 点击已有账号登录
        self.login.page_click_info()

    def teardown_class(self):
        # 退出driver驱动
        self.login.driver.quit()

    # 参数化
    @pytest.mark.parametrize("username,password,expect,toast_expect",
                             get_data())
    def test_login(self, username, password, expect, toast_expect):
        if expect:
            try:
                # 登录操作
                # self.login.page_login(username,password)
                self.login.page_input_user(username)
                self.login.page_input_pwd(password)
                self.login.page_click_login_btn()
                assert expect in self.login.page_get_nickname()
                allure.attach("登录状态:", "登录成功")
                # 退出操作
                self.login.page_login_logout()
                self.login.page_click_me()
                self.login.page_click_info()
            except:
                # 截图
                self.login.base_getImage()
                with open("./Image/failed.png", "rb") as f:
                    allure.attach("登录失败描述:", f.read(), allure.attach_type.PNG)
                # 抛异常
                raise
        else:
            # 登录 不能使用登录的封装(因为逆向只有第一次需要点击我的和已有账户登录)
            # self.login.page_login(username,password)
            # 以下两个操作放到setup中(以至于正向的操作 也不能使用登录和退出的封装)
            # self.login.page_click_me()
            # self.login.page_click_info()
            self.login.page_input_user(username)
            self.login.page_input_pwd(password)
            self.login.page_click_login_btn()
            try:
                # 断言toast
                assert toast_expect in self.login.base_get_toast(toast_expect)
                allure.attach("登录状态:", "逆向断言成功")
            except:
                # 截图
                self.login.base_getImage()
                with open('./Image/failed.png', 'rb') as f:
                    allure.attach("断言失败描述:", f.read(), allure.attach_type.PNG)
                # 抛异常
                raise
Esempio n. 4
0
class TestLogin():
    #实例化
    def setup_class(self):
        self.login = PageLogin(get_driver())

    def teardown_class(self):
        self.login.driver.quit()

    def test_login(self, username="******", pwd="2131"):
        self.login.page_input_username(username)
        self.login.page_input_pwd(pwd)
        self.login.page_click_login_btn()
Esempio n. 5
0
class TestLogin():
    # 初始化方法
    def setup_class(self):
        # 实例化 PageLogin
        self.login = PageLogin(get_driver())

    # 结束方法
    def teardown_class(self):
        # 关闭驱动对象
        self.login.driver.quit()

    # 测试方法
    def test_login(self, username="******", pwd="123456"):
        # 输入用户名
        self.login.page_input_username(username)
        # 输入密码
        self.login.page_input_password(pwd)
        # 点击登录
        self.login.page_click_login_btn()
Esempio n. 6
0
class TestLogin():
    # 初始化方法
    def setup_class(self):
        # 不加return,获取driver
        # self.driver = get_driver()
        # self.aike = PageLogin(self.driver)

        # 加return:
        self.aike = PageLogin(getdriver())

    # 结束方法
    def teardown_class(self):
        self.aike.driver.quit()

    # 测试方法
    def test_login01(self, username=18672090992, pwd=123456):
        self.aike.page_input_username(username)
        self.aike.page_input_password(pwd)
        self.aike.page_click_login_btn()
Esempio n. 7
0
class TestLogin():
    # 初始化方法
    def setup_class(self):
        # 实例化 PageLogin
        self.login=PageLogin(get_driver())
    # 结束方法
    def teardown_class(self):
        # 关闭驱动对象
        self.login.driver.quit()
    # 测试方法
    @pytest.mark.parametrize("username,password,expect_toast",get_data())
    def test_login(self,username,password,expect_toast):
        # 输入用户名
        self.login.page_input_username(username)
        # 输入密码
        self.login.page_input_password(password)
        print("预期结果为:",expect_toast)
        # 点击登录
        allure.attach("描述:","点击登录按钮")
        self.login.page_click_login_btn()
Esempio n. 8
0
class TestLogin():
    def setup_class(self):
        self.login = PageLogin(get_driver())
        self.login.page_click_me()
        self.login.page_click_info()

    def teardown_class(self):
        self.login.driver.quit()

    @pytest.mark.parametrize("username,password,expect,toast_expect", get_data())
    def test_login(self, username, password, expect, toast_expect):
        if expect:
            try:
                self.login.page_input_user(username)
                self.login.page_input_pwd(password)
                self.login.page_click_login_btn()
                assert expect in self.login.page_get_nickname()
                allure.attach("登录状态:","登陆成功")
                self.login.page_login_logout()
                self.login.page_click_me()
                self.login.page_click_info()
            except:
                #     截图
                self.login.base_getImage()
                with open("./Image/faild.png", "rb") as f:
                    allure.attach("失败描述", f.read(), allure.attach_type.PNG)
                raise
        else:
            try:
                self.login.page_input_user(username)
                self.login.page_input_pwd(password)
                self.login.page_click_login_btn()
                assert toast_expect in self.login.base_get_toast(toast_expect)
                allure.attach("登录状态:", "逆向断言成功")
            except:
                # 截图
                self.login.base_getImage()
                with open("./Image/faild.png", "rb") as f:
                    allure.attach("失败描述", f.read(), allure.attach_type.PNG)
                raise
Esempio n. 9
0
class TestLogin():

    # 初始化方法
    # 把开始运行的前置代码中的driver 实例化 搞一个变量  get_driver中的返回值也就是dreiver给page_login的类,self.login(login就是个变量)就是driver,
    def setup_class(self):
        self.login = PageLogin(get_driver())

    # 结束方法
    def teardown_class(self):
        self.login.driver.quit()

    # 测试方法
    # 函数的参数中,把page_login中输入框的文本写到这边,运用page的方法
    def test_login(self, username="******", pwd="136474"):
        self.login.page_input_username(username)
        self.login.page_input_password(pwd)
        self.login.page_click_login_btn()


# 这是右键运行的方法,不用导包os
# if __name__ == '__main__':
#     pytest.mark("-s test_login.py")
Esempio n. 10
0
class TestLogin():
    # setup
    def setup_class(self):
        # 实例化 pagelogin
        self.login = PageLogin(get_driver())

    # teardown
    def teardown_class(self):
        # 关闭driver
        self.login.driver.quit()

    # 测试方法 test_login
    @allure.step("开始登陆操作")
    def test_login(self, username="******", password="******"):
        # 输入用户名
        self.login.page_input_username(username)
        # 输入密码
        self.login.page_input_password(password)
        # 点击登录
        self.login.page_click_login_btn()
        # 断言
        try:
            result = self.login.page_get_toast("密码错误")
            print("获取出来的toast消息为:", result)
            assert "密码错误" in result

            # 提示断言成功
            print("断言成功!")
        except:
            # 截图
            self.login.base_get_screen()
            with open("./Image/faild.png", "rb") as f:
                # 注意写入图片的方法,还是使用 attach 参数:描述,图片流,图个片格式
                allure.attach("描述", f.read(), allure.attach_type.PNG)
            # 抛异常
            raise