class TestCase206UserCenterDevLog(unittest.TestCase):
    # 测试个人中心 - 帮助 - 业务日志 - 设备管理日志(设备修改和设备分配)
    def setUp(self):
        self.driver = AutomateDriverServer()
        self.base_url = self.driver.base_url
        self.base_page = BasePageServer(self.driver, self.base_url)
        self.login_page = LoginPage(self.driver, self.base_url)
        self.help_page = HelpPage(self.driver, self.base_url)
        self.account_center_page_operation_log = AccountCenterOperationLogPage(
            self.driver, self.base_url)
        self.help_page_sql = HelpPageSql()
        self.account_center_page_read_csv = AccountCenterPageReadCsv()
        self.connect_sql = ConnectSql()
        self.log_in_base = LogInBaseServer(self.driver, self.base_page)
        self.user_center_page = UserCenterPage(self.driver, self.base_url)
        self.driver.set_window_max()
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.driver.wait(1)

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

    def test_user_center_dev_log(self):
        self.base_page.open_page()
        self.log_in_base.log_in()
        user_account = self.log_in_base.get_log_in_account()

        # 点击设备管理
        current_handle = self.driver.get_current_window_handle()
        self.user_center_page.click_dev_management_button()
        sleep(3)
        self.base_page.change_windows_handle(current_handle)
        # 获取列表第一个imei号
        sleep(3)
        imei = self.user_center_page.get_dev_list_first_imei()
        # 点击编辑
        self.user_center_page.click_edit_dev_button()
        # 点击确定
        self.user_center_page.click_ensure_button()

        # 销售
        self.user_center_page.click_sale_button()

        # 进入帮助 - 业务日志页面
        current_handle_01 = self.driver.get_current_window_handle()
        self.user_center_page.click_user_center_button()
        self.base_page.change_windows_handle(current_handle_01)
        # 点击帮助
        self.user_center_page.click_help_button()
        # 切换到业务日志的frame里面
        self.user_center_page.switch_to_business_frame()

        self.user_center_page.click_search_button_in_business_log()

        # 获取第一条数据的操作人、目标账号、操作平台、描述
        sleep(3)
        operation = self.user_center_page.get_operation_in_business_log()
        target_account = self.user_center_page.get_target_account_in_business_log(
        )
        operation_platform = self.user_center_page.get_operation_platform_in_business_log(
        )
        desc = self.user_center_page.get_desc_in_business_log()
        self.assertEqual(' ' + user_account, operation)
        self.assertEqual(target_account, user_account)
        self.assertEqual('网页端', operation_platform)

        web_desc = "%s修改设备%s" % (user_account, imei)
        self.assertEqual(web_desc, desc)

        # 选择设备分配搜索
        self.user_center_page.search_dev_sale_in_business_log()
        # 点击搜索
        self.user_center_page.click_search_button_in_business_log()

        operation_01 = self.user_center_page.get_operation_in_business_log()
        target_account_01 = self.user_center_page.get_target_account_in_business_log(
        )
        operation_platform_01 = self.user_center_page.get_operation_platform_in_business_log(
        )
        desc_01 = self.user_center_page.get_desc_in_business_log()

        self.assertEqual(' ' + user_account, operation_01)
        self.assertEqual(target_account_01, user_account)
        self.assertEqual('网页端', operation_platform_01)

        web_desc_01 = "%s将设备%s从%s分配给%s" % (user_account, imei, user_account,
                                           user_account)
        self.assertEqual(web_desc_01, desc_01)
        self.driver.default_frame()
