def find_text(context, element, value, page): page = check_page(page) element = LocateHeper.get_protect_attribute(page, element) if LocateHeper(context.driver).find(element).get_text() != value: raise Exception( "The text of {element} is not {value} in {page}".format( element=element, value=value, page=page))
def check_element(context, element, page): page = check_page(page) element = LocateHeper.get_protect_attribute(page, element) if LocateHeper(context.driver).find(element): pass else: context.driver.get_screenshot_as_file( r'/Users/tianqi/Desktop/study/Appium_UI_Autotest/Log/test.png') context.logger.error("找不到元素{element} in {page}".format(element=element, page=page)) raise Exception
def __init__(self): self._setting = LocateHeper.locator("accessibility_id", "设置") # 设置 self._add_friend = LocateHeper.locator("accessibility_id", "添加好友") # 添加好友 self._user_info = LocateHeper.locator("id", "com.sina.weibo:id/layout_userinfo") # 用户昵称 self._back = LocateHeper.locator("accessibility_id", "返回") self._accout_manage = LocateHeper.locator("id", "com.sina.weibo:id/accountContent") # 账号管理 self._exit_accout = LocateHeper.locator("id", "com.sina.weibo:id/exitAccountContent") # 退出账号 self._title_text = LocateHeper.locator("id", "com.sina.weibo:id/titleText") # 页面标识(账号管理) self._cancel = LocateHeper.locator("xpath", ''' android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.TextView[1] ''') # 取消退出登录 self._sure = LocateHeper.locator("xpath", ''' android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.TextView[3] ''') # 确定退出登录
def __init__(self): self._login = LocateHeper.locator("id", "com.sina.weibo:id/titleSave") self._register = LocateHeper.locator("id", "com.sina.weibo:id/titleBack") self._my_profile = LocateHeper.locator("accessibility_id", "我的资料") self._register = LocateHeper.locator("id", "com.sina.weibo:id/titleBack") self._follow = LocateHeper.locator( "id", "com.sina.weibo:id/tv_groupName") # 关注 self._publish = LocateHeper.locator("id", "com.sina.weibo:id/plus_icon") self._find = LocateHeper.locator("accessibility_id", "发现") self._weibo = LocateHeper.locator("accessibility_id", "微博") self._page_id = self._follow # 用来标识页面
def check(self, driver): if self._page_id is None: msg = "the {page} id is None".format(page=self.__class__.__name__) logging.error(msg) raise Exception(msg) else: try: if LocateHeper(driver).find(self._page_id): return True else: return False except Exception: logging.error("can not find element" + self._page_id[1])
def check(self, driver): if self._pageid is None: logging.error("the page id is None in loginpage") raise Exception else: try: if LocateHeper(driver).find(self._pageid): return True else: return False except Exception: logging.exception("find elment {0} fail in {1}".format( self._pageid[1], "login page"), exc_info=True)
def __init__(self): self._close = LocateHeper.locator( "id", "com.sina.weibo:id/tv_title_bar_back") # 关闭 self._register = LocateHeper.locator( "id", "com.sina.weibo:id/tv_title_bar_register") # 注册 self._username = LocateHeper.locator( "id", "com.sina.weibo:id/etLoginUsername") # 登录用户名输入狂 self._pwd = LocateHeper.locator("id", "com.sina.weibo:id/etPwd") # 登录密码输入框 self._login_button = LocateHeper.locator( "id", "com.sina.weibo:id/bnLogin") # 登录按钮 self._other_login = LocateHeper.locator( "xpath", ''' android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[3]/android.widget.ImageView[1] ''') self._pageid = self._login_button
return result.readline().split("Physical size:")[1] else: logging.error( "there is no device info,please check the connection of mobile phone" ) # 得到手机屏幕大小 @classmethod def get_size(cls, driver): x = driver.get_window_size()['width'] y = driver.get_window_size()['height'] return (x, y) # debug if __name__ == "__main__": device = Device() device.get_device("device.xml") print(device) driver = device.connect_device('http://localhost:4723/wd/hub') print(device.get_app_pix()) print(device.get_men_total()) print(device.get_size(driver)) page = HomePage() time.sleep(30) LocateHeper(driver).find(page.login).click() #新浪微博 #com.sina.weibo #com.sina.weibo.SplashActivity
def swich_and_click(context, button, page): context.driver.switch_to_alert() page = check_page(page) button = LocateHeper.get_protect_attribute(page, button) LocateHeper(context.driver).find(button).click()
def input_text(context, element, text, page): page = check_page(page) element = LocateHeper.get_protect_attribute(page, element) LocateHeper(context.driver).find(element).send_keys(text)
def click_element(context, element, Page): page = check_page(Page) element = LocateHeper.get_protect_attribute(page, element) LocateHeper(context.driver).find(element).click()