def setup_subdepartment(sb): """ 添加子部门 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '用户管理') UserPage.add_department_by_parent_department_name(sb, request['name']) yield request sb.save_teardown_screenshot()
def test_add_face_alert_deployment_task_duplicate_task_name( sb, login, setup_face_alert_deployment_task_name_and_delete_task): """测试任务名重复""" # 先用初始值创建一个任务 task = FaceAccessControlTask(setup_face_alert_deployment_task_name_and_delete_task['name'], setup_face_alert_deployment_task_name_and_delete_task['name'], portraits=[ setup_face_alert_deployment_task_name_and_delete_task['name'] ]) TaskPage.add_face_alert_deployment_task(sb, task) # 再添加一个设备 MenuBar.click_menu_item_by_text(sb, '配置', '设备管理') rtsp_device = RTSP( setup_face_alert_deployment_task_name_and_delete_task['name'] + 'dup', setup_face_alert_deployment_task_name_and_delete_task['name'] + 'dup', setup_face_alert_deployment_task_name_and_delete_task['name'], setup_face_alert_deployment_task_name_and_delete_task['name'], 'rtsp://confidence.119:6554/SchoolAnniversary.264') DevicePage.add_device_by_type( sb, rtsp_device, '网络摄像机') # 用新的设备和原先的任务名称、人像库作为添加规则的准备数据 task2 = FaceAccessControlTask(setup_face_alert_deployment_task_name_and_delete_task['name'], setup_face_alert_deployment_task_name_and_delete_task['name'] + 'dup', portraits=[ setup_face_alert_deployment_task_name_and_delete_task['name'] ]) # 定位到setup中的任务菜单 MenuBar.click_menu_item_by_text(sb, '配置', '任务管理') # 再次添加规则 TaskPage.add_face_alert_deployment_task(sb, task2) # 校验"任务名已存在" TaskPage.assert_alert_message(sb, '任务名已存在') # 关闭新增任务窗口 TaskPage.click_task_cancel_button(sb)
def setup_peer_floor(sb): """ 添加同级楼层 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '地图管理') MapPage.add_floor_by_root_floor_name(sb, request['name']) yield request sb.save_teardown_screenshot()
def setup_subdepartment_name_and_delete_subdepartment(sb): """ 生成子部门名称并清理该子部门 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '用户管理') yield request sb.save_teardown_screenshot() UserPage.delete_department_by_name(sb, request['name'])
def setup_subordinate_floor(sb): """ 添加下一级楼层 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '地图管理') MapPage.add_floor_by_parent_name(sb, request['name'], is_peer=False) yield request sb.save_teardown_screenshot()
def setup_subordinate_floor_name_and_delete_floor(sb): """ 生成下一级楼层名称并清理该下一级楼层 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '地图管理') yield request sb.save_teardown_screenshot() MapPage.delete_floor_by_name(sb, request['name'])
def setup_portrait_database_name_and_delete_portrait_database(sb): """ 生成人像库名称并清理该人像库 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '人像库管理') yield request sb.save_teardown_screenshot() PortraitPage.delete_portrait_database_by_name(sb, request['name'])
def setup_device_group(sb): """ 添加设备分组 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '设备管理') DevicePage.add_group_by_root_group_name(sb, request['name']) yield request sb.save_teardown_screenshot()
def setup_device_group_name_and_delete_group(sb): """ 生成设备分组名并清理该该设备分组 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '设备管理') yield request sb.save_teardown_screenshot() DevicePage.delete_group_by_name(sb, request['name'])
def setup_user_reset_password(sb): request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '用户管理') default_password = UserPage.reset_user_password(sb, request['name']) yield str(default_password).strip() sb.save_teardown_screenshot() UserPage.delete_user_by_name(sb, request['name'])
def setup_user_name_and_delete_user(sb): """ 生成用户名并清理该用户 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '用户管理') yield request sb.save_teardown_screenshot() UserPage.delete_user_by_name(sb, request['name'])
def setup_user(sb): """ 添加用户 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '用户管理') user = User(request['name'], request['name']) UserPage.add_user_by_department_name(sb, user) yield request sb.save_teardown_screenshot()
def setup_role_name_and_delete_role(sb): """ 生成角色名称并删除该角色 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '角色管理') yield request sb.save_teardown_screenshot() MenuBar.click_menu_item_by_text(sb, '配置', '角色管理') RolePage.delete_role_by_name(sb, request['name'])
def setup_portrait_database(sb, portrait_type): """ 添加人像库 """ request = {'name': generate_uuid()} MenuBar.click_menu_item_by_text(sb, '配置', '人像库管理') PortraitPage.add_portrait_database_by_name(sb, request['name'], type=portrait_type) yield request sb.save_teardown_screenshot()
def test_detect_facial_attribute(sb, login): """ 测试1:1人脸验证功能 """ sb.sleep(2) MenuBar.click_menu_item_by_text(sb, '工具', '1:1人脸验证') Tools.verify_one_to_one_face( sb, os.getcwd() + '/guard/data/portrait/face_img/img1.jpg', os.getcwd() + '/guard/data/portrait/face_img/img2.jpg') assert '评分参考' == Tools.get_one_to_one_face_result(sb)
def test_invalid_peer_floor(sb, login, setup_peer_floor_and_delete_floor, name): MenuBar.click_menu_item_by_text(sb, '配置', '地图管理') MapPage.add_floor_by_parent_name( sb, name, parent_name=setup_peer_floor_and_delete_floor['name'], is_peer=False) MapPage.assert_element_text(sb, '.el-form-item__error', '请输入分组名称') MapPage.click_cancel_in_dialog(sb)
def test_first_login_reset_password(sb, login, setup_user): # 登陆系统创建新用户,并退出当前用户 MenuBar.click_personal_info_menu_item(sb, '退出系统') # 登陆新用户,并修改密码 LoginPage.login(sb, setup_user['name'], '888888') PersonInfoPage.reset_password(sb, '888888', 'Guard123', 'Guard123') sb.sleep(5) # 重新登陆系统,验证密码修改成功 LoginPage.login(sb, setup_user['name'], 'Guard123') sb.assert_element_visible('.avatar-name')
def test_delete_existing_subordinate_floor(sb, login, setup_peer_floor_and_delete_floor): subordinate_name = f"{setup_peer_floor_and_delete_floor['name']}S" MapPage.add_floor_by_parent_name( sb, subordinate_name, parent_name=setup_peer_floor_and_delete_floor['name'], is_peer=False) MenuBar.click_menu_item_by_text(sb, '配置', '地图管理') MapPage.delete_floor_by_name(sb, subordinate_name) MapPage.assert_alert_message(sb, '删除分组成功!')
def test_portrait(self): # 访问人像库管理页面 MenuBar.click_menu_item_by_text(self, '配置', '人像库管理') # 添加白名单库 PortraitPage.add_portrait_database_by_name( self, SmokeTest.SMOKE_PORTRAIT_DATABASE_WHITELIST_NAME, type='白名单') # PortraitPage.assert_alert_message(self, '创建下一级分组成功') # 添加重点人员库 PortraitPage.add_portrait_database_by_name( self, SmokeTest.SMOKE_PORTRAIT_DATABASE_KEY_PERSONNEL_NAME, type='重点人员')
def test_login_with_wrong_password_five_times(sb, login, setup_user): ALERT_MESSAGE_LIST = [ '用户名或密码有误,请重新输入,您还有 4 次机会', '用户名或密码有误,请重新输入,您还有 3 次机会', '用户名或密码有误,请重新输入,您还有 2 次机会', '用户名或密码有误,请重新输入,您还有 1 次机会', '多次输入密码有误,账户已被锁定,请联系IT部门' ] MenuBar.click_personal_info_menu_item(sb, '退出系统') for i in range(5): LoginPage.login(sb, setup_user['name'], '123456') sb.sleep(1) LoginPage.assert_alert_message(sb, ALERT_MESSAGE_LIST[i]) sb.sleep(2)
def test_map(self): # 访问地图管理页面 MenuBar.click_menu_item_by_text(self, '配置', '地图管理') # 添加父楼层 MapPage.add_floor_by_root_floor_name( self, SmokeTest.SMOKE_MAP_PARENT_FLOOR_NAME) # MapPage.assert_alert_message(self, '创建同级分组成功') # 添加子楼层 MapPage.add_floor_by_parent_name( self, SmokeTest.SMOKE_MAP_CHILD_FLOOR_NAME, parent_name=SmokeTest.SMOKE_MAP_PARENT_FLOOR_NAME, is_peer=False)
def test_device(self): # 访问设备管理页面 MenuBar.click_menu_item_by_text(self, '配置', '设备管理') # 创建设备分组 DevicePage.add_group_by_root_group_name( self, SmokeTest.SMOKE_DEVICE_GROUP_NAME) # DevicePage.assert_alert_message(self, '创建同级分组成功') # 添加RTSP设备 rtsp_device = RTSP(SmokeTest.SMOKE_DEVICE_RTSP_NAME, SmokeTest.SMOKE_DEVICE_RTSP_NAME, SmokeTest.SMOKE_DEVICE_GROUP_NAME, SmokeTest.SMOKE_MAP_CHILD_FLOOR_NAME, SmokeTest.SMOKE_DEVICE_RTSP_ADDRESS) DevicePage.add_device_by_type(self, rtsp_device, '网络摄像机')
def setup_portrait_with_portrait_database_and_delete_portrait_database( sb, setup_portrait_database_and_delete_portrait_database): """ 添加人像到人像库并删除人像库 """ request = { 'name': generate_uuid(), 'portrait_database': setup_portrait_database_and_delete_portrait_database['name'] } MenuBar.click_menu_item_by_text(sb, '配置', '人像库管理') portrait = Portrait(name=request['name'], id_number=request['name'], image_path=os.getcwd() + '/guard/data/portrait/001-JPG.jpg', portrait_databases=[request['portrait_database']]) PortraitPage.add_portrait(sb, portrait) yield request sb.save_teardown_screenshot()
def test_check_all_face_property(sb, login): """ 测试人脸属性输出的属性字段 """ MenuBar.click_menu_item_by_text(sb, '工具', '人脸属性检测') Tools.detect_facial_attribute( sb, os.getcwd() + '/guard/data/portrait/face_property/seleniumbase.jpg') sex_data = Tools.get_facial_attribute_by_name(sb, "性别") age_data = Tools.get_facial_attribute_by_name(sb, "年龄") phiz_data = Tools.get_facial_attribute_by_name(sb, "表情") mustache_data = Tools.get_facial_attribute_by_name(sb, "胡子") glasse_data = Tools.get_facial_attribute_by_name(sb, "眼镜") mask_data = Tools.get_facial_attribute_by_name(sb, "口罩") helmet_data = Tools.get_facial_attribute_by_name(sb, "安全帽") hat_data = Tools.get_facial_attribute_by_name(sb, "帽子") assert '性别:' == sex_data[0] and '年龄:' == age_data[ 0] and '表情:' == phiz_data[0] and '胡子:' == mustache_data[ 0] and '眼镜:' == glasse_data[0] and '口罩:' == mask_data[ 0] and '安全帽:' == helmet_data[0] and '帽子:' == hat_data[0]
def test_check_face_mustache(sb, login, data): """ 上传不同的人脸照片,查看输出的人脸属性 """ MenuBar.click_menu_item_by_text(sb, '工具', '人脸属性检测') Tools.detect_facial_attribute( sb, os.getcwd() + f'/guard/data/portrait/face_property/{data["img_path"]}') sex_data = Tools.get_facial_attribute_by_name(sb, "性别") age_data = Tools.get_facial_attribute_by_name(sb, "年龄") phiz_data = Tools.get_facial_attribute_by_name(sb, "表情") mustache_data = Tools.get_facial_attribute_by_name(sb, "胡子") glasse_data = Tools.get_facial_attribute_by_name(sb, "眼镜") mask_data = Tools.get_facial_attribute_by_name(sb, "口罩") helmet_data = Tools.get_facial_attribute_by_name(sb, "安全帽") hat_data = Tools.get_facial_attribute_by_name(sb, "帽子") assert data["sex"] in sex_data[-1] and data["age"] in age_data[ -1] and data["phiz"] in phiz_data[-1] and data[ "mustache"] in mustache_data[-1] and data["glasse"] in glasse_data[ -1] and data["mask"] in mask_data[-1] and data[ "helmet"] in helmet_data[-1] and data["hat"] in hat_data[-1]
def setup_portrait_with_two_portrait_databases_and_delete_portrait_databases( sb, setup_portrait_database_name): """ 添加人像到人像库并删除人像库 """ request = { 'name': generate_uuid(), 'portrait_databases': [ f'{setup_portrait_database_name["name"]}1', f'{setup_portrait_database_name["name"]}2' ] } for portrait_database in request['portrait_databases']: PortraitPage.add_portrait_database_by_name(sb, portrait_database) MenuBar.click_menu_item_by_text(sb, '配置', '人像库管理') portrait = Portrait(name=request['name'], id_number=request['name'], image_path=os.getcwd() + '/guard/data/portrait/001-JPG.jpg', portrait_databases=request['portrait_databases']) PortraitPage.add_portrait(sb, portrait) yield request sb.save_teardown_screenshot() for portrait_database in request['portrait_databases']: PortraitPage.delete_portrait_database_by_name(sb, portrait_database)
def test_add_face_access_control_task_duplicate_task_name( sb, login, setup_face_access_control_task_name_and_delete_task): """测试任务名重复""" # 先用初始值创建一个任务 task = FaceAccessControlTask( setup_face_access_control_task_name_and_delete_task['name'], setup_face_access_control_task_name_and_delete_task['name'], portraits=[ setup_face_access_control_task_name_and_delete_task['name'] ]) TaskPage.add_face_access_control_task(sb, task) # 再添加一个设备 MenuBar.click_menu_item_by_text(sb, '配置', '设备管理') frontend_device = Frontend( setup_face_access_control_task_name_and_delete_task['name'] + 'dup', setup_face_access_control_task_name_and_delete_task['name'] + 'dup', setup_face_access_control_task_name_and_delete_task['name'], setup_face_access_control_task_name_and_delete_task['name'], 'SensePass') DevicePage.add_device_by_type(sb, frontend_device, '人脸识别机(前)') # 用新的设备和原先的任务名称、人像库作为添加规则的准备数据 task2 = FaceAccessControlTask( setup_face_access_control_task_name_and_delete_task['name'], setup_face_access_control_task_name_and_delete_task['name'] + 'dup', portraits=[ setup_face_access_control_task_name_and_delete_task['name'] ]) # 定位到setup中的任务菜单 MenuBar.click_menu_item_by_text(sb, '配置', '任务管理') # 再次添加规则 TaskPage.add_face_access_control_task(sb, task2) # 校验"任务名已存在" TaskPage.assert_alert_message(sb, '任务名已存在') # 关闭新增任务窗口 TaskPage.click_task_cancel_button(sb)
def test_login_with_reset_locked_account(sb, login, setup_user): #5次登录错误,账户被锁定 MenuBar.click_personal_info_menu_item(sb, '退出系统') for i in range(5): LoginPage.login(sb, setup_user['name'], '123456') sb.sleep(1) #管理员登录,重置密码 LoginPage.login(sb, sb_config.username, sb_config.password) sb.sleep(2) MenuBar.click_menu_item_by_text(sb, '配置', '用户管理') default_password = UserPage.reset_user_password(sb, setup_user['name']) MenuBar.click_personal_info_menu_item(sb, '退出系统') sb.sleep(2) # 重新登录,并修改密码 LoginPage.login(sb, setup_user['name'], str(default_password).strip()) PersonInfoPage.reset_password(sb, str(default_password).strip(), 'Guard123', 'Guard123') sb.sleep(5) # 重新登陆系统,验证密码修改成功 LoginPage.login(sb, setup_user['name'], 'Guard123') sb.assert_element_visible('.avatar-name')
def test_locked_account_login_in_thirty_minutes(sb, login, setup_user): MenuBar.click_personal_info_menu_item(sb, '退出系统') for i in range(6): LoginPage.login(sb, setup_user['name'], '123456') sb.sleep(1) LoginPage.assert_alert_message(sb, "多次输入密码有误,账户已被锁定,请联系IT部门")
def setup_log(sb): MenuBar.click_menu_item_by_text(sb, '配置', '日志管理')