class TestCase04LoginWithTester(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.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_login_exception(self):
        '''测试体验账号登录'''

        # 打开风控首页-登录页
        self.base_page.open_page()

        # 点击“我要体验”
        self.login_page.taste()

        # 判断登录成功后招呼栏的用户名是否正确
        username = self.user_center.get_username()

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

        # 成功退出系统
        sleep(2)
        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()
class TestCase01LoginSuccess(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.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_login_by_csv(self):
        '''通过csv测试用户账户成功登录和成功退出功能'''
        data = ["部门管理", "设备", "贷款客户", "车辆监控中心", "统计报表", "设置"]

        csv_file = self.log_in_page_read_csv.read_csv('login_account.csv')
        csv_data = csv.reader(csv_file)

        for row in csv_data:
            user_to_login = {
                "account": row[0],
                "passwd": row[1],
            }

            # 打开风控首页-登录页
            self.base_page.open_page()
            # 输入用户信息进行登录
            self.login_page.user_login(user_to_login["account"],
                                       user_to_login["passwd"])
            self.driver.wait(1)

            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

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

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

            # 验证模块
            module = self.user_center.get_module_name()
            print(module)
            self.assertEqual(data, module, "用户账号登录,模块显示错误")

            # 取消退出系统
            sleep(2)
            self.user_center.logout_dismiss()

            # 关闭退出系统弹框
            sleep(2)
            self.user_center.logout_close()

            # 成功退出系统
            sleep(2)
            self.user_center.logout()

            # 再次登录判断是否成功退出到登录页并登录成功
            self.login_page.user_login(user_to_login["account"],
                                       user_to_login["passwd"])

            # # 成功退出系统
            sleep(2)
            self.user_center.logout()

        csv_file.close()
class TestCase01OrgManageAddRole(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.role_management = RoleManagement(self.driver, self.base_url)
        self.log_in_page_read_csv = LogInPageReadCsv()
        self.user_center_read_csv = UserCenterReadCsv()
        self.role_management_read_csv = RoleManagementReadCsv()
        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_add_role(self):
        # 通过csv测试新增角色功能

        csv_file = self.role_management_read_csv.read_csv('add_role.csv')
        csv_data = csv.reader(csv_file)
        for row in csv_data:
            add_role = {
                "account": row[0],
                "password": row[1],
                "add_role_name": row[2],
                "add_role_description": row[3],
                "add_role_limit": row[4],
            }

            # 打开风控首页-登录页
            self.base_page.open_page()
            sleep(1)
            # 登录账号
            self.login_page.user_login(add_role['account'],
                                       add_role['password'])

            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

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

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

            # 点击进入角色管理
            self.role_management.click_role_manage()
            # 点击创建角色
            self.role_management.click_add_role()
            # 切入内层frame
            self.role_management.switch_to_2_frame()
            # 输入角色名称
            self.role_management.input_add_role_name(add_role['add_role_name'])
            # 输入角色描述
            self.role_management.input_add_role_description(
                add_role['add_role_description'])
            # 选择角色权限
            self.role_management.choose_add_role_limit(
                add_role['add_role_limit'])
            # 点击取消
            self.role_management.click_add_role_dismiss()
            # 从数据库查询验证角色未创建成功
            new_role_name_01 = self.role_management.get_add_role_by_sql(
                add_role['account'])
            self.assertNotEqual(new_role_name_01, add_role['add_role_name'])
            self.driver.wait(1)

            # 点击创建角色
            self.role_management.click_add_role()
            # 切入内层frame
            self.role_management.switch_to_2_frame()
            # 输入角色名称
            self.role_management.input_add_role_name(add_role['add_role_name'])
            # 输入角色描述
            self.role_management.input_add_role_description(
                add_role['add_role_description'])
            # 选择角色权限
            self.role_management.choose_add_role_limit(
                add_role['add_role_limit'])
            # 点击关闭按钮
            self.role_management.click_add_role_close()

            # 从数据库查询验证角色未创建成功
            new_role_name_02 = self.role_management.get_add_role_by_sql(
                add_role['account'])
            self.assertNotEqual(new_role_name_02, add_role['add_role_name'])
            self.driver.wait(1)

            # 点击创建角色
            self.role_management.click_add_role()
            # 切入内层frame
            self.role_management.switch_to_2_frame()
            # 输入角色名称
            self.role_management.input_add_role_name(add_role['add_role_name'])
            # 输入角色描述
            self.role_management.input_add_role_description(
                add_role['add_role_description'])
            # 选择角色权限
            self.role_management.choose_add_role_limit(
                add_role['add_role_limit'])
            # 点击保存按钮
            self.role_management.click_add_role_save()
            # 跳出最外层frame
            self.role_management.switch_to_default_content()
            # 从数据库查询验证角色创建成功
            new_role_name_03 = self.role_management.get_add_role_by_sql(
                add_role['account'])
            self.assertEqual(new_role_name_03, add_role['add_role_name'])
            self.driver.wait(1)

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

        csv_file.close()
class TestCase05RoleManageSearchRole(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.role_management = RoleManagement(self.driver, self.base_url)
        self.log_in_page_read_csv = LogInPageReadCsv()
        self.user_center_read_csv = UserCenterReadCsv()
        self.role_management_read_csv = RoleManagementReadCsv()
        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_search_role(self):
        # 通过csv测试搜索角色功能

        csv_file = self.role_management_read_csv.read_csv('search_role.csv')
        csv_data = csv.reader(csv_file)
        for row in csv_data:
            search_role = {
                "account": row[0],
                "password": row[1],
                "search_name": row[2],
            }

            # 打开风控首页-登录页
            self.base_page.open_page()
            sleep(1)
            # 登录账号
            self.login_page.user_login(search_role['account'],
                                       search_role['password'])

            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

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

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

            # 点击进入角色管理
            self.role_management.click_role_manage()

            # 输入搜索关键词进行搜索
            self.role_management.search_role(search_role['search_name'])

            # 获取搜索结果
            num = int(self.role_management.get_search_result_num())
            role_name = self.role_management.get_search_result_all()

            # 数据库查询搜索结果
            role_name_by_sql = self.role_management.get_search_result_rolename_by_sql(
                search_role['account'], search_role['search_name'])
            num_by_sql = self.role_management.get_search_result_num_by_sql(
                search_role['account'], search_role['search_name'])

            # 验证搜索结果是否一致
            self.assertEqual(num, num_by_sql)
            self.assertEqual(set(role_name), set(role_name_by_sql))

            # 跳出外层frame
            self.role_management.switch_to_default_content()

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

        csv_file.close()
Exemple #6
0
class TestCase04RoleManageEditRole(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.role_management = RoleManagement(self.driver, self.base_url)
        self.log_in_page_read_csv = LogInPageReadCsv()
        self.user_center_read_csv = UserCenterReadCsv()
        self.role_management_read_csv = RoleManagementReadCsv()
        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_edit_role(self):
        # 通过csv测试修改角色功能

        csv_file = self.role_management_read_csv.read_csv('edit_role_info.csv')
        csv_data = csv.reader(csv_file)
        for row in csv_data:
            edit_role_info = {
                "account": row[0],
                "password": row[1],
                "search_key": row[2],
                "edit_role_name": row[3],
                "edit_role_description": row[4],
                "edit_role_limit": row[5],
            }

            # 打开风控首页-登录页
            self.base_page.open_page()
            sleep(1)
            # 登录账号
            self.login_page.user_login(edit_role_info['account'],
                                       edit_role_info['password'])

            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

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

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

            # 点击进入角色管理
            self.role_management.click_role_manage()

            # 查找11111角色
            self.role_management.search_role(edit_role_info['search_key'])
            # 获取页面查找结果
            search_role_name_01 = self.role_management.get_search_result_one()
            # 查询数据库获取搜索结果
            role_info_00 = self.role_management.get_search_result_by_sql(
                edit_role_info['account'], edit_role_info['search_key'])
            role_name_00 = role_info_00[0]
            role_desc_00 = role_info_00[1]
            self.assertEqual(search_role_name_01, role_name_00)

            # 点击修改
            self.role_management.click_edit_role()
            # 切入内层frame
            self.role_management.switch_to_2_frame()
            # 获取当前显示的角色名称是否与未修改前一致
            current_role_name_01 = self.role_management.get_current_role_name()
            self.assertEqual(search_role_name_01, current_role_name_01)
            # 获取显示的角色描述是否与未修改前一致
            current_role_desc = self.role_management.get_current_role_desc()
            self.assertEqual(role_desc_00, current_role_desc)

            # 输入角色名称
            self.role_management.input_add_role_name(
                edit_role_info['edit_role_name'])
            # 输入角色描述
            self.role_management.input_add_role_description(
                edit_role_info['edit_role_description'])
            # 选择角色权限
            self.role_management.choose_add_role_limit(
                edit_role_info['edit_role_limit'])
            # 点击取消
            self.role_management.click_add_role_dismiss()
            # 数据库查询是否修改失败
            role_info_01 = self.role_management.get_search_result_by_sql(
                edit_role_info['account'], edit_role_info['search_key'])
            role_name_01 = role_info_01[0]
            role_desc_01 = role_info_01[1]
            self.assertEqual(role_name_00, role_name_01)
            self.assertEqual(role_desc_00, role_desc_01)

            # 点击修改
            self.role_management.click_edit_role()
            # 切入内层frame
            self.role_management.switch_to_2_frame()
            # 获取当前显示的角色名称是否与未修改前一致
            current_role_name_01 = self.role_management.get_current_role_name()
            self.assertEqual(search_role_name_01, current_role_name_01)
            # 获取显示的角色描述是否与未修改前一致
            current_role_desc = self.role_management.get_current_role_desc()
            self.assertEqual(role_desc_00, current_role_desc)

            # 输入角色名称
            self.role_management.input_add_role_name(
                edit_role_info['edit_role_name'])
            # 输入角色描述
            self.role_management.input_add_role_description(
                edit_role_info['edit_role_description'])
            # 选择角色权限
            self.role_management.choose_add_role_limit(
                edit_role_info['edit_role_limit'])
            # 点击关闭按钮
            self.role_management.click_add_role_close()
            # 数据库查询是否修改失败
            role_info_02 = self.role_management.get_search_result_by_sql(
                edit_role_info['account'], edit_role_info['search_key'])
            role_name_02 = role_info_02[0]
            role_desc_02 = role_info_02[1]
            self.assertEqual(role_name_00, role_name_02)
            self.assertEqual(role_desc_00, role_desc_02)

            # 点击修改
            self.role_management.click_edit_role()
            # 切入内层frame
            self.role_management.switch_to_2_frame()
            # 获取当前显示的角色名称是否与未修改前一致
            current_role_name_01 = self.role_management.get_current_role_name()
            self.assertEqual(search_role_name_01, current_role_name_01)
            # 获取显示的角色描述是否与未修改前一致
            current_role_desc = self.role_management.get_current_role_desc()
            self.assertEqual(role_desc_00, current_role_desc)

            # 输入角色名称
            self.role_management.input_add_role_name(
                edit_role_info['edit_role_name'])
            # 输入角色描述
            self.role_management.input_add_role_description(
                edit_role_info['edit_role_description'])
            # 选择角色权限
            self.role_management.choose_add_role_limit(
                edit_role_info['edit_role_limit'])
            # 点击保存按钮
            self.role_management.click_add_role_save()
            # 数据库查询是否修改成功
            role_info_03 = self.role_management.get_search_result_by_sql(
                edit_role_info['account'], edit_role_info['edit_role_name'])
            role_name_03 = role_info_03[0]
            role_desc_03 = role_info_03[1]
            self.assertNotEqual(role_name_00, role_name_03)
            self.assertNotEqual(role_desc_00, role_desc_03)

            # 跳出外层frame
            self.role_management.switch_to_default_content()

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

        csv_file.close()
class TestCase01UserManageAddUser(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.user_management = UserManagement(self.driver, self.base_url)
        self.log_in_page_read_csv = LogInPageReadCsv()
        self.user_center_read_csv = UserCenterReadCsv()
        self.user_management_read_csv = UserManagementReadCsv()
        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_add_user(self):
        # 通过csv测试新增用户功能

        csv_file = self.user_management_read_csv.read_csv('add_user.csv')
        csv_data = csv.reader(csv_file)
        for row in csv_data:
            add_user = {
                "account": row[0],
                "password": row[1],
                "add_user_name": row[2],
                "add_login_user": row[3],
                "add_login_passwd": row[4],
                "add_user_phone": row[5],
            }

            # 打开风控首页-登录页
            self.base_page.open_page()
            sleep(1)
            # 登录账号
            self.login_page.user_login(add_user['account'], add_user['password'])

            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

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

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

            # 点击进入用户管理
            self.user_management.click_user_manage()
            # 点击新增用户
            self.user_management.click_add_user()
            # 切入内层frame
            self.user_management.switch_to_2_frame()
            # 输入新增用户名
            self.user_management.input_add_user_name(add_user['add_user_name'])
            # 输入登陆账号
            self.user_management.input_add_login_user(add_user['add_login_user'])
            # 输入登录密码
            self.user_management.input_add_login_passwd(add_user['add_login_passwd'])
            # 输入手机号码
            self.user_management.input_add_user_phone(add_user['add_user_phone'])
            # 分配角色
            self.user_management.input_add_user_role()
            # 选择所属公司部门
            self.user_management.choose_add_user_org()

            # 点击取消
            self.user_management.click_add_user_dismiss()
            # 从数据库查询验证角色未创建成功
            new_user_account_01 = self.user_management.get_add_user_by_sql(add_user['account'])
            self.assertNotEqual(new_user_account_01, add_user['add_login_user'])
            self.driver.wait(1)





            # 点击新增用户
            self.user_management.click_add_user()
            # 切入内层frame
            self.user_management.switch_to_2_frame()
            # 输入新增用户名
            self.user_management.input_add_user_name(add_user['add_user_name'])
            # 输入登陆账号
            self.user_management.input_add_login_user(add_user['add_login_user'])
            # 输入登录密码
            self.user_management.input_add_login_passwd(add_user['add_login_passwd'])
            # 输入手机号码
            self.user_management.input_add_user_phone(add_user['add_user_phone'])
            # 分配角色
            self.user_management.input_add_user_role()
            # 选择所属公司部门
            self.user_management.choose_add_user_org()
            # 点击关闭按钮
            self.user_management.click_add_user_close()

            # 从数据库查询验证角色未创建成功
            new_user_account_02 = self.user_management.get_add_user_by_sql(add_user['account'])
            self.assertNotEqual(new_user_account_02, add_user['add_login_user'])
            self.driver.wait(1)





            # 点击新增用户
            self.user_management.click_add_user()
            # 切入内层frame
            self.user_management.switch_to_2_frame()
            # 输入新增用户名
            self.user_management.input_add_user_name(add_user['add_user_name'])
            # 输入登陆账号
            self.user_management.input_add_login_user(add_user['add_login_user'])
            # 输入登录密码
            self.user_management.input_add_login_passwd(add_user['add_login_passwd'])
            # 输入手机号码
            self.user_management.input_add_user_phone(add_user['add_user_phone'])
            # 分配角色
            self.user_management.input_add_user_role()
            # 选择所属公司部门
            self.user_management.choose_add_user_org()
            # 点击保存按钮
            self.user_management.click_add_user_save()
            # 跳出最外层frame
            self.user_management.switch_to_default_content()
            # 从数据库查询验证角色创建成功
            new_add_account_03 = self.user_management.get_add_user_by_sql(add_user['account'])
            self.assertEqual(new_add_account_03, add_user['add_login_user'])
            self.driver.wait(1)

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

        csv_file.close()
class TestCase01OrgManageAddOrg(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.organize_management = OrganizeManagement(self.driver,
                                                      self.base_url)
        self.log_in_page_read_csv = LogInPageReadCsv()
        self.user_center_read_csv = UserCenterReadCsv()
        self.organize_management_read_csv = OrganizeManagementReadCsv()
        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_add_org(self):
        # 通过csv测试新增公司部门功能

        csv_file = self.user_center_read_csv.read_csv('add_org_info.csv')
        csv_data = csv.reader(csv_file)
        for row in csv_data:
            add_org_info = {
                "account": row[0],
                "password": row[1],
                "add_org_name": row[2],
                "add_org_tel": row[3],
            }

            # 打开风控首页-登录页
            self.base_page.open_page()
            sleep(1)
            # 登录账号
            self.login_page.user_login(add_org_info['account'],
                                       add_org_info['password'])

            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

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

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

            # 点击进入部门管理
            self.organize_management.click_org_manage()
            # 点击新增公司部门
            self.organize_management.click_add_org()
            # 验证上级部门是否显示正确
            sup_org_name = self.organize_management.get_sup_org_name()
            # 数据库查询当前登录账户的上级部门
            sup_org_name_by_aql = self.organize_management.get_user_sup_org_by_sql(
                add_org_info['account'])

            self.assertEqual(sup_org_name, sup_org_name_by_aql)

            # 选择上级部门
            self.organize_management.choose_sup_org()
            # 填写新增部门名称
            self.organize_management.input_add_org_name(
                add_org_info['add_org_name'])
            # 填写联系方式
            self.organize_management.input_add_org_tel(
                add_org_info['add_org_tel'])
            # 点击取消
            self.organize_management.click_add_org_dismiss()
            # 从数据库查询验证未新增成功
            new_org_name_01 = self.organize_management.get_add_org_by_sql(
                add_org_info['account'])
            self.assertNotEqual(new_org_name_01, add_org_info['add_org_name'])
            self.driver.wait(1)

            # 点击新增公司部门
            self.organize_management.click_add_org()
            # 验证上级部门是否显示正确
            sup_org_name = self.organize_management.get_sup_org_name()
            # 数据库查询当前登录账户的上级部门
            sup_org_name_by_aql = self.organize_management.get_user_sup_org_by_sql(
                add_org_info['account'])

            self.assertEqual(sup_org_name, sup_org_name_by_aql)

            # 选择上级部门
            self.organize_management.choose_sup_org()
            # 填写新增部门名称
            self.organize_management.input_add_org_name(
                add_org_info['add_org_name'])
            # 填写联系方式
            self.organize_management.input_add_org_tel(
                add_org_info['add_org_tel'])
            # 点击关闭按钮
            self.organize_management.click_add_org_close()

            # 从数据库查询验证未新增成功
            new_org_name_02 = self.organize_management.get_add_org_by_sql(
                add_org_info['account'])
            self.assertNotEqual(new_org_name_02, add_org_info['add_org_name'])
            self.driver.wait(1)

            # 点击新增公司部门
            self.organize_management.click_add_org()
            # 验证上级部门是否显示正确
            sup_org_name = self.organize_management.get_sup_org_name()
            # 数据库查询当前登录账户的上级部门
            sup_org_name_by_aql = self.organize_management.get_user_sup_org_by_sql(
                add_org_info['account'])

            self.assertEqual(sup_org_name, sup_org_name_by_aql)

            # 选择上级部门
            self.organize_management.choose_sup_org()
            # 填写新增部门名称
            self.organize_management.input_add_org_name(
                add_org_info['add_org_name'])
            # 填写联系方式
            self.organize_management.input_add_org_tel(
                add_org_info['add_org_tel'])
            # 点击保存按钮
            self.organize_management.click_add_org_save()
            # 跳出最外层frame
            self.organize_management.switch_to_default_content()
            # 从数据库查询验证新增成功
            new_org_name_03 = self.organize_management.get_add_org_by_sql(
                add_org_info['account'])
            self.assertEqual(new_org_name_03, add_org_info['add_org_name'])
            self.driver.wait(1)

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

        csv_file.close()
class TestCase06UserCenterFeedback(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.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_feedback(self):
        '''通过csv测试用户中心意见反馈功能'''
        data = ["部门管理", "设备", "贷款客户", "车辆监控中心", "统计报表", "设置"]

        csv_file = self.user_center_read_csv.read_csv('user_feedback_info.csv')
        csv_data = csv.reader(csv_file)

        for row in csv_data:
            user_feedback_info = {
                "account": row[0],
                "passwd": row[1],
                "type": row[2],
                "content": row[3],
                "linkman": row[4],
                "phone": row[5],
            }

            # 打开风控首页-登录页
            self.base_page.open_page()
            # 输入用户信息进行登录
            self.login_page.user_login(user_feedback_info["account"],
                                       user_feedback_info["passwd"])
            self.driver.wait(1)

            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

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

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

            # 验证模块
            module = self.user_center.get_module_name()
            print(module)
            self.assertEqual(data, module, "用户账号登录,模块显示错误")

            self.driver.wait(10)

            # 进入意见反馈
            self.user_center.click_feedback()

            # 提交反馈信息
            self.user_center.choose_problem_type(user_feedback_info['type'])
            self.user_center.input_problem_content(
                user_feedback_info['content'])
            self.user_center.input_linkman(user_feedback_info['linkman'])
            self.user_center.input_phone(user_feedback_info['phone'])
            self.user_center.click_submit()

            # 获取提交反馈信息成功提示语
            text = self.user_center.get_feedback_success_text()
            self.assertEqual('意见反馈成功', text)

            # 从数据库获取反馈信息验证是否提交成功
            feedback_info = self.user_center.get_feedback_info_by_sql(
                user_feedback_info['account'])
            print(feedback_info)

            self.assertEqual(user_feedback_info['account'], feedback_info[0])
            self.assertEqual(user_feedback_info['type'], feedback_info[1])
            self.assertEqual(user_feedback_info['content'], feedback_info[2])
            self.assertEqual(user_feedback_info['linkman'], feedback_info[3])
            self.assertEqual(user_feedback_info['phone'], feedback_info[4])

            # # 成功退出系统
            sleep(2)
            self.user_center.logout()

        csv_file.close()
class TestCase04UserManageEditUser(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.user_management = UserManagement(self.driver, self.base_url)
        self.log_in_page_read_csv = LogInPageReadCsv()
        self.user_center_read_csv = UserCenterReadCsv()
        self.user_management_read_csv = UserManagementReadCsv()
        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_edit_user(self):
        # 通过csv测试修改用户功能

        csv_file = self.user_management_read_csv.read_csv('edit_user_info.csv')
        csv_data = csv.reader(csv_file)
        for row in csv_data:
            edit_user_info = {
                "account": row[0],
                "password": row[1],
                "search_key": row[2],
                "edit_user_name": row[3],
                "edit_user_phone": row[4],
            }

            # 打开风控首页-登录页
            self.base_page.open_page()
            sleep(1)
            # 登录账号
            self.login_page.user_login(edit_user_info['account'], edit_user_info['password'])

            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

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

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

            # 点击进入用户管理
            self.user_management.click_user_manage()

            # 查找用户testAddUser2
            self.user_management.search_user(edit_user_info['search_key'])
            # 获取页面查找结果
            search_user_name_01 = self.user_management.get_search_result_one()
            # 查询数据库获取搜索结果
            user_info_00 = self.user_management.get_search_result_by_sql(edit_user_info['account'],
                                                                         edit_user_info['search_key'])
            user_name_00 = user_info_00[0]
            user_tel_00 = user_info_00[1]
            self.assertEqual(search_user_name_01, user_name_00)

            # 点击修改
            self.user_management.click_edit_user()
            # 切入内层frame
            self.user_management.switch_to_2_frame()
            # 获取当前显示的用户名称是否与未修改前一致
            current_user_name_01 = self.user_management.get_current_user_name()
            self.assertEqual(search_user_name_01, current_user_name_01)
            # 获取显示的用户手机号码是否与未修改前一致
            current_user_tel_01 = self.user_management.get_current_user_tel()
            self.assertEqual(user_tel_00, current_user_tel_01)

            # 输入用户名称
            self.user_management.input_add_user_name(edit_user_info['edit_user_name'])
            # 输入用户手机号码
            self.user_management.input_add_user_phone(edit_user_info['edit_user_phone'])
            # 点击取消
            self.user_management.click_add_user_dismiss()
            # 数据库查询是否修改失败
            user_info_01 = self.user_management.get_search_result_by_sql(edit_user_info['account'],
                                                                         edit_user_info['search_key'])
            user_name_01 = user_info_01[0]
            user_tel_01 = user_info_01[1]
            self.assertEqual(user_name_00, user_name_01)
            self.assertEqual(user_tel_00, user_tel_01)


            # 点击修改
            self.user_management.click_edit_user()
            # 切入内层frame
            self.user_management.switch_to_2_frame()
            # 获取当前显示的角色名称是否与未修改前一致
            current_user_name_02 = self.user_management.get_current_user_name()
            self.assertEqual(search_user_name_01, current_user_name_02)
            # 获取显示的角色描述是否与未修改前一致
            current_user_tel_02 = self.user_management.get_current_user_tel()
            self.assertEqual(user_tel_00, current_user_tel_02)

            # 输入用户名称
            self.user_management.input_add_user_name(edit_user_info['edit_user_name'])
            # 输入用户手机号码
            self.user_management.input_add_user_phone(edit_user_info['edit_user_phone'])
            # 点击关闭按钮
            self.user_management.click_add_user_close()
            # 数据库查询是否修改失败
            user_info_02 = self.user_management.get_search_result_by_sql(edit_user_info['account'],
                                                                         edit_user_info['search_key'])
            user_name_02 = user_info_02[0]
            user_tel_02 = user_info_02[1]
            self.assertEqual(user_name_00, user_name_02)
            self.assertEqual(user_tel_00, user_tel_02)

            # 点击修改
            self.user_management.click_edit_user()
            # 切入内层frame
            self.user_management.switch_to_2_frame()
            # 获取当前显示的角色名称是否与未修改前一致
            current_user_name_03 = self.user_management.get_current_user_name()
            self.assertEqual(search_user_name_01, current_user_name_03)
            # 获取显示的角色描述是否与未修改前一致
            current_user_tel_03 = self.user_management.get_current_user_tel()
            self.assertEqual(user_tel_00, current_user_tel_03)

            # 输入用户名称
            self.user_management.input_add_user_name(edit_user_info['edit_user_name'])
            # 输入用户手机号码
            self.user_management.input_add_user_phone(edit_user_info['edit_user_phone'])
            # 点击保存按钮
            self.user_management.click_add_user_save()
            # 数据库查询是否修改成功
            user_info_03 = self.user_management.get_search_result_by_sql(edit_user_info['account'],
                                                                         edit_user_info['edit_user_name'])
            user_name_03 = user_info_03[0]
            user_tel_03 = user_info_03[1]
            self.assertNotEqual(user_name_00, user_name_03)
            self.assertNotEqual(user_tel_00, user_tel_03)

            # 跳出外层frame
            self.user_management.switch_to_default_content()

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

        csv_file.close()
class TestCase03LoginWithRememberMe(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.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_login_exception(self):
        '''测试登录时记住密码'''

        # 打开风控首页-登录页
        self.base_page.open_page()

        # 登录时勾选“记住我”复选框
        self.login_page.account_input('syntest')
        self.login_page.password_input('jimi123')
        self.login_page.remember_me()
        self.login_page.login_button_click()
        self.driver.wait()

        # 判断登录成功后招呼栏的用户名是否正确
        username = self.user_center.get_username()

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

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

        # 成功退出系统
        sleep(2)
        self.user_center.logout()

        # 输入用户名
        self.login_page.account_input('syntest')
        # 点击密码输入框
        self.login_page.click_password()
        self.driver.wait()
        # 验证退出系统后“记住我”复选框是否是已勾选状态
        box_status = self.login_page.check_remember_me()
        self.assertEqual(True, box_status, '记住密码失败')

        self.driver.wait()

        # 输入用户名,不输入密码直接点击登录
        self.login_page.login_button_click()
        self.driver.wait()

        # 判断登录成功后招呼栏的用户名是否正确
        username = self.user_center.get_username()

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

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

        # 成功退出系统
        sleep(2)
        self.user_center.logout()

        # 输入用户名
        self.login_page.account_input('syntest')
        # 点击密码输入框
        self.login_page.click_password()
        # 验证退出系统后“记住我”复选框是否是已勾选状态
        box_status = self.login_page.check_remember_me()
        self.assertEqual(True, box_status, '记住密码失败')

        self.driver.wait()

        # 输入用户名,取消勾选“记住我”复选框,输入密码再次登录
        self.login_page.account_input('syntest')
        # 点击密码输入框
        self.login_page.click_password()
        self.driver.wait(2)
        # 取消勾选“记住我”复选框
        self.login_page.remember_me()

        # 验证“记住我”复选框是否是未勾选状态
        box_status = self.login_page.check_remember_me()
        self.assertEqual(False, box_status, '取消记住密码失败')

        # 点击登录
        self.login_page.login_button_click()
        self.driver.wait()

        # 判断登录成功后招呼栏的用户名是否正确
        username = self.user_center.get_username()

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

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

        # 成功退出系统
        sleep(2)
        self.user_center.logout()

        # 输入用户名
        self.login_page.account_input('syntest')
        # 点击密码输入框
        self.login_page.click_password()
        # 验证退出系统后“记住我”复选框是否是未勾选状态
        box_status = self.login_page.check_remember_me()
        self.assertEqual(False, box_status, '取消记住密码失败')
Exemple #12
0
class TestCase04OrgManageEditOrg(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.organize_management = OrganizeManagement(self.driver,
                                                      self.base_url)
        self.log_in_page_read_csv = LogInPageReadCsv()
        self.user_center_read_csv = UserCenterReadCsv()
        self.organize_management_read_csv = OrganizeManagementReadCsv()
        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_edit_org(self):
        # 通过csv测试修改公司部门功能

        csv_file = self.user_center_read_csv.read_csv('edit_org_info.csv')
        csv_data = csv.reader(csv_file)
        for row in csv_data:
            edit_org_info = {
                "account": row[0],
                "password": row[1],
                "search_key": row[2],
                "edit_org_name": row[3],
                "choose_sup_org": row[4],
                "edit_org_tel": row[5],
            }

            # 打开风控首页-登录页
            self.base_page.open_page()
            sleep(1)
            # 登录账号
            self.login_page.user_login(edit_org_info['account'],
                                       edit_org_info['password'])

            # 判断登录成功后招呼栏的用户名是否正确
            username = self.user_center.get_username()

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

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

            # 点击进入部门管理
            self.organize_management.click_org_manage()

            # 查找test00000部门
            self.organize_management.search_org(edit_org_info['search_key'])
            # 获取页面查找结果
            search_org_name_01 = self.organize_management.get_search_result_one(
            )
            # 查询数据库获取搜索结果
            org_info_00 = self.organize_management.get_search_result_by_sql(
                edit_org_info['account'], edit_org_info['search_key'])
            org_name_00 = org_info_00[0]
            sup_org_name_00 = org_info_00[1]
            org_tel_00 = org_info_00[2]
            self.assertEqual(search_org_name_01, org_name_00)

            # 点击修改
            self.organize_management.click_edit_org()
            # 切入内层frame
            self.organize_management.switch_to_2_frame()
            # 获取当前显示的部门名称是否与未修改前一致
            current_org_name_01 = self.organize_management.get_current_org_name(
            )
            self.assertEqual(search_org_name_01, current_org_name_01)
            # 获取显示的所属上级是否与未修改前一致
            current_sup_org = self.organize_management.get_current_sup_org_name(
            )
            self.assertEqual(sup_org_name_00, current_sup_org)
            # 获取显示的联系方式是否与未修改前一致
            current_org_tel = self.organize_management.get_current_org_tel()
            self.assertEqual(org_tel_00, current_org_tel)

            # 修改部门名称
            self.organize_management.edit_org_name(
                edit_org_info['edit_org_name'])
            # 修改所属上级
            self.organize_management.edit_sup_org(
                edit_org_info['choose_sup_org'])
            # 修改联系方式
            self.organize_management.edit_org_tel(
                edit_org_info['edit_org_tel'])
            # 跳出内层frame
            self.organize_management.switch_to_parent_content()
            # 取消
            self.organize_management.click_org_modify_dismiss()
            # 数据库查询是否修改失败
            org_info_01 = self.organize_management.get_search_result_by_sql(
                edit_org_info['account'], edit_org_info['search_key'])
            org_name_01 = org_info_01[0]
            sup_org_name_01 = org_info_01[1]
            org_tel_01 = org_info_01[2]
            self.assertEqual(org_name_00, org_name_01)
            self.assertEqual(sup_org_name_00, sup_org_name_01)
            self.assertEqual(org_tel_00, org_tel_01)

            # 点击修改
            self.organize_management.click_edit_org()
            # 切入内层frame
            self.organize_management.switch_to_2_frame()

            # 修改部门名称
            self.organize_management.edit_org_name(
                edit_org_info['edit_org_name'])
            # 修改所属上级
            self.organize_management.edit_sup_org(
                edit_org_info['choose_sup_org'])
            # 修改联系方式
            self.organize_management.edit_org_tel(
                edit_org_info['edit_org_tel'])
            # 跳出内层frame
            self.organize_management.switch_to_parent_content()

            # 关闭
            self.organize_management.click_org_modify_close()
            # 数据库查询是否修改失败
            org_info_02 = self.organize_management.get_search_result_by_sql(
                edit_org_info['account'], edit_org_info['search_key'])
            org_name_02 = org_info_02[0]
            sup_org_name_02 = org_info_02[1]
            org_tel_02 = org_info_02[2]
            self.assertEqual(org_name_00, org_name_02)
            self.assertEqual(sup_org_name_00, sup_org_name_02)
            self.assertEqual(org_tel_00, org_tel_02)

            # 点击修改
            self.organize_management.click_edit_org()
            # 切入内层frame
            self.organize_management.switch_to_2_frame()

            # 修改部门名称
            self.organize_management.edit_org_name(
                edit_org_info['edit_org_name'])
            # 修改所属上级
            self.organize_management.edit_sup_org(
                edit_org_info['choose_sup_org'])
            # 修改联系方式
            self.organize_management.edit_org_tel(
                edit_org_info['edit_org_tel'])
            # 跳出内层frame
            self.organize_management.switch_to_parent_content()

            # 修改(保存)
            self.organize_management.click_org_modify_button()
            # 数据库查询是否修改成功
            org_info_03 = self.organize_management.get_search_result_by_sql(
                edit_org_info['account'], edit_org_info['search_key'])
            org_name_03 = org_info_03[0]
            sup_org_name_03 = org_info_03[1]
            org_tel_03 = org_info_03[2]
            self.assertEqual(edit_org_info['edit_org_name'], org_name_03)
            self.assertEqual(edit_org_info['choose_sup_org'], sup_org_name_03)
            self.assertEqual(edit_org_info['edit_org_tel'], org_tel_03)

            # 跳出外层frame
            self.organize_management.switch_to_default_content()

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

        csv_file.close()