示例#1
0
class TestCase04UserCenterModifyPassword(unittest.TestCase):
    # 测试个人中心修改密码
    def setUp(self):
        self.driver = AutomateDriver()
        self.base_url = self.driver.base_url
        self.base_page = BasePage(self.driver, self.base_url)
        self.login_page = LoginPage(self.driver, self.base_url)
        self.user_center = UserCenter(self.driver, self.base_url)
        self.log_in_page_read_csv = LogInPageReadCsv()
        self.user_center_read_csv = UserCenterReadCsv()
        self.driver.set_window_max()
        self.connect_sql = ConnectSql()
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.driver.wait(1)

        # 打开途强在线首页-登录页
        self.base_page.open_page()
        sleep(1)
        # 登录账号
        self.login_page.test_user_login()

    def tearDown(self):
        self.driver.quit_browser()

    def test_user_center_modify_password(self):
        # 通过csv测试修改密码功能

        # 点击打开修改密码框
        self.user_center.click_edit_password()

        csv_file = self.user_center_read_csv.read_csv(
            "modify_password_exception.csv")
        csv_data = csv.reader(csv_file)
        for row in csv_data:
            data = {
                "old_password": row[0],
                "new_password": row[1],
                "new_password2": row[2],
                "pwd_prompt": row[3],
            }

            text = self.user_center.get_modify_pwd_exception_prompt(
                data['old_password'], data['new_password'],
                data['new_password2'])

            self.assertIn(data["pwd_prompt"], text, "修改密码,错误提示语显示不一致")

        csv_file.close()

        # 关闭修改密码框
        self.user_center.click_edit_password_close()

        # 退出登录
        self.user_center.logout()
class TestCase03UserCenterModifyPassword(unittest.TestCase):
    # 测试个人中心修改密码
    def setUp(self):
        self.driver = AutomateDriver()
        self.base_url = self.driver.base_url
        self.base_page = BasePage(self.driver, self.base_url)
        self.login_page = LoginPage(self.driver, self.base_url)
        self.user_center = UserCenter(self.driver, self.base_url)
        self.log_in_page_read_csv = LogInPageReadCsv()
        self.user_center_read_csv = UserCenterReadCsv()
        self.driver.set_window_max()
        self.connect_sql = ConnectSql()
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.driver.wait(1)

    def tearDown(self):
        self.driver.quit_browser()

    def test_user_center_modify_password(self):
        # 通过csv测试修改密码功能

        csv_file = self.user_center_read_csv.read_csv(
            'user_to_modify_password.csv')
        csv_data = csv.reader(csv_file)
        for row in csv_data:
            user_to_modify_password = {
                "account": row[0],
                "old_passwd": row[1],
                "new_passwd": row[2],
            }

            # 打开途强在线首页-登录页
            self.base_page.open_page()
            sleep(1)
            # 登录账号
            self.login_page.user_login(user_to_modify_password['account'],
                                       user_to_modify_password['old_passwd'])

            # 修改密码
            self.user_center.click_edit_password()
            self.user_center.input_old_password(
                user_to_modify_password['old_passwd'])
            self.user_center.input_new_password(
                user_to_modify_password['new_passwd'])
            self.user_center.input_password_again(
                user_to_modify_password['new_passwd'])

            # 确认
            self.user_center.click_edit_password_confirm()
            self.driver.wait()

            # 用旧密码登录,验证提示
            self.login_page.user_login(user_to_modify_password['account'],
                                       user_to_modify_password['old_passwd'])
            exception_text = self.login_page.get_exception_text()
            self.assertEqual('登录密码验证错误', exception_text)

            self.driver.wait()

            # 用新密码登录,验证是否修改成功
            self.login_page.user_login(user_to_modify_password['account'],
                                       user_to_modify_password['new_passwd'])
            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

            # 从数据库获取登录账号的用户名
            account_info = self.user_center.get_account_info_by_sql(
                user_to_modify_password['account'])
            print(account_info)
            account_name = account_info[1]

            self.assertEqual(account_name, username, '登录成功后招呼栏的用户名错误')

            # 退出登录
            self.user_center.logout()

        csv_file.close()