class TestCase208UserCenterSafeAreaLog(unittest.TestCase):
    # 测试个人中心 - 帮助 - 业务日志 - 安全区域管理日志(编辑、删除、关联、删除关联)
    def setUp(self):
        self.driver = AutomateDriverServer()
        self.base_url = self.driver.base_url
        self.base_page = BasePageServer(self.driver, self.base_url)
        self.login_page = LoginPage(self.driver, self.base_url)
        self.help_page = HelpPage(self.driver, self.base_url)
        self.account_center_page_operation_log = AccountCenterOperationLogPage(self.driver, self.base_url)
        self.help_page_sql = HelpPageSql()
        self.account_center_page_read_csv = AccountCenterPageReadCsv()
        self.connect_sql = ConnectSql()
        self.log_in_base = LogInBaseServer(self.driver, self.base_page)
        self.user_center_page = UserCenterPage(self.driver, self.base_url)
        self.driver.set_window_max()
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.driver.wait(1)

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

    def test_user_center_safe_area_log(self):
        self.base_page.open_page()
        self.log_in_base.log_in()
        user_account = self.log_in_base.get_log_in_account()

        # 点击安全区域
        current_handle = self.driver.get_current_window_handle()
        self.user_center_page.click_safe_area_button()
        self.base_page.change_windows_handle(current_handle)

        # 搜索平台围栏
        self.user_center_page.search_platform_fence()
        # 获取第一个围栏的名称
        fence_name = self.user_center_page.get_first_fence_name()

        # 点击编辑
        self.user_center_page.click_edit_fence_button()
        # 点击保存
        self.user_center_page.click_ensure_button()

        # 点击关联
        self.user_center_page.click_relevance_fence_button()
        # 选择设备进行关联
        imei_01 = self.user_center_page.click_dev_relevance_fence()
        # 点击保存
        self.user_center_page.click_ensure_button()

        # 取消关联
        self.user_center_page.click_relevance_fence_button()
        # 选择设备进行关联
        imei_02 = self.user_center_page.click_dev_relevance_fence()
        # 点击保存
        self.user_center_page.click_ensure_button()

        # 进入帮助 - 业务日志页面
        self.user_center_page.click_user_center_button()
        # 点击帮助
        self.user_center_page.click_help_button()
        # 切换到业务日志的frame里面
        self.user_center_page.switch_to_business_frame()

        # 选择安全区域查询 - 新增、编辑
        self.user_center_page.select_safe_area_search()
        self.user_center_page.select_edit_safe_area_search()
        sleep(5)

        operation_01 = self.user_center_page.get_operation_in_business_log()
        target_account_01 = self.user_center_page.get_target_account_in_business_log()
        operation_platform_01 = self.user_center_page.get_operation_platform_in_business_log()
        desc_01 = self.user_center_page.get_desc_in_business_log()

        self.assertEqual(operation_01, ' ' + user_account)
        self.assertEqual(target_account_01, user_account)
        self.assertEqual('网页端', operation_platform_01)
        web_desc_01 = "用户修改了(%s)围栏信息" % (fence_name)
        self.assertEqual(desc_01, web_desc_01)

        # 选择关联设备
        self.user_center_page.select_relevant_safe_area_search()
        sleep(5)

        operation_02 = self.user_center_page.get_operation_in_business_log_02()
        target_account_02 = self.user_center_page.get_target_account_in_business_log_02()
        operation_platform_02 = self.user_center_page.get_operation_platform_in_business_log_02()
        desc_02 = self.user_center_page.get_desc_in_business_log_02()

        self.assertEqual(operation_02, ' ' + user_account)
        self.assertEqual(target_account_02, user_account)
        self.assertEqual('网页端', operation_platform_02)
        web_desc_02 = "%s关联设备%s与区域信息%s" % (user_account, imei_01, fence_name)
        self.assertEqual(desc_02, web_desc_02)

        self.driver.default_frame()
