コード例 #1
0
class TestLogin():
    def setup_class(self):
        # 实例化 登录页面类
        self.login = PageLogin(get_driver())

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

    def test_login(self):
        # 登录操作
        self.login.page_login("18610453007", "123456")
        try:
            assert "itheima" in self.login.page_get_nickname()
            allure.attach('断言成功描述')
            # 退出操作
            self.login.page_login_logout()
        except:
            # 截图
            self.login.base_getImage()
            with open("./Image/faild.png", "rb") as f:
                allure.attach("失败描述:", f.read(), allure.attach_type.PNG)

            # 抛异常
            raise
コード例 #2
0
class TestLogin():
    def setup_class(self):
        # 实例化PageLogin
        self.login = PageLogin(get_driver())

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

    def test_login(self):
        # 登录操作
        self.login.page_login("13331172859", "123456")
        try:
            # 断言登录是否成功
            assert "lj0918" in self.login.page_get_nickname()
            print('登录成功')
            # 退出操作
            self.login.page_login_logout()
        except:
            # 失败 截图
            self.login.base_getimage()
            with open('./Image/failed.png', 'rb') as f:
                allure.attach('登录失败描述:', f.read(), allure.attach_type.PNG)
            # 抛出异常
            raise
コード例 #3
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.
コード例 #4
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
コード例 #5
0
ファイル: test_login.py プロジェクト: LJ0918/BaiNianALDZ
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
コード例 #6
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
コード例 #7
0
class TestLogin:
    driver = None

    # # 初始化方法
    def setup_class(self):
        self.driver = GetDriver().get_driver()
        self.login = PageLogin(self.driver)

    # 关闭浏览器
    # def teardown_class(self):
    #     GetDriver().quit_driver()

    # 登录
    @pytest.mark.parametrize('args', data_with_key("test_login"))
    @allure.testcase("账号密码登录用例")
    def test_login(self, args):
        username = args["username"]
        password = args["password"]
        code = args["code"]
        expect = args["expect"]
        self.login.page_login(username, password, code)
        nickname = self.login.page_get_nickname()
コード例 #8
0
ファイル: test_login.py プロジェクト: yhtpcl/BaiNian
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):
        # 默认为TRUE,如果expect为TRUE代表有值也就是正向用例,需要进行以下操作
        # 通过模拟功能测试得出思路
        if expect:
            # 进行异常捕获
            try:
                #  输入用户名
                self.login.page_input_username(username)

                # 输入密码
                self.login.page_input_pwd(password)

        #         点击登录
                self.login.page_click_dl_btn()

        #         断言登录后的名称
                assert expect in self.login.page_get_nickname()
                allure.attach("登录状态: ","登录成功")

        #         退出登录
                self.login.page_exit()

        #         点击我的
                self.login.page_click_me()

        #         点击已有账户立即登录
                self.login.page_click_info()

            #     如果出现异常就截图保存
            except:
                # 调用截图方法
                self.login.base_get_screenshot()
                # 打开截图
                with open("./Image/filed.png","rb") as f:
                    # 写入报告中,三个参数:描述,读取文件,写入报告格式声明   png
                    allure.attach("登录失败描述",f.read(),allure.attach_type.PNG)
                raise
        #     相反也就是expect为空,对应的就是逆向,需要执行的操作
        else:
            try:
                # 输入用户名

                self.login.page_input_username(username)
                # 输入密码:
                self.login.page_input_pwd(password)
                # 点击登录
                self.login.page_click_dl_btn()
                # 断言toast_expect消息
                # 调用获取toast消息方法,动态判断登录后的是否相等
                assert toast_expect in self.login.base_get_toast(toast_expect)
                allure.attach("登录状态","逆向断言成功")
            except:
                self.login.base_get_screenshot()
                with open("./Image/filed.png","rb") as f :
                    allure.attach("登录失败描述",f.read(),allure.attach_type.PNG)
                raise