def test2_1(self): """通过搜索分享地点""" test_name = "%s:通过搜索分享地点" % self._testMethodName mylogger.info("%s start" % test_name) mainChat_element(self) first_chat_element(self) mylogger.info("进入与第一个联系人交互界面") chat_img_more_element(self) time.sleep(2) chat_place_search_place(self, n=0) mylogger.info("触发:输入框输入") chat_place_type(self=self, n=3) mylogger.info("选择地点类型为地点") chat_place_choice_Address(self, n=1) mylogger.info("位置信息发送") self.driver.implicitly_wait(5) screenShot(self=self, test_name=test_name) self.driver.implicitly_wait(5) return_home(self=self, test_name=test_name)
def chat_send_file_choice_folder(self, x, y, z): """ 文件管理:下选择具体的文件夹 , 仅支持首页 :param self: :param x: 第1层第几个文件夹 :param y: 第2层第几个文件夹 :param z: 第3层第几个文件 :return: """ try: self.driver.implicitly_wait(5) self.driver.find_element_by_xpath( "//android.widget.ListView/android.widget.FrameLayout[%s]" % x).click() self.driver.find_element_by_xpath( "//android.widget.ListView/android.widget.FrameLayout[%s]" % y).click() self.driver.find_element_by_xpath( "//android.widget.ListView/android.widget.FrameLayout[%s]" % z).click() # 点击确定按钮 self.driver.find_element_by_xpath( "//android.widget.LinearLayout/android.widget.Button[1]").click() mylogger.info("确定发送") except Exception as e: self.driver.implicitly_wait(5) element_error(self, e)
def check_comments_successful(self): """校验评论成功""" try: self.driver.find_element_by_android_uiautomator( 'new UiSelector().textContains("这是一条评论测试")') return True except Exception as e: mylogger.info(e) return False
def check_mobile_login(self, test_name): try: self.driver.implicitly_wait(5) self.driver.find_element_by_id('chat_img').click() mylogger.info("进入消息界面成功") return True except Exception as e: mylogger.debug(e) screenShot(self, test_name) return False
def check_send_photo_success(self): print("运行了一次check") try: self.driver.implicitly_wait(5) self.driver.find_element_by_id("com.erlinyou.worldlist:id/img_more") return True except Exception as e: print(e) mylogger.info("发送图片校验失败") return False
def check_wx_login(self, test_name): try: self.driver.implicitly_wait(5) download_map(self) # driver.find_element_by_android_uiautomator('new UiSelector().text("离线地图")').click() mylogger.info("True") return True except Exception as e: mylogger.debug(e) screenShot(self, test_name) return False
def check_create_dynamic_just_friend_see(self): """校验新建动态仅好友可见""" try: self.driver.find_element_by_android_uiautomator( 'new UiSelector().textContains("这是一条测试动态")').click() return True except Exception as e: print("False") mylogger.info(e) return False
def check_share_location_stop(self, test_name): try: ele = self.driver.find_element_by_id("stop").text if ele == "停止": mylogger.info("停止按钮未从页面消失") return False else: return True except: mylogger.info("停止按钮从页面消失,断言结果为True") return True
def check_setting_city(self, city_text): # 设置城市 check_element = self.driver.find_element_by_id( "com.erlinyou.worldlist:id/tv_city_value") if city_text == check_element.get_attribute("text"): mylogger.info("设置城市成功") return True else: mylogger.info("设置城市失败") return False
def check_direct_go_home(self, test_name): """设置回家是否成功""" try: ele = self.find_element_by_id( "com.erlinyou.worldlist:id/top_map_mode_img").text if ele == "到这去": return True else: return False except Exception as e: mylogger.info("%s" % e) screenShot(self, test_name) return False
def test6_1(self): """message send voice """ test_name = "发送语音时长为10s" mylogger.debug("%s start" % test_name) mainChat_element(self) first_chat_element(self) mylogger.info("进入与第一个联系人交互界面") chat_voice_element(self).click() self.driver.implicitly_wait(5) chat_send_voice_element(self=self, t=10000) # time.sleep(5) return_home(self, test_name)
def return_home(self, test_name): """返回主页""" while True: try: print("检查是否进入主页") self.driver.implicitly_wait(5) time.sleep(1) self.driver.find_element_by_id( "com.erlinyou.worldlist:id/chat_img") mylogger.info("返回主页面") break except: mylogger.info("并未返回主页") try: print("检查是否弹出退出窗口") self.driver.implicitly_wait(5) time.sleep(1) self.driver.find_element_by_id("android:id/button2").click() print("检查是否弹出退出窗口结束") break except: mylogger.info("并未返回主页面") self.driver.press_keycode(4) mylogger.info("{}回归原点".format(test_name))
def test5(self): """message share file""" test_name = "%s发送文件" % self._testMethodName mylogger.info("%s start" % test_name) mainChat_element(self.driver) first_chat_element(self.driver) mylogger.info("进入与第一个联系人交互界面") for i in range(1, 5): if i == 1: self.driver.implicitly_wait(5) chat_img_more_element(self.driver) time.sleep(2) chat_swipeLeft(self=self, t=5000) mylogger.info("触发chat左滑") else: self.driver.implicitly_wait(5) chat_img_more_element(self) self.driver.implicitly_wait(5) chat_send_file_element(self) self.driver.implicitly_wait(5) # 从文件管理中选取管理文件 chat_send_file_type(self=self, n=3) chat_send_file_choice_folder(self=self, x=4, y=4, z=i) mylogger.info("发送文件第%s" % i) screenShot(self=self, test_name="%s发送第%s" % (str_nowTime(), i)) return_home(self, test_name)
def check_history_search(self): """通过对搜索列表下第一条数据指定字段text的获取,校验生成历史数据成功""" try: ele = self.driver.find_element_by_xpath( "//android.widget.LinearLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[2]" "/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.TextView[1]" ).text print(ele) if ele == "奥林匹克公园": print('pass') return True except Exception as e: mylogger.info("%s" % e) self.driver.press_keycode(4) return False
def check_cancel_go_home(self, test_name): """通过是否能找到住宿这个button来判断取消回家成功""" try: ele = self.driver.find_element_by_id( "com.erlinyou.worldlist:id/tv_house").text if ele == "住宿": return True else: return False except Exception as e: mylogger.info("%s" % e) screenShot(self, test_name) self.driver.press_keycode(4) time.sleep(1) self.driver.press_keycode(4) mylogger.error("test2_a_1失败") return False
def test3_5_Service(self): """进入 place service 并分享周边兴趣列表位置""" test_name = "%s:服务下分享" % self._testMethodName mylogger.debug("%s start" % test_name) mainChat_element(self) first_chat_element(self) mylogger.info("进入与第一个联系人交互界面") chat_img_more_element(self) time.sleep(2) chat_place_service(self.driver) chat_place_surrounding_share(self.driver, n=1) mylogger.info("分享位置触发") time.sleep(2) screenShot(self=self, test_name=test_name) return_home(self, test_name)
def test3_2_Food(self): """进入 place food 并分享周边兴趣列表位置""" test_name = "%s:美食下分享" % self._testMethodName mylogger.debug("%s start" % test_name) mainChat_element(self) first_chat_element(self) mylogger.info("进入与第一个联系人交互界面") chat_img_more_element(self) time.sleep(2) chat_place_eat(self) chat_place_surrounding_share(self=self, n=1) mylogger.info("分享位置触发") time.sleep(2) screenShot(self=self, test_name=test_name) self.driver.implicitly_wait(5) return_home(self, test_name)
def through_config_setting(self, config_number): # 通过配置文件中的config number 来进行成市设置 if config_number == 0: pass else: mylogger.info("研发版:即将进入设置当前城市") city_text = myconfig.get_setting_city() home_page_city(self=self) setting_city_search(self=self, city_text=city_text) self.driver.implicitly_wait(5) self.driver.find_element_by_xpath( "//android.widget.ListView/android.widget.LinearLayout[1]" "/android.widget.LinearLayout").click() # self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("巴黎")').click() # self.driver.find_element_by_xpath("*[@text='巴黎']").click() self.assertEqual(True, check_setting_city(self=self, city_text=city_text))
def get_error_code(self, e, test_name): global error_code mylogger.error(e) screenShot(self, test_name) error_code = True while True: try: print("检查是否进入主页") self.driver.implicitly_wait(5) time.sleep(1) self.driver.find_element_by_id( "com.erlinyou.worldlist:id/chat_img") print("检查是否进入主页") mylogger.info("返回主页面") error_code = False print(error_code) except Exception as e: print(e) if error_code == False: break try: print("检查是否弹出退出窗口") self.driver.implicitly_wait(5) time.sleep(1) self.driver.find_element_by_id("android:id/button2").click() print("检查是否弹出退出窗口结束") print(error_code) error_code = False except Exception as e: print(e) print(error_code) # if error_code == False: # unittest.skipIf(error_code == False, reason='定位元素失败') # break self.driver.press_keycode(4) mylogger.info("%s执行了测试用例回归原点操作,测试标记失败结束" % test_name) return False
def test2_3(self): """通过搜索分享城市""" test_name = "%s:通过搜索分享城市" % self._testMethodName mylogger.info("%s start" % test_name) mainChat_element(self) first_chat_element(self) mylogger.info("进入与第一个联系人交互界面") chat_img_more_element(self) time.sleep(2) chat_place_search_place(self=self, n=2) mylogger.info("触发:输入框输入") chat_place_type(self=self, n=2) mylogger.info("选择地点类型为城市") chat_place_choice_City(self=self, n=1) mylogger.info("位置信息发送") screenShot(self=self, test_name=test_name) return_home(self, test_name)
def test4_share_software(self): """message share software""" test_name = "%s:分享软件" % self._testMethodName mylogger.info("%s start" % test_name) mainChat_element(self) first_chat_element(self) mylogger.info("进入与第一个联系人交互界面") chat_img_more_element(self) time.sleep(2) chat_add_all(self.driver, n=8) mylogger.info("触发分享app发送") screenShot(self.driver, test_name) return_home(self, test_name)
def get_login_state(self): """校验当前是否是登录状态""" login_state = 0 try: self.driver.implicitly_wait(4) self.driver.find_element_by_id("chat_img").click() login_state += 1 mylogger.info("进入登录校验") try: self.driver.implicitly_wait(5) self.driver.find_element_by_id( "com.erlinyou.worldlist:id/textview_tab_chat") mylogger.info("当前是登录状态") login_state += 1 self.driver.press_keycode(4) return login_state except: mylogger.info("当前是未登录状态") self.driver.press_keycode(4) return login_state except: mylogger.info("当前是未登录状态") return login_state
def navigation_details_collection(self): """收藏""" try: self.driver.implicitly_wait(5) ele = self.driver.find_element_by_id( "com.erlinyou.worldlist:id/favorite_tv").text mylogger.info("ele:%s" % ele) if ele == "收藏": mylogger.info("该景点未收藏") self.driver.implicitly_wait(5) self.driver.find_element_by_id( "com.erlinyou.worldlist:id/favorite_layout").click() elif ele == "已收藏": mylogger.info("该地点已收藏") except Exception as e: element_error(self, e)
def test3_8_place_GPS(self): """ place GPS 分享当前GPS定位""" test_name = "%s:地图上发送默认地点" % self._testMethodName mylogger.info("%s start" % test_name) mainChat_element(self) first_chat_element(self) mylogger.info("进入与第一个联系人交互界面") chat_img_more_element(self) time.sleep(2) chat_place_on_map_GPS(self.driver) mylogger.info("on map 触发位置共享") time.sleep(3) screenShot(self, test_name) self.driver.implicitly_wait(5) return_home(self, test_name)
def test3_6_Favor(self): """进入 place service 并分享周边兴趣列表位置""" test_name = "出行下分享" mylogger.info("%s start" % test_name) mainChat_element(self) first_chat_element(self) mylogger.info("进入与第一个联系人交互界面") chat_img_more_element(self) time.sleep(2) chat_place_service(self) self.driver.implicitly_wait(5) chat_place_surrounding_share(self=self, n=1) mylogger.info("分享位置触发") time.sleep(2) screenShot(self=self, test_name=test_name) self.driver.implicitly_wait(5) return_home(self=self, test_name=test_name)
def test3_7_Onmap(self): """进入place on_map 分享默认地点""" test_name = "%s:地图上发送默认地点" % self._testMethodName mylogger.info("%s start" % test_name) self.driver.implicitly_wait(5) mainChat_element(self) first_chat_element(self) mylogger.info("进入与第一个联系人交互界面") chat_img_more_element(self) time.sleep(2) chat_place_on_map(self.driver) mylogger.info("on map 触发位置共享") self.driver.implicitly_wait(5) chat_place_on_map_sure(self.driver) screenShot(self.driver, test_name) return_home(self, test_name)
def check_wx_logout(self, test_name): try: mylogger.info("进入退出验证") self.driver.implicitly_wait(5) # count_visitor = driver.find_element_by_xpath("//android.support.v7.widget.RecyclerView[2]" # "/android.widget.LinearLayout[5]/android.widget.TextView[1]").text count_visitor = self.driver.find_element_by_id( "com.erlinyou.worldlist:id/user_name_tv").text # mylogger.info("定位成功") print(count_visitor) # count_visitor = int(count_visitor) # mylogger.info('获取访客数成功%s' % count_visitor) if count_visitor == "注册/登录": mylogger.info("True") return True else: mylogger.info("退出登录失败") return False except Exception as e: mylogger.debug(e) screenShot(self, test_name) return False
def logout(self, login_state): # 账号退出 test_name = "mobile quit" if login_state == 2: self.driver.implicitly_wait(5) userAvatar_element(self) mylogger.info("get into mine home page") time.sleep(3) swipeUp(self=self, t=6000) mylogger.info("向上滑动屏幕") self.driver.implicitly_wait(10) mine_setting(self) self.driver.find_element_by_id( "com.erlinyou.worldlist:id/btn_logout").click() mylogger.info("触发退出登录按钮") self.driver.implicitly_wait(5) self.driver.find_element_by_id("android:id/button1").click() mylogger.info("确认退出登录退出") time.sleep(3) self.driver.press_keycode(4) mylogger.info("返回我的页面") # self.driver.implicitly_wait(10) self.driver.implicitly_wait(10) self.assertEqual(True, check_wx_logout(self=self, test_name=test_name)) mylogger.info("登录退出成功") else: mylogger.bug("未执行退出操作")
def login(self, mode, login_state): """ 账号登录 :param login_state: 登录状态 2 的时候表示已经登录 :param self: :param driver: :param mode:1:账号密码登录 2:微信登录 """ test_name = "登录" if login_state == 2: pass else: if mode == 1: # 账号密码登录 self.driver.implicitly_wait(5) mainChat_element(self) test_name = "mobile账号密码登录" mylogger.debug(test_name) # 返回测试用例名称 mylogger.info("进入登录页面成功") self.driver.implicitly_wait(5) mobile_title_element(self) mylogger.info("切换成账号密码登录") time.sleep(4) # driver.implicitly_wait(10) mobile_user_element(self) mylogger.info("输入账号成功") self.driver.implicitly_wait(10) mobile_password_element(self) mylogger.info("输如密码成功") self.driver.implicitly_wait(5) mobile_login_element(self) mylogger.info("触发登录") self.assertEqual(True, check_mobile_login(self, test_name)) mylogger.info("mobile 登录成功") elif mode == 2: # 微信登录 self.driver.implicitly_wait(5) userAvatar_element(self) mylogger.info("进入我的页面") self.driver.implicitly_wait(5) dL_element(self) mylogger.info('点击注册/登录 进入登录页面') self.driver.implicitly_wait(10) wX_element(self) time.sleep(2) mylogger.info('点击微信图标进行登录') self.driver.implicitly_wait(4) self.assertEqual(True, check_wx_login(self=self, test_name=test_name))