class TestCase212UserCenterCancelCommandLog(unittest.TestCase):
    # 测试个人中心 - 帮助 - 业务日志 - 取消指令日志
    def setUp(self):
        self.driver = AutomateDriverServer()
        self.base_url = self.driver.base_url
        self.base_page = BasePageServer(self.driver, self.base_url)
        self.login_page = LoginPage(self.driver, self.base_url)
        self.help_page = HelpPage(self.driver, self.base_url)
        self.account_center_page_operation_log = AccountCenterOperationLogPage(
            self.driver, self.base_url)
        self.help_page_sql = HelpPageSql()
        self.account_center_page_read_csv = AccountCenterPageReadCsv()
        self.connect_sql = ConnectSql()
        self.log_in_base = LogInBaseServer(self.driver, self.base_page)
        self.user_center_page = UserCenterPage(self.driver, self.base_url)
        self.driver.set_window_max()
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.driver.wait(1)

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

    def test_user_center_cancel_command_log(self):
        self.base_page.open_page()
        self.log_in_base.log_in_jimitest()
        user_account = self.log_in_base.get_log_in_account()

        # 点击设置 - 指令管理
        self.user_center_page.click_set_up_and_command_set_up()
        # 点击下发指令管理
        self.user_center_page.click_issued_command_management()
        sleep(3)
        # 搜索待发送的指令记录
        self.user_center_page.search_to_be_sent_command()

        # 获取第一条指令的信息
        command_info = self.user_center_page.get_command_info_first_command_record(
        )
        command_imei = self.user_center_page.get_command_imei_first_command_record(
        )

        command_imei_user_account = self.user_center_page.get_command_imei_user_account(
            command_imei)

        # 选择第一条记录,选中取消指令
        self.user_center_page.select_first_command_record_and_cancel()

        self.user_center_page.click_user_center_button()
        # 点击帮助
        self.user_center_page.click_help_button()
        # 切换到业务日志的frame里面
        self.user_center_page.switch_to_business_frame()

        # 搜索取消指令
        self.user_center_page.select_cancel_command_log()
        # 点击搜索
        self.user_center_page.click_search_button_in_business_log()
        sleep(5)

        # 获取第一条日志的记录
        operation = self.user_center_page.get_operation_in_business_log()
        target_account = self.user_center_page.get_target_account_in_business_log(
        )
        operation_platform = self.user_center_page.get_operation_platform_in_business_log(
        )
        desc = self.user_center_page.get_desc_in_business_log()

        # 断言
        self.assertEqual(operation + " ", ' ' + user_account)
        self.assertEqual(target_account, command_imei_user_account)
        self.assertEqual('网页端', operation_platform)

        desc_01 = "%s取消设备%s 指令%s" % (operation, command_imei, command_info)
        self.assertEqual(desc_01, " " + desc)
