class Test_RulePage(): driver = AutoDriver() RulePage = RulePage() DevicePage = DevicePage() DevicePage.into_devicePage() @allure.feature("联动管理模块") @allure.story("新建联动--正向用例") @allure.title("新建一键联动测试") def test_09_add_oneKeyRule(self): """ 用例描述: 测试点:新建一键联动 用例步骤:1、新建一键联动 校验:1、拿到最新一键联动的名称与创建的名称做比较 :return: """ self.RulePage.into_rulePage() rule_name = "一键联动" + str(random.randint(0, 99)) self.RulePage.into_oneKey_page() self.RulePage.into_cloud_rule() self.RulePage.set_rule_name(rule_name) self.RulePage.add_one_key_type() self.RulePage.add_actionOrCondition("cloud", 0, 0, 0, 1, 1) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name, "新建一键联动失败, 期望: %s, 实际: %s" % ( rule_name, actual_name)
class PageBase(ElementLoader, unittest.TestCase): driver = AutoDriver() def __init__(self): ElementLoader.__init__(self, self.__class__.__name__) def login(self, email, pwd): email_field = self.driver.find_element(self.locator("email_field")) self.driver.send_keys(email_field, email) pwd_field = self.driver.find_element(self.locator("pwd_field")) self.driver.send_keys(pwd_field, pwd) btn_login = self.driver.find_element(self.locator("btn_login")) self.driver.click(btn_login) def access_Page(self, page_name): if page_name == "注册新设备": link_register_new_device = self.driver.find_element( self.locator("link_register_new_device")) self.driver.click(link_register_new_device) def get_user_with_id(self, user_id): return self.get_config_user_info(user_id) def get_current_user_nickname(self): nickname = self.driver.find_element(self.locator("nickname")) return nickname.text def logout(self): script = "document.querySelector('body > div > div.main-wrapper.ng-scope > div:nth-child(1) > div > header > div:nth-child(2) > nav > div > ul').setAttribute('class','');" self.driver.execute_script(script) link_logout = self.driver.find_element(self.locator("link_logout")) self.driver.click(link_logout)
class Test_ProjectPage(): driver = AutoDriver() ProjectPage = ProjectPage() @allure.feature("项目管理模块") @allure.story("新建项目--正向用例") @allure.title("新建项目场景测试") def test_01_addProject(self): """ 用例描述: 测试点:新建项目 用例步骤:1、创建新项目 检验:1、获取当前最新项目的title,与project_name做比较 :return: """ project_name = "项目" + str(random.randint(0, 99)) # with allure.step("step1: 统计当前项目个数"): # old_project = self.ProjectPage.get_project_num() # except_num = old_project + 1 with allure.step("step1: 新建项目"): self.ProjectPage.add_project(project_name) with allure.step("step2: 获取当前最新的项目名称"): actual_name = self.ProjectPage.get_project_name() with allure.step("step3: 断言"): assert actual_name == project_name
class PageNewDevice(PageBase): driver = AutoDriver() def __init__(self): ElementLoader.__init__(self, self.__class__.__name__) def get_title(self): title = self.driver.find_element(self.locator("title")) return title.text
class Test_DevicePage(): driver = AutoDriver() ProjectPage = ProjectPage() DevicesPage = DevicesPage() @allure.feature("设备管理模块") @allure.story("修改设备名称--正向用例") @allure.title("修改设备测试") def test_01_editDeviceName(self): """
class MyInfoPage(ElementLoader): driver = AutoDriver() ProjectPage = ProjectPage() def __init__(self): ElementLoader.__init__(self, self.__class__.__name__) @allure.step("进入个人中心页") def into_myInfo(self): """ 进入个人中心页面 :return: """ #判断是否在项目列表页面,在则返回True flag = self.ProjectPage.is_project_page() if flag: into_btn = self.driver.find_element_until_visibility( self.locator("into_myinfo")) self.driver.click(into_btn) else: return "不在项目列表页面" @allure.step("判断是否在个人中心页") def is_myInfoPage(self): """ 判断是否在个人中心页面 :return: """ flag = self.driver.is_element(self.locator("myinfo_flag"), 3) return flag @allure.step("退出登录") def logout(self): """ 退出登录 :return: """ #判断是否在个人中心页面 flag = self.is_myInfoPage() if flag: logout_btn = self.driver.find_element_until_visibility( self.locator("myinfo_logout")) self.driver.click(logout_btn) v_done = self.driver.find_element_until_visibility( self.locator("v_done")) self.driver.click(v_done) else: return "not found"
class RoomPage(ElementLoader, unittest.TestCase): driver = AutoDriver() def __init__(self): ElementLoader.__init__(self, self.__class__.__name__) @allure.step("判断是否在房间列表页面") def is_room_page(self): """判断是否在房间列表页面,是返回True,不是返回False""" flag = self.driver.is_element(self.locator("room_page"), 3) #@allure.step("进入房间页面") def into_rommPage(self): """进入房间页面""" #room_class = "android.widget.RelativeLayout" #room_btn = self.driver.get_text_ele(room_class,"多个本地延时QQ") room_btn = self.driver.find_elements_until_visibility( self.locator("room_name")) self.driver.click(room_btn[1]) @allure.step("获取房间名称") def get_room_name(self, num=0): """ 从房间列表中获取房间名称 :param num: 默认为第一个 :return: 房间名称 """ room = self.driver.find_elements_until_visibility( self.locator("room_name")) name = room[mun].text return name @allure.step("获取房间个数") def get_room_num(self): """ 从房间列表获取房间个数 :return: 房间个数 """ rooms = self.driver.find_elements_until_visibility( self.locator("room_name")) num = len(rooms) return num
class TestSmoke(): """ 冒烟测试:正向流程 """ driver = AutoDriver() LoginPage = LoginPage() ProjectPage = ProjectPage() RoomPage = RoomPage() DevicePage = DevicePage() RulePage = RulePage() MyInfoPage = MyInfoPage() @pytest.mark.skip(reason='skip testing this') @allure.feature("登录模块") @allure.story("登录--正向用例") @allure.title("登录测试") def test_01_login(self): """ 用例描述: 测试点:登录 用例步骤:1、调起app,判断app是否处于登录页,否则则操作logout 检验:1、操作登录后判断是否进入项目列表页面 :return: """ #判断是否在登录页 flag = self.LoginPage.is_in_login_page() if flag: self.LoginPage.app_login("18002549655", "Hyp123456") else: self.MyInfoPage.into_myInfo() self.MyInfoPage.logout() self.LoginPage.app_login("18002549655", "Hyp123456") flag_assert = self.ProjectPage.is_project_page() assert flag_assert, '登录失败' @allure.feature("项目管理模块") @allure.story("新建项目--正向用例") @allure.title("新建酒店项目测试") def test_02_addHotelProject(self): """ 用例描述: 测试点:新建项目 用例步骤:1、创建新项目 检验:1、获取当前最新项目的title,与project_name做比较 :return: """ project_name = "自动化" + str(random.randint(0, 99)) + "_创建" + str(random.randint(0, 99)) # with allure.step("step1: 统计当前项目个数"): # old_project = self.ProjectPage.get_project_num() # except_num = old_project + 1 with allure.step("step1: 新建项目"): self.ProjectPage.add_project(project_name) with allure.step("step2: 获取当前最新的项目名称"): actual_name = self.ProjectPage.get_project_name() with allure.step("step3: 断言"): assert actual_name == project_name @allure.feature("项目管理模块") @allure.story("删除项目--正向用例") @allure.title("删除酒店项目测试") def test_03_removeHotelProject(self): """ 用例描述: 测试点:删除项目 用例步骤:1、选择上个用例新建的项目,进入对应房间,操作删除项目 检验:1、 :return: """ self.DevicePage.into_devicePage() self.DevicePage.into_room_more() self.DevicePage.del_room() actual_toast = self.DevicePage.remove_toast() assert actual_toast == '移除成功' @allure.feature("房间管理模块") @allure.story("修改房间名称--正向用例") @allure.title("修改房间名称测试") def test_04_changeRoomName(self): """ 用例描述: 测试点:修改房间名称 用例步骤:1、从项目列表进入房间,进入房间更多页,操作修改名称 校验:1、获取修改后的房间title,与修改的name作校验 :return: """ #进入设备列表页面 self.DevicePage.into_devicePage() #进入房间更多页 self.DevicePage.into_room_more() NewName = str(random.randint(0,99)) + "楼_" + "房间_" + str(random.randint(0,99)) self.DevicePage.set_room_name(NewName) #返回设备列表页面,获取其房间名称 self.DevicePage.go_back() actual_name = self.DevicePage.get_roomName() assert actual_name == NewName, "修改房间名称失败,期望:%s, 实际:%s" % (NewName, actual_name) @allure.feature("设备管理模块") @allure.story("修改设备名称--正向用例") @allure.title("修改设备名称测试") def test_05_changeDeviceName(self): """ 用例描述: 测试点:修改设备名称 用例步骤:1、选择某个设备进去更多页 校验:1、获取修改后的设备name,与修改的name作校验 :return: """ #进入设备列表页面 #self.DevicePage.into_devicePage() #选择第一个设备进入设备更多页 self.DevicePage.into_deviceMore_page() NewName = "米兰_" + str(random.randint(0,99)) + "_设备_" + str(random.randint(0,99)) self.DevicePage.set_device_name(NewName) #actual_toast = self.DevicePage.sucess_toast() self.DevicePage.go_back() actual_name = self.DevicePage.get_device_name() assert actual_name == NewName @allure.feature("设备管理模块") @allure.story("修改设备开关名称--正向用例") @allure.title("修改设备开关名称测试") def test_06_changeOnOffName(self): """ 用例描述: 测试点:修改设备开关名称 用例步骤:1、选择某个设备进入更多页,操作开关重命名修改 校验:1、获取修改后的设备开关name,与修改的name作校验 :return: """ #进入设备列表页面 #self.DevicePage.into_devicePage() #选择第一个设备进入设备更多页 self.DevicePage.into_deviceMore_page() NewName = "修改的" + str(random.randint(0,99)) + "_开关" + str(random.randint(0,99)) self.DevicePage.set_device_function_name(NewName) actual_toast = self.DevicePage.sucess_toast() assert actual_toast == "修改成功" #回到设备更多页 self.DevicePage.back() @allure.feature("设备管理模块") @allure.story("修改设备位置--正向用例") @allure.title("修改设备位置测试") def test_07_changeDeviceLocation(self): """ 用例描述: 测试点:修改设备位置 用例步骤:1、选择某个设备进入更多页,操作设备位置修改 校验:1、获取修改后的设备位置,与修改的位置作校验/获取toast :return: """ # 进入设备列表页面 #self.DevicePage.into_devicePage() # 选择第一个设备进入设备更多页 #self.DevicePage.into_deviceMore_page() self.DevicePage.set_device_location() actual_toast = self.DevicePage.sucess_toast() assert actual_toast == "修改成功" # 回到设备更多页 self.DevicePage.back() @allure.feature("设备管理模块") @allure.story("修改设备点位--正向用例") @allure.title("修改设备点位测试") def test_08_changeDevicePoint(self): """ 用例描述: 测试点:修改设备点位 用例步骤:1、选择某个设备进入更多页,操作设备点位修改 校验:1、获取修改后的点位,与修改的点位作校验 :return: """ # 进入设备列表页面 #self.DevicePage.into_devicePage() # 选择第一个设备进入设备更多页 #self.DevicePage.into_deviceMore_page() NewName = str(random.randint(0,99)) + "楼_" + str(random.randint(0,99)) + "房间" self.DevicePage.set_device_pointName(NewName) actual_toast = self.DevicePage.sucess_toast() assert actual_toast == "修改成功" # 回到设备更多页 self.DevicePage.go_back() # 回到设备单控页 self.DevicePage.go_back() # 回到设备列表页面 self.DevicePage.go_back() #@pytest.mark.skip(reason='skip testing this') @allure.feature("联动管理模块") @allure.story("新建联动--正向用例") @allure.title("新建一键联动测试") def test_09_add_oneKeyRule(self): """ 用例描述: 测试点:新建一键联动 用例步骤:1、新建一键联动 校验:1、拿到最新一键联动的名称与创建的名称做比较 :return: """ self.RulePage.into_rulePage() rule_name = "一键联动" + str(random.randint(0,99)) self.RulePage.into_oneKey_page() self.RulePage.into_cloud_rule() self.RulePage.set_rule_name(rule_name) self.RulePage.add_one_key_type() self.RulePage.add_actionOrCondition("cloud",0,0,0,1,1) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name, "新建一键联动失败, 期望: %s, 实际: %s" % (rule_name, actual_name) @allure.feature("联动管理模块") @allure.story("编辑联动--正向用例") @allure.title("编辑一键联动测试") def test_10_edit_oneKeyRule(self): """ 用例描述: 测试点:编辑一键联动 用例步骤:1、编辑一键联动:名称及条件动作 校验:1、拿到最新一键联动的名称与创建的名称做比较 :return: """ #self.RulePage.into_rulePage() rule_name = "修改" + str(random.randint(0,99)) + "_" + "一键" + str(random.randint(0,99)) self.RulePage.into_oneKey_page() self.RulePage.into_oneKey_rule() self.RulePage.set_rule_name(rule_name) self.RulePage.add_actionOrCondition("cloud",1,0,0,1,1) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name @allure.feature("联动管理模块") @allure.story("删除联动--正向用例") @allure.title("删除一键联动测试") def test_11_del_oneKeyRule(self): """ 用例描述: 测试点:删除一键联动 用例步骤:1、删除一键联动 校验:1、toast校验 :return: """ #self.RulePage.into_rulePage() self.RulePage.into_oneKey_page() self.RulePage.into_oneKey_rule() self.RulePage.del_rule() actual_toast = self.RulePage.remove_toast() assert actual_toast == "删除成功" @allure.feature("联动管理模块") @allure.story("新建联动--正向用例") @allure.title("新建云端联动测试") def test_12_add_autoCloudRule(self): """ 用例描述: 测试点:新建云端联动 用例步骤:1、新建云端联动 校验:1、拿到最新联动的名称与创建的名称做校验 :return: """ rule_name = "云端联动" + str(random.randint(0,9999)) self.RulePage.into_autoRule_page() self.RulePage.into_cloud_rule() self.RulePage.set_rule_name(rule_name) self.RulePage.add_actionOrCondition("cloud",0,0,0,0,1) self.RulePage.add_actionOrCondition("cloud",1,0,0,1,1) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name, "新建云端自动化联动失败, 期望: %s, 实际: %s" % (rule_name, actual_name) @allure.feature("联动管理模块") @allure.story("编辑联动--正向用例") @allure.title("编辑云端联动测试") def test_13_edit_autoCloudRule(self): """ 用例描述: 测试点:编辑云端联动 用例步骤:1、拿到最新建的云端联动,进行编辑:联动名称、动作、条件 校验:1、拿到最新联动的名称与创建的名称做校验 :return: """ rule_name = "修改" + str(random.randint(0,99)) + "_" + "云端" + str(random.randint(0,99)) self.RulePage.into_auto_rule() self.RulePage.set_rule_name(rule_name) self.RulePage.add_actionOrCondition("cloud",0,0,1,0,1) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name @allure.feature("联动管理模块") @allure.story("删除联动--正向用例") @allure.title("删除云端联动测试") def test_14_del_autoCloudRule(self): """ 用例描述: 测试点:删除云端联动 用例步骤:1、删除云端联动 校验:1、toast校验 :return: """ #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_auto_rule() self.RulePage.del_rule() actual_toast = self.RulePage.remove_toast() assert actual_toast == "删除成功" @allure.feature("联动管理模块") @allure.story("新建联动--正向用例") @allure.title("新建A2本地联动测试") def test_15_add_autoA2LocalRule(self): """ 用例描述: 测试点:新建A2本地联动 用例步骤:1、新建A2本地联动 校验:1、拿到最新联动的名称与创建的名称做校验 :return: """ rule_name = "新建" + str(random.randint(0,99)) + "_A2本地_" + str(random.randint(0,99)) #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_select_local_rule("A2") self.RulePage.set_rule_name(rule_name) self.RulePage.add_actionOrCondition("A2",0,0,0,0,1) self.RulePage.add_actionOrCondition("A2",0,0,1,1,1) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name @allure.feature("联动管理模块") @allure.story("编辑联动--正向用例") @allure.title("编辑A2本地联动测试") def test_16_edit_autoA2LocalRule(self): """ 用例描述: 测试点:编辑A2本地联动 用例步骤:1、编辑A2本地联动 校验:1、拿到最新联动的名称与创建的名称做校验 :return: """ rule_name = "修改" + str(random.randint(0, 99)) + "_" + "A2本地" + str(random.randint(0, 99)) #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_auto_rule() self.RulePage.set_rule_name(rule_name) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name @allure.feature("联动管理模块") @allure.story("删除联动--正向用例") @allure.title("删除A2本地联动测试") def test_17_del_autoA2LocalRule(self): """ 用例描述: 测试点:删除A2本地联动 用例步骤:1、删除A2本地联动 校验:1、获取toast提示 :return: """ #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_auto_rule() self.RulePage.del_rule() actual_toast = self.RulePage.remove_toast() assert actual_toast == "删除成功" @pytest.mark.skip(reason='skip testing this') @allure.feature("联动管理模块") @allure.story("新建联动--正向用例") @allure.title("新建罗马本地联动测试") def test_18_add_autoAylaLocalRule(self): """ 用例描述: 测试点:新建罗马本地联动 用例步骤:1、新建罗马本地联动 校验:1、拿到最新联动的名称与创建的名称做校验 :return: """ rule_name = "新建" + str(random.randint(0, 99)) + "_罗马本地_" + str(random.randint(0, 99)) #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_select_local_rule("ayla") self.RulePage.set_rule_name(rule_name) self.RulePage.add_actionOrCondition("ayla", 0, 0, 0, 0, 1) self.RulePage.add_actionOrCondition("ayla", 0, 0, 1, 1, 1) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name @pytest.mark.skip(reason='skip testing this') @allure.feature("联动管理模块") @allure.story("编辑联动--正向用例") @allure.title("编辑罗马本地联动测试") def test_19_edit_autoAylaLocalRule(self): """ 用例描述: 测试点:编辑罗马本地联动 用例步骤:1、编辑罗马本地联动 校验:1、拿到最新联动的名称与创建的名称做校验 :return: """ rule_name = "修改" + str(random.randint(0, 99)) + "_" + "罗马本地" + str(random.randint(0, 99)) #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_auto_rule() self.RulePage.set_rule_name(rule_name) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name @pytest.mark.skip(reason='skip testing this') @allure.feature("联动管理模块") @allure.story("删除联动--正向用例") @allure.title("删除罗马本地联动测试") def test_20_del_autoAylaLocalRule(self): """ 用例描述: 测试点:删除罗马本地联动 用例步骤:1、删除罗马本地联动 校验:1、获取toast提示 :return: """ #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_auto_rule() self.RulePage.del_rule() actual_toast = self.RulePage.remove_toast() assert actual_toast == "删除成功" @allure.feature("联动管理模块") @allure.story("新建联动--正向用例") @allure.title("新建米兰本地联动测试") def test_21_add_autoAliLocalRule(self): """ 用例描述: 测试点:新建米兰本地联动 用例步骤:1、新建米兰本地联动 校验:1、拿到最新联动的名称与创建的名称做校验 :return: """ rule_name = "新建" + str(random.randint(0, 99)) + "_米兰本地_" + str(random.randint(0, 99)) #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_select_local_rule("ali") self.RulePage.set_rule_name(rule_name) self.RulePage.add_actionOrCondition("ali", 0, 0, 0, 0, 1) self.RulePage.add_actionOrCondition("ali", 1, 0, 1, 1, 1) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name @allure.feature("联动管理模块") @allure.story("编辑联动--正向用例") @allure.title("编辑米兰本地联动测试") def test_22_edit_autoAliLocalRule(self): """ 用例描述: 测试点:编辑米兰本地联动 用例步骤:1、编辑米兰本地联动 校验:1、拿到最新联动的名称与创建的名称做校验 :return: """ rule_name = "修改" + str(random.randint(0, 99)) + "_" + "米兰本地" + str(random.randint(0, 99)) #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_auto_rule() self.RulePage.set_rule_name(rule_name) self.RulePage.save_rule() actual_name = self.RulePage.get_rule_name() assert actual_name == rule_name @allure.feature("联动管理模块") @allure.story("删除联动--正向用例") @allure.title("删除米兰本地联动测试") def test_23_del_autoAliLocalRule(self): """ 用例描述: 测试点:删除米兰本地联动 用例步骤:1、删除米兰本地联动 校验:1、获取toast提示 :return: """ #self.RulePage.into_rulePage() self.RulePage.into_autoRule_page() self.RulePage.into_auto_rule() self.RulePage.del_rule() actual_toast = self.RulePage.remove_toast() self.DevicePage.back() self.DevicePage.back() assert actual_toast == "删除成功" @allure.feature("方案模块") @allure.story("分享方案--正向用例") @allure.title("分享方案") def test_24_sharePlan(self): """ 用例描述: 前置条件:房间下有设备 测试点:分享方案 用例步骤:1、进入房间更多页,进入方案设置页,操作分享方案 校验:方案口令已复制 元素存在 :return: """ self.DevicePage.into_devicePage() self.DevicePage.into_room_more() self.DevicePage.into_plan_page() share_code = self.DevicePage.get_share_plan() self.DevicePage.go_to_room_list() self.DevicePage.go_back() assert share_code != None @allure.feature("方案模块") @allure.story("添加方案--正向用例") @allure.title("添加方案") #@pytest.mark.parametrize("plan_code", ["8659f82b95974d1b82449820b8e79822"]) def test_25_addPlan(self): """ 用例描述: 前置条件:先创建新房间 测试点:导入方案 用例步骤:1、先创建一个新房间,进入该房间,进行导入方案 :param plan_code: :return: """ plan_code = "8659f82b95974d1b82449820b8e79822" self.test_02_addProject() self.DevicePage.into_devicePage() self.DevicePage.into_room_more() self.DevicePage.into_plan_page() self.DevicePage.add_plan(plan_code) #actual_toast = self.DevicePage.add_sucess_toast() flag = self.DevicePage.is_add_plan_succ() assert flag self.DevicePage.go_back() self.DevicePage.go_back() self.test_03_removeProject() @allure.feature("项目管理") @allure.story("添加项目--正向用例") @allure.title("创建地产项目") def test_26_addEstateProject(self): """ 用例描述: 前置条件:切换到地产项目 测试点:创建地产项目 用例步骤:操作创建地产项目 校验:1、获取当前最新项目的title,与project_name做比较 :return: """ project_name = "自动化" + str(random.randint(0, 99)) + "_创建" + str(random.randint(0, 99)) self.ProjectPage.change_to_estate() self.ProjectPage.add_project(project_name) actual_name = self.ProjectPage.get_project_name() assert actual_name == project_name
class LoginPage(ElementLoader): driver = AutoDriver() def __init__(self): ElementLoader.__init__(self, self.__class__.__name__) def login_user_field(self, user_ele): username_field = self.driver.find_element_until_visibility( self.locator("username_field")) return username_field def login_pass_field(self, user_pass): password_field = self.driver.find_element_until_visibility( self.locator("password_field")) return password_feild def login_btn(self, loginBtn): login_btn = self.driver.find_element_until_visibility( self.locator("login_button")) return login_btn @allure.step("登录") def app_login(self, username, password): """ 登录APP :param username: 用户名 :param password: 密码 :return: """ username_field = self.driver.find_element_until_visibility( self.locator("username_field")) self.driver.send_keys(username_field, username) password_field = self.driver.find_element_until_visibility( self.locator("password_field")) self.driver.send_keys(password_field, password) time.sleep(2) login_btn = self.driver.find_element_until_visibility( self.locator("login_button")) self.driver.click(login_btn) @allure.step("注册账号") def user_register(self, register_user_name, register_account, register_pass): """ 注册账号 :param register_user_name: 用户名 :param register_account: 账号 :param register_pass: 密码 :return: """ register_page_btn = self.driver.find_element_until_visibility( self.locator("register_page_btn")) self.driver.click(register_page_btn) #进入注册页面 register_user_name_field = self.driver.find_element_until_visibility( self.locator("register_user_name")) self.driver.clear(register_user_name_field) self.driver.send_keys(register_user_name_field, register_user_name) register_account_field = self.driver.find_element_until_visibility( self.locator("register_account")) self.driver.clear(register_account_field) self.driver.send_keys(register_account_field, register_account) register_pass_field = self.driver.find_element_until_visibility( self.locator("register_pass")) self.driver.clear(register_pass_field) self.driver.send_keys(register_pass_field, register_pass) register_btn = self.driver.find_element_until_visibility( self.locator("register_btn")) self.driver.click(register_btn) @allure.step("返回登录页面") def back_login_page(self): """ 返回登录页面 :return: """ back_login = self.driver.find_element_until_visibility( self.locator("login_page_btn")) self.driver.click(back_login) @allure.step("判断是否在登录页面") def is_in_login_page(self): """用于判断是否是在登录页面""" flag = self.driver.is_element(self.locator("register_page_btn"), 3) return flag #以下用于toast验证 def account_null_toast(self): """ 账号为空 :return: """ #toast = self.driver.is_toast_exist(self.locator("account_null")).text toast = self.driver.get_toast("登录账号不能为空") if toast == "Toast no found": return "获取不到toast" else: toast_text = toast.text #print(toast_text) return toast_text def password_null_toast(self): """ 密码为空 :return: """ #toast = self.driver.is_toast_exist(self.locator("password_null")).text toast_text = self.driver.get_toast("登陆密码不能为空").text return toast_text def password_error_toast(self): """ 密码错误 :return: """ toast_text = self.driver.get_toast("密码错误").text #print(toast) return toast_text def account_error_toast(self): """ 错误的账号 :return: """ toast = self.driver.get_toast("请输入正确的邮箱或手机号码").text return toast def account_no_exist_toast(self): """ 不存在的用户账号或错误的密码 :return: """ toast = self.driver.find_element_until_visibility( self.locator("error_show")).text return toast def register_account_error_toast(self): """ 错误格式的账号 :return: """ toast = self.driver.get_toast("请输入正确的邮箱或手机号码").text return toast def register_username_null_toast(self): """ 注册用户名为空 :return: """ toast = self.driver.get_toast("用户名不能为空").text return toast def register_pass_error_toast(self): """ 不符合规范的密码 :return: """ toast = self.driver.get_toast("密码长度不能少于6位").text return toast def register_succ_toast(self): """注册成功""" toast = self.driver.get_toast("注册成功").text return toast
class ProjectPage(ElementLoader): driver = AutoDriver() def __init__(self): ElementLoader.__init__(self, self.__class__.__name__) @allure.step("判断是否在项目页面") def is_project_page(self): """用于判断是不是在项目页面,是返回True,不是返回False""" #print("进入校验") flag = self.driver.is_element(self.locator("project_page_title"), 3) #print(flag) return flag @allure.step("获取项目名称") def get_project_name(self, num=0): """ 从项目列表中获取项目名称 :param num: 项目列表序列,默认为第一个 :return: 项目名称 """ project = self.driver.find_elements_until_visibility(self.locator("project_name")) name = project[num+1].text#num=0是"我的项目"标题 return name @allure.step("获取项目数") def get_project_num(self): """ 从项目列表中获取项目个数 :return: 项目数 """ flag = self.driver.is_element(self.locator("project_type")) if flag: project = self.driver.find_elements_until_visibility(self.locator("project_type")) number = len(project) else: number = 0 return number @allure.step("创建项目") def add_project(self, name = "", type=False): """ 创建项目,默认创建展箱 :param name:项目名称 :param type:项目类型默认为展厅 :return: """ add_project_btn = self.driver.find_element_until_visibility(self.locator("project_add_btn")) self.driver.click(add_project_btn) time.sleep(2) project_name_btn = self.driver.find_element_until_visibility(self.locator("project_name_btn")) self.driver.click(project_name_btn) project_name_field = self.driver.find_element_until_visibility(self.locator("project_name_field")) self.driver.send_keys(project_name_field, name) v_done_btn = self.driver.find_element_until_visibility(self.locator("v_done")) self.driver.click(v_done_btn) if type: zt_btn = self.driver.find_element_until_visibility(self.locator("project_type_zt")) self.driver.click(zt_btn) save = self.driver.find_element_until_visibility(self.locator("project_save_btn")) self.driver.click(save) @allure.step("进入项目详情页") def intoProjectInfo(self, num=0): """进入项目详情页面""" #project_class = "android.widget.TextView" #project_btn = self.driver.get_text_ele(project_class, "验证导入") project_btn = self.driver.find_elements_until_visibility(self.locator("project_type")) time.sleep(1) self.driver.click(project_btn[num]) @allure.step("判断项目类型") def projectTypeFlag(self, num=0): """ 判断项目类型,type为正式的,不能操作删除 :param num: 默认为第一个 :return: """ type_flag = False flag = self.driver.is_element(self.locator("project_name")) if flag: types = self.driver.find_elements_until_visibility(self.locator("project_type_1")) type_text = types[num].text if type_text != "正式": type_flag = True else: logger.info("暂无项目") return type_flag @allure.step("切换地产行业") def change_to_estate(self): """ 切换到地产行业 :return: """ change_btn = self.driver.find_element_until_visibility(self.locator("project_page_title")) self.driver.click(change_btn) estate_btn = self.driver.find_element_until_visibility(self.locator("estate_change_btn")) self.driver.click(estate_btn) time.sleep(10)
#@project: ayla_ui_project #@author: heyeping #@file: conftest.py.py #@ide: PyCharm #@time: 2021/5/25 4:16 PM import pytest from selenium import webdriver from BaseDriver.Driver import AutoDriver import os, time import allure _driver = AutoDriver() @pytest.hookimpl(tryfirst=True, hookwrapper=True) def pytest_runtest_makereport(item, call): """ 获取每个用例状态的钩子函数 :param item: :param call: :return: """ #获取钩子方法的调用结果 outcome = yield rep = outcome.get_result() #仅仅获取用例call执行结果是失败的情况,不包含setup/teardown if rep.when == "call" and rep.failed: mode = "a" if os.path.exists("failures") else "w" with open("failures", mode) as f: if "tmpdir" in item.fixturenames: extra = " (%s)" % item.funcargs["tmpdir"]
class DevicePage(ElementLoader): driver = AutoDriver() #ElementLoader = ElementLoader() ProjectPage = ProjectPage() RoomPage = RoomPage() #device_names = driver.find_elements_until_visibility(ElementLoader.locator("device_name")) #more_btn = driver.find_element_until_visibility(ElementLoader.locator("room_more_btn")) def __init__(self): ElementLoader.__init__(self, self.__class__.__name__) @allure.step("进入设备列表页面") def into_devicePage(self): """ 进入设备列表页面 :return: """ #进入房间列表页面 self.ProjectPage.intoProjectInfo() #进入设备列表页面 self.RoomPage.into_rommPage() devicePage_btn = self.driver.find_element_until_visibility( self.locator("device_page")) self.driver.click(devicePage_btn) @allure.step("返回操作") def back(self): self.driver.click_device_btn(4) @allure.step("获取当前房间的name") def get_roomName(self): """获取当前房间name""" roomName_btn = self.driver.find_element_until_visibility( self.locator("roomName")) roomName = roomName_btn.text return roomName @allure.step("判断是否在device页面") def is_in_devicePage(self): """ 判断是否在device页面 :return: """ flag = self.driver.is_element(self.locator("device_page")) return flag @allure.step("获取设备名称") def get_device_name(self, num=0): """ 获取设备名称 :param num:默认获取第一个设备 :return: """ device_names = self.driver.find_elements_until_visibility( self.locator("device_name")) device_name = device_names[num].text return device_name @allure.step("获取设备数") def get_device_num(self): """ 获取设备 :return:设备数 """ #判断是否存在tv_device_online_status元素,不存在就返回0 device_names = self.driver.find_elements_until_visibility( self.locator("device_name")) flag = self.driver.is_element(self.locator("device_status")) if flag: device_nums = len(device_names) else: device_nums = 0 return device_nums @allure.step("设置房间名称") def set_room_name(self, roomName=None): """ 设置房间名称 :return: """ room_name_btn = self.driver.find_element_until_visibility( self.locator("room_name_btn")) self.driver.click(room_name_btn) roomName_text = self.driver.find_element_until_visibility( self.locator("name_text")) self.driver.send_keys(roomName_text, roomName) done_btn = self.driver.find_element_until_visibility( self.locator("done_btn")) self.driver.click(done_btn) @allure.step("进入房间更多页") def into_room_more(self): """ 进入房间更多页 :return: """ roomMore_btn = self.driver.find_element_until_visibility( self.locator("room_more_btn")) self.driver.click(roomMore_btn) # flag = self.is_in_devicePage() # if flag: # # else: # return "not in devicePage" @allure.step("判断是否在房间更多页") def is_in_roomMorePage(self): """ 判断是否在房间更多页 :return: """ flag = self.driver.is_element(self.locator("room_name_btn")) return flag @allure.step("移除房间") def del_room(self): """ 删除房间 :return: """ flag = self.is_in_roomMorePage() if flag: remove_btn = self.driver.find_element_until_visibility( self.locator("btn_remove_room")) self.driver.click(remove_btn) v_done = self.driver.find_element_until_visibility( self.locator("done_btn")) self.driver.click(v_done) else: return "not in roomMorePage" @allure.step("进入方案设置页") def into_plan_page(self): """ 进入方案分享页 :return: """ rl_room_plan = self.driver.find_element_until_visibility( self.locator("rl_room_plan")) rl_room_plan.click() @allure.step("添加方案") def add_plan(self, plan_code=None): """ 添加方案 :param plan_code: 方案包 :return: """ #判断房间是否已使用过方案,通过room_plan_type元素的text进行判断 room_plan_type_ele = self.driver.find_element_until_visibility( self.locator("room_plan_type")) room_plan_type_text = room_plan_type_ele.text if room_plan_type_text == "未使用": #操作添加方案按钮 add_plan_ele = self.driver.find_element_until_visibility( self.locator("add_plan")) self.driver.click(add_plan_ele) #输入方案包 code_text = self.driver.find_element_until_visibility( self.locator("code_text")) self.driver.send_keys(code_text, plan_code) #操作导入 done_btn = self.driver.find_element_until_visibility( self.locator("room_more_btn")) self.driver.click(done_btn) elif room_plan_type_text == "已使用": # 操作更换方案按钮 add_plan_ele = self.driver.find_element_until_visibility( self.locator("add_plan")) self.driver.click(add_plan_ele) #确定清空方案 v_done = self.driver.find_element_until_visibility( self.locator("done_btn")) self.driver.click(v_done) # 输入方案包 code_text = self.driver.find_element_until_visibility( self.locator("code_text")) self.driver.send_keys(code_text, plan_code) # 操作导入 done_btn = self.driver.find_element_until_visibility( self.locator("room_more_btn")) self.driver.click(done_btn) @allure.step("分享方案") def get_share_plan(self): """ 分享方案 :return: """ #操作分享 share_btn = self.driver.find_element_until_visibility( self.locator("share_plan")) self.driver.click(share_btn) #获取分享码 share_code_flag = self.driver.is_element(self.locator("plan_code")) if share_code_flag: share_code_btn = self.driver.find_element_until_visibility( self.locator("plan_code")) share_code = share_code_btn.text else: share_code = None return share_code @allure.step("判断导入方案是否成功") def is_add_plan_succ(self): """ 判断待添加设备存在 :return: """ flag = self.driver.is_element(self.locator("device_no_add")) return flag @allure.step("返回房间列表页") def go_to_room_list(self): """ 前往房间列表 :return: """ v_done = self.driver.find_element_until_visibility( self.locator("done_btn")) self.driver.click(v_done) @allure.step("进入设备更多页") def into_deviceMore_page(self, num=0): """ 进入设备更多页面,默认第一个设备 :param num: 默认第一个设备 :return: """ device_names = self.driver.find_elements_until_visibility( self.locator("device_name")) self.driver.click(device_names[num]) #time.sleep(2) #尝试切换context,用class_name不行,不切context使用原生的xpath可以,前提是包要确保需要开启webview远程调试功能:this.appView.setWebContentsDebuggingEnabled(true); #context = self.driver.get_all_contexts() #self.driver.switch_to_context("WEBVIEW_com.ayla.hotelsaas") #return context #判断当前是否存在设备更多页,false则是进入单控页 flag = self.driver.is_element(self.locator("device_more_title")) if flag: print("已进入设备更多页") else: more_btn = self.driver.find_element_until_visibility( self.locator("more_btn")) self.driver.click(more_btn) @allure.step("设置设备名称") def set_device_name(self, name=None): """ 设置设备名称 :param name: :return: """ #self.into_deviceMore_page(0) device_name_btn = self.driver.find_element_until_visibility( self.locator("device_name")) self.driver.click(device_name_btn) device_name_text = self.driver.find_element_until_visibility( self.locator("name_text")) self.driver.send_keys(device_name_text, name) done_btn = self.driver.find_element_until_visibility( self.locator("done_btn")) self.driver.click(done_btn) @allure.step("设置开关重命名") def set_device_function_name(self, name=None): """ 设置开关重命名 :param name: :return: """ device_function_name = self.driver.find_element_until_visibility( self.locator("device_function_name")) self.driver.click(device_function_name) tv_nicknames = self.driver.find_elements_until_visibility( self.locator("tv_nickname")) self.driver.click(tv_nicknames[0]) nickname_text = self.driver.find_element_until_visibility( self.locator("name_text")) self.driver.send_keys(nickname_text, name) done_btn = self.driver.find_element_until_visibility( self.locator("done_btn")) self.driver.click(done_btn) @allure.step("设置设备点位") def set_device_pointName(self, name=None): """ 设置设备点位 :param name: :return: """ rl_location = self.driver.find_element_until_visibility( self.locator("rl_location")) self.driver.click(rl_location) rl_region_name = self.driver.find_element_until_visibility( self.locator("rl_region_name")) self.driver.click(rl_region_name) region_name_text = self.driver.find_element_until_visibility( self.locator("name_text")) self.driver.send_keys(region_name_text, name) done_btn = self.driver.find_element_until_visibility( self.locator("done_btn")) self.driver.click(done_btn) @allure.step("设置设备位置") def set_device_location(self, num=0): """ 设置设备位置 :param num: 默认设置第一个 :return: """ rl_location = self.driver.find_element_until_visibility( self.locator("rl_location")) self.driver.click(rl_location) device_location = self.driver.find_element_until_visibility( self.locator("device_location")) self.driver.click(device_location) device_location_types = self.driver.find_elements_until_visibility( self.locator("device_location_type")) self.driver.click(device_location_types[num]) @allure.step("返回操作") def go_back(self): """ 返回操作 :return: """ iv_left = self.driver.find_element_until_visibility( self.locator("iv_left")) self.driver.click(iv_left) # 以下用于toast验证 def remove_toast(self): """ 移除成功 :return: """ toast = self.driver.get_toast("移除成功").text return toast def sucess_toast(self): """ 修改成功 :return: """ toast = self.driver.get_toast("修改成功").text return toast def add_sucess_toast(self): """ 导入成功 :return: """ toast = self.driver.get_toast("导入成功").text
class RulePage(ElementLoader): driver = AutoDriver() ProjectPage = ProjectPage() RoomPage = RoomPage() def __init__(self): ElementLoader.__init__(self, self.__class__.__name__) @allure.step("进入规则模块") def into_rulePage(self): """ 进入规则模块 :return: """ # 进入房间列表页面 #self.ProjectPage.intoProjectInfo() # 进入设备列表页面 #self.RoomPage.into_rommPage() #进入规则列表页面 rulePage_btn = self.driver.find_element_until_visibility( self.locator("rule_page")) self.driver.click(rulePage_btn) @allure.step("进入一键联动列表") def into_oneKey_page(self): """ 进入一键联动列表 :return: """ onekey_page_btn = self.driver.find_element_until_visibility( self.locator("rule_onekey_list")) self.driver.click(onekey_page_btn) @allure.step("进入自动化列表页面") def into_autoRule_page(self): """ 进入自动化列表页面 :return: """ autoRule_page_btn = self.driver.find_element_until_visibility( self.locator("rule_auto_list")) self.driver.click(autoRule_page_btn) @allure.step("获取联动名称") def get_rule_name(self, num=0): """ 获取联动名称 :param num:默认为第一个 :return: 联动名称 """ rule_names = self.driver.find_elements_until_visibility( self.locator("device_names")) rule_name = rule_names[num].text return rule_name @allure.step("获取一键联动个数") def get_oneKey_rule_num(self): """ 从一键联动列表中获取一键联动的个数 :return: 一键联动的个数 """ oneKey_rules = self.driver.find_elements_until_visibility( self.locator("rule_names")) oneKey_rule_num = len(oneKey_rules) return oneKey_rule_num @allure.step("进入添加云端联动") def into_cloud_rule(self): """ 进入添加云端联动页面 :return: """ add_btn = self.driver.find_element_until_visibility( self.locator("add_btn")) self.driver.click(add_btn) cloud_rule_btn = self.driver.find_element_until_visibility( self.locator("cloud_rule_btn")) self.driver.click(cloud_rule_btn) @allure.step("进入添加本地联动") def into_local_rule(self, num=0): """ 进入添加本地联动页面,存在多个网关时,默认进入第一个 :return: """ add_btn = self.driver.find_element_until_visibility( self.locator("add_btn")) self.driver.click(add_btn) local_rule_btn = self.driver.find_element_until_visibility( self.locator("local_rule_btn")) self.driver.click(local_rule_btn) flag = self.driver.is_element(self.locator("select_net")) if flag: net_btn = self.driver.find_elements_until_visibility( self.locator("nets_icon")) self.driver.click(net_btn[num]) @allure.step("选择性进入本地联动添加页面") def into_select_local_rule(self, net_select='ayla'): """ 选择性进入本地联动添加页面 :param net_select: 默认进入罗马网关 :return: """ add_btn = self.driver.find_element_until_visibility( self.locator("add_btn")) self.driver.click(add_btn) local_rule_btn = self.driver.find_element_until_visibility( self.locator("local_rule_btn")) self.driver.click(local_rule_btn) flag = self.driver.is_element(self.locator("select_net")) if flag: if net_select == "ayla": ayla_net_btn = self.driver.find_element_until_visibility( self.locator("ayla_net")) self.driver.click(ayla_net_btn) elif net_select == "ali": ali_net_btn = self.driver.find_element_until_visibility( self.locator("ali_net")) self.driver.click(ali_net_btn) elif net_select == "A2": A2_net_btn = self.driver.find_element_until_visibility( self.locator("A2_net")) self.driver.click(A2_net_btn) else: return "暂无网关" else: return "not found" @allure.step("设置规则名称") def set_rule_name(self, ruleName=None): """ 设置规则名称 :return: """ rule_name_btn = self.driver.find_element_until_visibility( self.locator("rule_name")) self.driver.click(rule_name_btn) rule_name_text = self.driver.find_element_until_visibility( self.locator("rule_name_field")) self.driver.send_keys(rule_name_text, ruleName) ensure_btn = self.driver.find_element_until_visibility( self.locator("done_btn")) self.driver.click(ensure_btn) @allure.step("添加一键执行按钮") def add_one_key_type(self): """ 条件添加一键执行按钮 :return: """ add_condition_btn = self.driver.find_element_until_visibility( self.locator("add_condition_btn")) self.driver.click(add_condition_btn) type_one_key = self.driver.find_element_until_visibility( self.locator("type_one_key")) self.driver.click(type_one_key) @allure.step("添加条件或动作") def add_actionOrCondition(self, rule_type="cloud", device_num=0, function1_num=0, function2_num=0, flag_AC=0, AC_num=1): """ 添加条件或动作 :param rule_type:联动的类型cloud:云端(会进入条件选择/动作选择页面),A2、米兰网关、罗马不会进入条件选择页面,A2、罗马会进入动作选择页 :param device_num:选择的设备,默认为第一个 :param function1_num:选择功能,默认第一个 :param function2_num:选择最终功能,默认第一个 :param flag_AC:默认为添加条件,值不为0是添加动作 :param AC_num:添加多少个,默认添加1个 :return: """ i = 0 while i < AC_num: if flag_AC == 0: """进入的是添加条件页面""" add_condition_btn = self.driver.find_element_until_visibility( self.locator("add_condition_btn")) self.driver.click(add_condition_btn) if rule_type == "cloud": # 进入选择设备功能页面 device_changed_btn = self.driver.find_element_until_visibility( self.locator("type_device_changed")) self.driver.click(device_changed_btn) else: """进入的是添加动作页面""" add_action_btn = self.driver.find_element_until_visibility( self.locator("add_action_btn")) self.driver.click(add_action_btn) if rule_type == "cloud" or rule_type == "A2" or rule_type == "ayla": # 进入选择设备功能页面 device_changed_btn = self.driver.find_element_until_visibility( self.locator("type_device_changed")) self.driver.click(device_changed_btn) flag = self.driver.is_element(self.locator("device_names")) if flag: device_names = self.driver.find_elements_until_visibility( self.locator("device_names")) self.driver.click(device_names[device_num]) function_name_btn = self.driver.find_elements_until_visibility( self.locator("function_name_btn")) self.driver.click(function_name_btn[function1_num]) cb_function_checkeds = self.driver.find_elements_until_visibility( self.locator("cb_function_checked")) self.driver.click(cb_function_checkeds[function2_num]) save_btn = self.driver.find_element_until_visibility( self.locator("save_btn")) self.driver.click(save_btn) else: print("暂无设备") i += 1 @allure.step("保存操作") def save_rule(self): """ 保存操作 :return: """ save_btn = self.driver.find_element_until_visibility( self.locator("save_btn")) self.driver.click(save_btn) @allure.step("统计联动个数") def rule_nums(self): """ 统计联动的个数:通过tv_device_name元素的个数统计 判断是否存在tv_device_name元素 :return: """ flag = self.driver.is_element(self.locator("device_names")) if flag: rule = self.driver.find_elements_until_visibility( self.locator("device_names")) rule_nums = len(oneKey) else: rule_nums = 0 return rule_nums @allure.step("获取某个联动的状态") def get_rule_status(self, mun=0): """ 获取某个联动当前的状态:开启/关闭 :param num:默认第一个 :return: """ flag = self.driver.is_element(self.locator("device_names")) if flag: rules = self.driver.find_elements_until_visibility( self.locator("rule_status")) rule_status = rules[mun].text return rule_status else: return "no rule" @allure.step("改变联动状态") def change_rule_status(self, num=0): """ 改变联动状态 :param mun:默认第一个 :return: """ flag = self.driver.is_element(self.locator("device_names")) if flag: status = self.driver.find_elements_until_visibility( self.locator("rule_status")) self.driver.click(status[num]) else: return "no rule" @allure.step("进入联动编辑页面") def into_auto_rule(self, num=0): """ 进入原有的联动(云端+本地)编辑页 :param num: 默认第一个 :return: """ rules = self.driver.find_elements_until_visibility( self.locator("device_names")) self.driver.click(rules[num]) @allure.step("进入一键联动编辑页面") def into_oneKey_rule(self, num=0): """ 进入原有的一键联动编辑页 :param num: 默认第一个 :return: """ edit_btn = self.driver.find_elements_until_visibility( self.locator("edit_onekey_btn")) self.driver.click(edit_btn[num]) #time.sleep(2) @allure.step("删除联动") def del_rule(self): """ 删除联动 :return: """ time.sleep(2) self.driver.swipe_control("u") #self.driver.swipeElement("rule_del_btn") # size = self.driver.getSize() # x = size['width'] # y = size['height'] # self.driver.swipe(x*0.5, y*0.5, x*0.5, y*0.2) rule_del_btn = self.driver.find_element_until_visibility( self.locator("rule_del_btn")) self.driver.click(rule_del_btn) ensure_btn = self.driver.find_element_until_visibility( self.locator("done_btn")) self.driver.click(ensure_btn) # 以下用于toast验证 def remove_toast(self): """ 删除成功 :return: """ toast = self.driver.get_toast("删除成功").text return toast
class Test_LoginPage(): driver = AutoDriver() LoginPage = LoginPage() ProjectPage = ProjectPage() # 截图相关 def add_img(self): self.imgs.append(self.driver.get_screenshot_by_base64()) return True # 截图相关 def cleanup(self): pass def setUp(self): print("登录页面:") self.imgs = [] # 截图相关 self.addCleanup(self.cleanup) # 截图相关 time.sleep(2) def tearDown(self): # self.driver.click_device_btn(4) pass def test_01_login(self): """账号为空""" self.LoginPage.app_login(login_data['account_null'], login_data['passwd_null']) expected_toast = toast_data['account_null'] print("期望的toast为", expected_toast) time.sleep(2) actual_toast = self.LoginPage.account_null_toast() print("实际的toast为", actual_toast) assert actual_toast == expected_toast, "验证结果,期望: %s, 实际: %s" % ( expected_toast, actual_toast) def test_02_login(self): """密码为空""" self.LoginPage.app_login(login_data['account_01'], login_data['passwd_null']) expected_toast = toast_data['password_null'] print("期望的toast为", expected_toast) time.sleep(2) actual_toast = self.LoginPage.password_null_toast() print("实际的toast为", actual_toast) assert actual_toast == expected_toast, "验证结果,期望: %s, 实际: %s" % ( expected_toast, actual_toast) def test_03_login(self): """错误的账号""" self.LoginPage.app_login(login_data['account_error'], login_data['passwd_error']) #self.driver.wait_activity_display('.ui.LoginActivity') expected_toast = toast_data['account_error'] print("期望的toast为", expected_toast) time.sleep(2) actual_toast = self.LoginPage.account_error_toast() print("实际的toast为", actual_toast) assert actual_toast == expected_toast, "验证结果,期望: %s, 实际: %s" % ( expected_toast, actual_toast) def test_04_login(self): """错误的密码""" self.LoginPage.app_login(login_data['account_01'], login_data['passwd_error']) #self.driver.wait_activity_display('.ui.LoginActivity') expected_toast = toast_data['password_error'] print("期望的toast为", expected_toast) time.sleep(2) actual_toast = self.LoginPage.password_error_toast() print("实际的toast为", actual_toast) assert actual_toast == expected_toast, "验证结果,期望: %s, 实际: %s" % ( expected_toast, actual_toast) def test_05_register(self): """ 错误的账号 """ self.LoginPage.user_register(register_data['register_user_name'], register_data['register_account_error'], register_data['register_pass_01']) expected_toast = toast_data['register_account_error'] print("期望的toast为", expected_toast) time.sleep(2) actual_toast = self.LoginPage.register_account_error_toast() print("实际的toast为", actual_toast) time.sleep(2) self.LoginPage.back_login_page() assert actual_toast == expected_toast, "验证结果,期望: %s, 实际: %s" % ( expected_toast, actual_toast) def test_06_register(self): """ 用户名为空 """ self.LoginPage.user_register(register_data['register_user_name_null'], register_data['register_account_01'], register_data['register_pass_01']) expected_toast = toast_data['register_user_null'] print("期望的toast为", expected_toast) time.sleep(2) actual_toast = self.LoginPage.register_username_null_toast() print("实际的toast为", actual_toast) time.sleep(2) self.LoginPage.back_login_page() assert actual_toast == expected_toast, "验证结果,期望: %s, 实际: %s" % ( expected_toast, actual_toast) def test_07_register(self): """ 密码小于6位 """ self.LoginPage.user_register(register_data['register_user_name'], register_data['register_account_01'], register_data['register_pass_error']) expected_toast = toast_data['register_pass_error'] print("期望的toast为", expected_toast) time.sleep(2) actual_toast = self.LoginPage.register_pass_error_toast() print("实际的toast为", actual_toast) time.sleep(2) self.LoginPage.back_login_page() assert actual_toast == expected_toast, "验证结果,期望: %s, 实际: %s" % ( expected_toast, actual_toast) def test_08_register(self): """注册成功""" self.LoginPage.user_register(register_data['register_username_02'], register_data['register_account_02'], register_data['register_pass_02']) self.driver.wait_activity_display(".ui.LoginActivity") expected_toast = toast_data['register_succ'] print("期望的toast为", expected_toast) time.sleep(4) actual_toast = self.LoginPage.register_succ_toast() print("实际的toast为", actual_toast) assert actual_toast == expected_toast, "验证结果,期望: %s, 实际: %s" % ( expected_toast, actual_toast) def test_09_login(self): """登录成功""" self.LoginPage.app_login(login_data['account_01'], login_data['passwd_01']) flag = self.ProjectPage.is_project_page() assert flag, '登录失败'