self.log.info('跳转至搜索页面') return SearchPage(self.driver) # 跳转至行情首页页面 def to_marketPage(self): self.main_exception() self.click_button(self._market_locator) self.log.info('跳转至行情首页页面') # 跳转至交易首页页面 def to_dealPage(self): self.main_exception() self.click_button(self._deal_locator) self.log.info('跳转至交易首页页面') # 跳转至我的页面 def to_myPage(self): self.main_exception() self.click_button(self._my_locator) self.log.info('跳转至我的页面') if __name__ == '__main__': from Common.app import App app = App.startApp() # ma=MainPage(app) app.to_marketPage() app.to_dealPage() app.to_myPage() # ma.to_search().search(keyword="hello")
else: toast_text=self.find_element(loc=(self.by.XPATH,self.get_xpath_loc(text_loc=text))).text self.log.info('toast:{}'.format(toast_text)) return toast_text # 针对h5页面编写单独的xpath定位方式 def webview_xpath(self,label,property_value,property_key='placeholder'): '''lable:标签名称,property_key:属性名,property_value:属性值''' return self.find_element(loc=(self.by.XPATH,'//{}[@{}="{}"]'.format(label,property_key,property_value))) #切换元素定位引擎 def swith_locEngine(self,engine_type='WEBVIEW_'): '''app采用原生appium提供的定位方式,webview采用chromeDirver定位(请注意版本匹配, 、当前app采用chrome68,对应的chromeDriver版本为2.39),具体明细请参考:https://blog.csdn.net/BinGISer/article/details/88559532''' contexts=self.driver.contexts self.log.info('contexts:{}'.format(contexts)) if engine_type in ('web','webView','web-view','web_view','WEBVIEW_','h5'): self.driver.switch_to.context(contexts[-1]) self.log.info('swith to locEngine:{}'.format(contexts[-1])) else: self.log.info('swith to locEngine :{}'.format(contexts[0])) self.driver.switch_to.context(contexts[0]) if __name__=="__main__": from Common.app import App bs=basePage(App.startApp().getScreenShot()) # bs.getScreenShot() # print(ele.get_windows_size()) # print(hasattr(MobileBy,'-ios predicate string'))
from Common.BasePage import basePage class eleOpenShopPage(basePage): _speedOpenShop_locator = (basePage.by.XPATH, basePage.get_xpath_loc( class_loc=basePage._classButton_locator, text_loc='极速开店')) def jump_to_speedOpenShopPage(self): # 切换元素定位引擎为web,chromeDriver self.swith_locEngine(engine_type='web') label = 'input' property_key = 'placeholder' property_list = ['请输入验证码', '请填写姓名', '请填写工号'] for i in property_list: self.webview_xpath(label=label, property_key=property_key, property_value=i).send_keys('test_1') # 切换定位引擎为appium self.swith_locEngine(engine_type='app') self.click_button(loc=self._speedOpenShop_locator) return self if __name__ == "__main__": from Common.app import App el = eleOpenShopPage(App.startApp())
def teardown(self): App.quit()
def setup(self): self.driver = App.startApp() self.log = App.log
def startApp(): app = App.startApp() return app
def closeApp(): yield App.quit()