class TestCase207UserCenterCustomerLog(unittest.TestCase):
    # 测试个人中心 - 帮助 - 业务日志 - 客户管理日志(新增客户、修改客户信息、删除客户、修改密码、重置密码、转移客户)
    def setUp(self):
        self.driver = AutomateDriverServer()
        self.base_url = self.driver.base_url
        self.base_page = BasePageServer(self.driver, self.base_url)
        self.login_page = LoginPage(self.driver, self.base_url)
        self.help_page = HelpPage(self.driver, self.base_url)
        self.account_center_page_operation_log = AccountCenterOperationLogPage(
            self.driver, self.base_url)
        self.help_page_sql = HelpPageSql()
        self.account_center_page_read_csv = AccountCenterPageReadCsv()
        self.connect_sql = ConnectSql()
        self.log_in_base = LogInBaseServer(self.driver, self.base_page)
        self.user_center_page = UserCenterPage(self.driver, self.base_url)
        self.driver.set_window_max()
        self.driver.wait(1)
        self.driver.clear_cookies()
        self.driver.wait(1)

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

    def test_user_center_customer_log(self):
        self.base_page.open_page()
        self.log_in_base.log_in()
        user_account = self.log_in_base.get_log_in_account()

        # 点击客户管理
        new_customer_data = ['新增的客户', 'new_1226']

        current_handle = self.driver.get_current_window_handle()
        self.user_center_page.click_customer_mangement()
        self.base_page.change_windows_handle(current_handle)

        # 新增客户按钮
        self.user_center_page.click_add_new_customer_buttons()
        # 点击切换到frame
        self.user_center_page.switch_to_add_new_customer_frame()
        # 填写用户名称和账号
        self.user_center_page.add_user_name_and_user_account(new_customer_data)
        self.driver.default_frame()
        # 点击确定
        self.user_center_page.click_ensure_button()

        # 搜索新增的用户
        self.user_center_page.search_user_in_customer_management(
            new_customer_data[1])

        # 修改用户信息 - 点击编辑
        self.user_center_page.click_edit_customer_button()
        # 点击保存
        self.user_center_page.click_ensure_button()

        # 点击重置密码
        self.user_center_page.click_reset_password_button()
        # 点击保存
        self.user_center_page.click_ensure_button()

        # 点击转移客户
        self.user_center_page.click_transfer_customer_button()
        # 点击保存
        self.user_center_page.click_ensure_button()

        # 点击删除客户
        self.user_center_page.click_delete_customer_button()
        # 点击保存
        self.user_center_page.click_ensure_button()

        # 进入帮助 - 业务日志页面
        self.user_center_page.click_user_center_button()
        # 点击帮助
        self.user_center_page.click_help_button()
        # 切换到业务日志的frame里面
        self.user_center_page.switch_to_business_frame()

        # 查询 客户管理 - 新增客户
        self.user_center_page.select_customer_management_condition()
        self.user_center_page.select_add_new_customer_log()
        # 点击搜索
        self.user_center_page.click_search_button_in_business_log()

        operation_01 = self.user_center_page.get_operation_in_business_log()
        target_account_01 = self.user_center_page.get_target_account_in_business_log(
        )
        operation_platform_01 = self.user_center_page.get_operation_platform_in_business_log(
        )
        desc_01 = self.user_center_page.get_desc_in_business_log()

        self.assertEqual(" " + user_account, operation_01)
        self.assertEqual(new_customer_data[1], target_account_01)
        self.assertEqual('网页端', operation_platform_01)
        web_desc_01 = "用户%s执行添加客户操作" % user_account
        self.assertEqual(web_desc_01, desc_01)

        # 查询修改用户信息
        self.user_center_page.select_edit_customer_log()
        # 点击搜索
        self.user_center_page.click_search_button_in_business_log()

        operation_02 = self.user_center_page.get_operation_in_business_log()
        target_account_02 = self.user_center_page.get_target_account_in_business_log(
        )
        operation_platform_02 = self.user_center_page.get_operation_platform_in_business_log(
        )
        desc_02 = self.user_center_page.get_desc_in_business_log()

        self.assertEqual(" " + user_account, operation_02)
        self.assertEqual(new_customer_data[1], target_account_02)
        self.assertEqual('网页端', operation_platform_02)
        web_desc_02 = "用户%s执行修改用户信息操作" % user_account
        self.assertEqual(web_desc_02, desc_02)

        # 查询删除用户信息
        self.user_center_page.select_delete_customer_log()
        # 点击搜索
        self.user_center_page.click_search_button_in_business_log()

        operation_03 = self.user_center_page.get_operation_in_business_log()
        target_account_03 = self.user_center_page.get_target_account_in_business_log(
        )
        operation_platform_03 = self.user_center_page.get_operation_platform_in_business_log(
        )
        desc_03 = self.user_center_page.get_desc_in_business_log()

        self.assertEqual(" " + user_account, operation_03)
        self.assertEqual(new_customer_data[1], target_account_03)
        self.assertEqual('网页端', operation_platform_03)
        web_desc_03 = "用户%s执行删除用户信息操作" % user_account
        self.assertEqual(web_desc_03, desc_03)

        # 查询重置密码信息
        self.user_center_page.select_reset_password_log()
        # 点击搜索
        self.user_center_page.click_search_button_in_business_log()

        operation_04 = self.user_center_page.get_operation_in_business_log()
        target_account_04 = self.user_center_page.get_target_account_in_business_log(
        )
        operation_platform_04 = self.user_center_page.get_operation_platform_in_business_log(
        )
        desc_04 = self.user_center_page.get_desc_in_business_log()

        self.assertEqual(" " + user_account, operation_04)
        self.assertEqual(new_customer_data[1], target_account_04)
        self.assertEqual('网页端', operation_platform_04)
        web_desc_04 = "用户%s执行重置密码操作" % user_account
        self.assertEqual(web_desc_04, desc_04)

        # 查询转移客户信息
        self.user_center_page.select_transfer_customer_log()
        # 点击搜索
        self.user_center_page.click_search_button_in_business_log()

        operation_05 = self.user_center_page.get_operation_in_business_log()
        target_account_05 = self.user_center_page.get_target_account_in_business_log(
        )
        operation_platform_05 = self.user_center_page.get_operation_platform_in_business_log(
        )
        desc_05 = self.user_center_page.get_desc_in_business_log()

        self.assertEqual(" " + user_account, operation_05)
        self.assertEqual(new_customer_data[1], target_account_05)
        self.assertEqual('网页端', operation_platform_05)
        web_desc_05 = "对用户%s从%s到%s执行转移客户操作" % (new_customer_data[1],
                                               user_account, user_account)
        self.assertEqual(web_desc_05, desc_05)

        self.driver.default_frame()