def long_tap(self, x = None, y = None, duration = 1000): # Long tap a coordinates (x,y) if (x == None) | (y == None) | (x > self.X) | (y > self.Y): raise AssertionError('Please input correct coordinates') action = TouchAction(self.driver) action.long_press(x = x, y = y, duration = duration).release() action.perform()
def test_005(self): '''验证long_press方法''' width = self.driver.get_window_size()['width'] height = self.driver.get_window_size()['height'] t.sleep(5) self.driver.swipe(width * 9 / 10, height / 2, width / 20, height / 2, 0) t.sleep(2) self.driver.swipe(width * 9 / 10, height / 2, width / 20, height / 2, 0) t.sleep(2) self.driver.swipe(width * 9 / 10, height / 2, width / 20, height / 2, 0) t.sleep(2) self.driver.swipe(width * 9 / 10, height / 2, width / 20, height / 2, 0) touch = TouchAction(self.driver) t.sleep(5) element = self.driver.find_element_by_id( 'com.baozoumanhua.android:id/channel_tv') touch.long_press(element).perform() t.sleep(4) actual_text = self.driver.find_element_by_id( 'com.baozoumanhua.android:id/tv_channel_title').text self.assertEqual(actual_text, u'暴走大事件第四季')
def long_press(self, elem, x, y, duration): """ appium API Begin a chain with a press down that lasts `duration` milliseconds """ action = MobileTouchAction(self.driver) action.long_press(elem, x, y, duration).perform()
def seekBar(driver, id, ratio): ''' :param driver: driver :param id: 元素的 id :param ratio: 宽度的比例位置 :return: ''' # 通过 id 找到 seek_bar seek_bar = driver.find_element_by_id(id) # 获取到 seek bar 的 X 轴位置 print(seek_bar.location) start = seek_bar.location.get('x') # 获取到 seek bar 的宽度 print(seek_bar.size) width = seek_bar.size.get('width') # 获取到 seek bar 的 Y 轴位置 y = seek_bar.location.get('x') # 获取一个 Action action = TouchAction(driver) # 获取移动的目的位置 moveTo = int(width * ratio) action.long_press(el=seek_bar, x=start, y=y).move_to(el=seek_bar, x=moveTo, y=y).release().perform()
def test_touch(self): size = self.driver.get_window_size() element = self.driver.find_element(MobileBy.ID, "status_single_image") action = TouchAction(self.driver) action.long_press(x=size['width'] * 0.5, y=size['height'] * 0.8).\ move_to(x=size['width'] * 0.2, y=size['height'] * 0.0).\ release().perform()
def test_long_press_x_y(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el1).move_to(el2).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Custom Adapter') action.tap(el).perform() # the element "People Names" is located at 430:310 (top left corner) # location can be changed by phone resolusion, OS version action.long_press(x=430, y=310).perform() # 'Sample menu' only comes up with a long press, not a tap el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Sample menu")') self.assertIsNotNone(el)
def swipe(driver, start_x, start_y, end_x, end_y, duration=None): """ 实现带duration的滑动,appium元素的swipe中使用的是press,无法实现带duration的滑动 """ action = TouchAction(driver) action.long_press(x=start_x, y=start_y).wait(duration).move_to( x=end_x, y=end_y).release().perform()
def long_click(self, what, duration = 1000): # Long click an element item = self.focus(what) action = TouchAction(self.driver) action.long_press(el = item, duration = duration) action.release() action.perform()
def case_check_long_press_and_back(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) contacts_list = self.test.find_list_byclass(TextView) name = 'test meig' actions = TouchAction(self.driver) for c in contacts_list: str_tmp = c.text if name in str_tmp: actions.long_press(c).release().perform() time.sleep(1) break share_button = self.test.find_byid(contacts_share_contact) if share_button is None: self.Case.fail("长按列表项切换功能按钮失败") self.driver.press_keycode(KEY_BACK, 0, 0) name_list = self.test.find_list_byclass(TextView) n_flag = False for n in name_list: str_tmps = n.text if "通讯录" in str_tmps: n_flag = True if not n_flag: self.Case.fail("返回通讯录主列表失败")
def test_chat(self): driver = self.driver sleep(2) driver.find_element_by_accessibility_id("对话").click() sleep(2) # driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='心之力']/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeScrollView/XCUIElementTypeOther[2]/XCUIElementTypeScrollView/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeScrollView").click() # sleep(2) # driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='心之力']/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeScrollView/XCUIElementTypeOther[2]/XCUIElementTypeScrollView/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeScrollView").send_keys("ios自动化测试发送") # sleep(2) # driver.find_element_by_accessibility_id("Send").click() # sleep(2) # input=driver.find_element_by_xpath("//XCUIElementTypeApplication[@name='心之力']/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeScrollView/XCUIElementTypeOther[2]/XCUIElementTypeScrollView/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeScrollView").text # self.assertEqual(input,"") driver.find_element_by_accessibility_id("发语音").click() sleep(2) if "不允许" in driver.page_source: driver.switch_to.alert.accept() sleep(2) element=driver.find_element_by_xpath("//XCUIElementTypeButton[@name='按住说话']") action = TouchAction(driver) action.long_press(element, None, None, 2000).wait(1000).release().perform() sleep(2) if "2" in driver.page_source: self.assertIn('2',driver.page_source) elif "3" in driver.page_source: self.assertIn('3', driver.page_source) elif "4" in driver.page_source: self.assertIn("4",driver.page_source) else: self.assertEqual(1,2)
def test_simple_action(self): # tutaj selectory do appium # http://appium.io/docs/en/commands/element/find-elements/ # accessbilibity -> content-desc dostepny w android, mozna po tym lokalizowac, dobre, # wyjatkowe, moze miec nazwe podobna do TEXT ale to nie znaczy ze cos ten tego, bo inne sa # w webowce nie ma content desc # self.driver.is_app_installed('io.appium.android.apis') #podejscie najprostrze #to jest poprawene linijka nizej ale zrobimy tapa #self.driver.find_element_by_accessibility_id('Views').click() #tapniecie to takie pykniecie, w wielu przypadkach to jest to samo co klikniecie #gesture touchAction appium -> http://appium.io/docs/en/writing-running-appium/touch-actions/#touchaction # elo = self.driver.find_element_by_accessibility_id('Views') action = TouchAction(self.driver) action.tap(elo).perform() sleep(3) self.driver.find_element_by_accessibility_id( 'Expandable Lists').click() self.driver.find_element_by_accessibility_id( '1. Custom Adapter').click() elo2 = self.driver.find_element_by_xpath( '//android.widget.TextView[@text="People Names"]') elo2.click() # nieobowiazkowe w testach action.long_press(elo2).perform() sleep(3) #jak clikniesz to sie rozwija lista ale jak dluzej przytrzymasz to masz w tedy menu self.driver.find_element_by_xpath( '//android.widget.TextView[@text="Sample action"]').click() sleep(3)
def add_video(driver): """ 添加视频使用xpath定位 //android.support.v7.widget.RecyclerView[1]/android.widget.RelativeLayout[3]/android.widget.ImageView[1] Usage: 在当前页面,添加图片视频区域,从左到右,从1开始计数,<添加视频>按钮处于第几个,则RelativeLayout填写几即可. 如:在只添加一张图、当前区域未进行滑动的情况下,RelativeLayout则为[3] 若添加图片视频区域进行了滑动操作,添加视频框输入第一个,则RelativeLayout为[1] """ try: screenshot(driver,'screenshot/Release_Video_init_page.png') el = "//android.support.v7.widget.RecyclerView[1]/android.widget.RelativeLayout[3]/android.widget.ImageView[1]" el_xpath_click(driver,el) # find: capture Video btn capture_btn = driver.find_element_by_id(cfg.get('release','capture_btn')) # 长按录制10s action = TouchAction(driver) action.long_press(capture_btn,None,None,10000).perform() screenshot(driver,'screenshot/Release_Video_capture_finish.png') sleep(1) el_click(driver,cfg.get('release','capture_finish')) screenshot(driver,'screenshot/Release_Video_capture_commit.png') sleep(5) except: try: screenshot(driver,'screenshot/Release_Video_error.png') el_click(driver,cfg.get('release','capture_close')) except: pass
def long_press_wheel_btn(self): log.debug("Long press '{}' button to go home page".format("Wheel")) wh = self.driver.find_element(*self.WHEEL_BTN) action = TouchAction(self.driver) action.long_press(x=center(wh)['XCentr'], y=center(wh)['YCentr'], duration=3000).release().perform()
def test_Long_Press_Validation(self): #self.driver.implicitly_wait(10) "Click on Views" self.driver.find_element_by_xpath( "//android.widget.TextView[@text='Views']").click() "Call the touch method from unittest module and select Expandable Lists" touch = TouchAction(self.driver) el = self.driver.find_element_by_xpath( "//android.widget.TextView[@text='Expandable Lists']") "Perform tap operation" touch.tap(el).perform() "Click on 1. Custom Adapter" self.driver.find_element_by_xpath( "//android.widget.TextView[@text='1. Custom Adapter']").click() "Select Fish Names" fish = self.driver.find_element_by_xpath( "//android.widget.TextView[@text='Fish Names']") "Long press on it to check whether the content is displayed " touch.long_press(fish).release().perform() "Check whether the selected element has displayed all the sub-elements" el = self.driver.find_element_by_id("android:id/title") self.assertEqual(True, ( self.driver.find_element_by_id("android:id/title").is_displayed()))
def test_long_press_x_y(self): el1 = self.driver.find_element_by_name('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el1).move_to(el2).perform() el = self.driver.find_element_by_accessibility_id('Views') # self.assertIsNotNone(el) action.tap(el).perform() el = self.driver.find_element_by_accessibility_id('Expandable Lists') # self.assertIsNotNone(el) action.tap(el).perform() el = self.driver.find_element_by_accessibility_id('1. Custom Adapter') # self.assertIsNotNone(el) action.tap(el).perform() # the element "People Names" is located at 0:110 (top left corner) action.long_press(x=10, y=120).perform() # 'Sample menu' only comes up with a long press, not a tap el = self.driver.find_element_by_name('Sample menu') self.assertIsNotNone(el)
def test_set(self, connect='', port1='', lvs='', fileserver='', appid='aaf98f8944e7df950144e8da282e0118', apptoken='d9e42bd10dae11e5ac73ac853d9f54f2'): '''登陆,设置app''' action1 = TouchAction(self.driver) el = self.driver.find_element_by_id("btn_middle") #长按云通讯进入设置页面 action1.long_press(el, duration=3000).perform() self.driver.find_element_by_id("setup_connect").set_text(connect) #self.driver.find_element_by_name("8085").clear() self.driver.find_element_by_id("setup_connect_port").set_text(port1) self.driver.find_element_by_id("setup_lvs").set_text(lvs) self.driver.find_element_by_id("setup_fileserver").set_text(fileserver) self.driver.press_keycode('4') #点击返回键 self.driver.find_element_by_id("setup_appid").set_text(appid) self.driver.press_keycode('4') #点击返回键 self.driver.find_element_by_id("setup_apptoken").set_text(apptoken) self.driver.press_keycode('4') #点击返回键 if connect == '': self.driver.find_element_by_id( "set_app_button").click() #点击设置appid else: self.driver.find_element_by_id("set_all_button").click() #点击设置全部 self.driver.find_element_by_id("btn_left").click()
def test_send_txt(self): '''发送链接消息''' time.sleep(5) #发送文本链接消息 swip.swipLeft(self, 500) #左划 time.sleep(2) self.driver.find_element_by_id( "com.yuntongxun.ecdemo:id/card_item_tv").click() self.driver.find_element_by_id("content").click() self.driver.find_element_by_id("content").send_keys("13311267857") self.driver.find_element_by_id("text_right").click() self.driver.find_element_by_id("chatting_content_et").send_keys( "https://www.baidu.com") time.sleep(2) self.driver.find_element_by_id("chatting_send_btn").click() el = self.driver.find_element_by_id("chatting_content_itv") action1 = TouchAction(self.driver) action1.long_press(el, duration=5000).perform() self.driver.find_element_by_name(u"删除").click() self.driver.find_element_by_id("dilaog_button3").click() self.driver.find_element_by_name("https://www.baidu.com").click() el = self.driver.contexts #获取H5页面 print el el = self.driver.find_element_by_id("btn_middle").get_attribute("text") assert_equal(el, u"下载", msg=u"访问链接失败") print u"访问链接成功" self.driver.press_keycode('4') #点击返回键 el = self.driver.find_element_by_id("chatting_content_itv") action1.long_press(el, duration=5000).perform() self.driver.find_element_by_name(u"删除").click() self.driver.find_element_by_id("dilaog_button3").click()
def test_long_press_x_y(self): el1 = self.driver.find_element_by_name('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el1).move_to(el2).perform() el = self.driver.find_element_by_accessibility_id('Views') # self.assertIsNotNone(el) action.tap(el).perform() el = self.driver.find_element_by_accessibility_id('Expandable Lists') # self.assertIsNotNone(el) action.tap(el).perform() el = self.driver.find_element_by_accessibility_id('1. Custom Adapter') # self.assertIsNotNone(el) action.tap(el).perform() # the element "People Names" is located at 0:110 (top left corner) action.long_press(x=10, y=120).perform() # 'Sample menu' only comes up with a long press, not a tap el = self.driver.find_element_by_name('Sample menu') self.assertIsNotNone(el)
def tap(self, positions, duration=None): """Taps on an particular place with up to five fingers, holding for a certain time :Args: - positions - an array of tuples representing the x/y coordinates of the fingers to tap. Length can be up to five. - duration - (optional) length of time to tap, in ms :Usage: driver.tap([(100, 20), (100, 60), (100, 100)], 500) """ if len(positions) == 1: action = TouchAction(self) x = positions[0][0] y = positions[0][1] if duration: action.long_press(x=x, y=y, duration=duration).release() else: action.tap(x=x, y=y) action.perform() else: ma = MultiAction(self) for position in positions: x = position[0] y = position[1] action = TouchAction(self) if duration: action.long_press(x=x, y=y, duration=duration).release() else: action.press(x=x, y=y).release() ma.add(action) ma.perform() return self
def test_delete_file(self): record_button = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.ID, "com.danielkim.soundrecorder:id/btnRecord"))) record_button.click() stop_button = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.ID, "com.danielkim.soundrecorder:id/btnRecord"))) stop_button.click() saved_recordings_button = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.XPATH, "//android.widget.TextView[@text='SAVED RECORDINGS']"))) saved_recordings_button.click() ## Check if there is a file present self.assertTrue(self.driver.find_elements_by_id('com.danielkim.soundrecorder:id/card_view')) actions = TouchAction(self.driver) actions.long_press(self.driver.find_element_by_xpath("//android.widget.FrameLayout[contains(@resource-id,'card_view')]")) actions.perform() delete_button = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.XPATH, "//android.widget.TextView[@text='Delete File']"))) delete_button.click() confirm_yes_button = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable((By.XPATH, "//android.widget.Button[@text='YES']"))) confirm_yes_button.click() ## Assert that there is more files here self.assertFalse(self.driver.find_elements_by_id('com.danielkim.soundrecorder:id/card_view'))
def test_camera_self(self): """拍摄-自拍视频(1:1).""" sc.logger.info('拍摄-美颜趣拍(1:1)') fun_name = 'test_camera_self' sc.logger.info('点击创作中心主按钮') sc.first_step(self.c_btn) sc.logger.info('点击“美颜趣拍”') sc.driver.find_element_by_android_uiautomator('text("美颜趣拍")').click() sc.logger.info('点击摄像头反转按钮') switch_btn = 'com.quvideo.xiaoying:id/img_switch' sc.driver.find_element_by_id(switch_btn).click() sc.capture_screen(fun_name, self.img_path) el_cp = sc.driver.find_element_by_id('com.quvideo.xiaoying:id/btn_rec') # 长按拍摄5s sc.logger.info('长按拍摄5s') actions = TouchAction(sc.driver) actions.long_press(el_cp, None, None, 5000).release().perform() sc.capture_screen(fun_name, self.img_path) sc.logger.info('点击确认按钮') next_btn = 'com.quvideo.xiaoying:id/cam_btn_next' sc.driver.find_element_by_id(next_btn).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('点击“存草稿”按钮') sc.driver.find_element_by_android_uiautomator('text("存草稿")').click() sc.logger.info('美颜趣拍测试完成,点击返回按钮返回主页面') left_btn = 'com.quvideo.xiaoying:id/xiaoying_com_btn_left' sc.driver.find_element_by_id(left_btn).click() sc.logger.info('拍摄-美颜趣拍拍摄完成')
def case_music_set_widget(self): self.driver.press_keycode(3, 0, 0) time.sleep(1) tmp = get_widget_menu(self.driver) if tmp is None: self.Case.fail('未成功长按出 桌面 小菜单') tmp.click() time.sleep(1) tmp = widget_list_swipe_Down(self.driver) if tmp is None: self.Case.fail('未找到音乐小挂件') touchAction = TouchAction(self.driver) touchAction.long_press(el=tmp) time.sleep(2) touchAction.release().perform() time.sleep(1) tmp = self.test.find_byid(music_video_widget_icon) if tmp is None: self.Case.fail('音乐桌面小图标,未放置成功') tmp.click() self.Case.assertTrue( self.test.wait_if_activity(music_video_music_acivity), '通过桌面小挂件打开音乐失败') time.sleep(1)
def tap(self, positions, duration=None): """Taps on an particular place with up to five fingers, holding for a certain time :Args: - positions - an array of tuples representing the x/y coordinates of the fingers to tap. Length can be up to five. - duration - (optional) length of time to tap, in ms :Usage: driver.tap([(100, 20), (100, 60), (100, 100)], 500) """ if len(positions) == 1: action = TouchAction(self) x = positions[0][0] y = positions[0][1] if duration: action.long_press(x=x, y=y, duration=duration).release() else: action.tap(x=x, y=y) action.perform() else: ma = MultiAction(self) for position in positions: x = position[0] y = position[1] action = TouchAction(self) if duration: action.long_press(x=x, y=y, duration=duration).release() else: action.press(x=x, y=y).release() ma.add(action) ma.perform() return self
def _del_contact(self): actions = TouchAction(self.driver) flag = False while True: time.sleep(1) contcat_list = self.test.find_list_byclass(TextView) if contcat_list is None: break for c in contcat_list: str_tmps = c.text if 'test' in str_tmps or '10086' in str_tmps: flag = True actions.long_press(c).release().perform() delete_contact_button = self.test.find_byid( contacts_delete_button) delete_contact_button.click() time.sleep(1) delete_contact_button_list = self.test.find_byclass( Button, '删除') delete_contact_button_list.click() break else: flag = False if not flag: break flag = False contcat_list = self.test.find_list_byclass(TextView) for x in contcat_list: t = x.text if 'meig test' in t: flag = True if flag: self.Case.fail('删除失败')
def test_music_create(self): """导出-创建视频.""" sc.logger.info('分享-创建视频') fun_name = 'test_music_create' sc.logger.info('点击创作中心主按钮') c_btn = 'com.quvideo.xiaoying:id/img_creation' WebDriverWait( sc.driver, 10, 1).until(lambda el: el.find_element_by_id(c_btn)).click() sc.logger.info('点击“拍摄”') sc.driver.find_element_by_id('com.quvideo.xiaoying:id/icon2').click() el_cp = sc.driver.find_element_by_id('com.quvideo.xiaoying:id/btn_rec') # 长按拍摄 sc.logger.info('长按拍摄5s') actions = TouchAction(sc.driver) actions.long_press(el_cp, None, None, 5000).release().perform() sc.capture_screen(fun_name, self.img_path) next_btn = 'com.quvideo.xiaoying:id/cam_btn_next' WebDriverWait( sc.driver, 10, 1).until(lambda c_btn: c_btn.find_element_by_id(next_btn)).click() WebDriverWait( sc.driver, 10, 1).until(lambda el: el.find_element_by_android_uiautomator( 'text("存草稿")')).click() sc.capture_screen(fun_name, self.img_path) sc.logger.info('分享-创建视频完成')
def case_share_contact(self): if TestResult.getTestFail(self.failkey): self.Case.skipTest('case_if_base test fail, skip this') self.case_if_base() time.sleep(1) contacts_list = self.test.find_list_byclass(TextView) name = 'test meig' actions = TouchAction(self.driver) for c in contacts_list: str_tmp = c.text if name in str_tmp: actions.long_press(c).release().perform() time.sleep(1) break self.test.find_byid(contacts_share_contact).click() time.sleep(1) buletooth_list = self.test.find_list_byclass(TextView) devices = 'Redmi' devices_name = "" for b in buletooth_list: str_tmp = b.text if devices in str_tmp: b.click() devices_name = str_tmp time.sleep(2) break check_text = "正在向“" + devices_name + "”发送文件" if self.test.if_toast_text(check_text) is None: self.Case.fail("分享联系人失败")
def test_send_picture(self): '''群成员发送图片消息''' clear_massage(self, name="groupname1") clear_massage(self, name=u"系统通知") driver = self.driver with open('F:\Appium\group\groupID.txt', 'r') as f: el = f.read() driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/btn_address_list").click() #点击联系人 driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/tv_head_group").click() #点击群组 driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/p_list").click() #点击群组列表 el = u"群组id:" + el driver.find_element_by_name(el).click() #点击群组id,以后改为读取上一条用例创建群组的id #群成员发送图片 self.driver.find_element_by_id("chatting_attach_btn").click() #点击加号 self.driver.find_element_by_name(u"相册").click() #点击相册 self.driver.find_element_by_name("image").click() self.driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/checkmark").click() #点击选中 self.driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/btn_send").click() #点击发送 print "Start : %s" % time.ctime() #输出当前时间 time.sleep(5) print "Stop : %s" % time.ctime() #输出当前时间 #self.test_get_screen_by_element()#获取图片保存到本地 #删除发送的图片 el = self.driver.find_element_by_id("tv_read_unread") #状态 action1 = TouchAction(self.driver) action1.long_press(el, duration=5000).perform() self.driver.find_element_by_name(u"删除").click() self.driver.find_element_by_id("dilaog_button3").click() #确认删除
def test_long_press(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el1).move_to(el2).perform() el = self.driver.find_element_by_accessibility_id('Views') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Custom Adapter') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("People Names")') action.long_press(el).perform() # 'Sample menu' only comes up with a long press, not a tap el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Sample menu")') self.assertIsNotNone(el)
def longclick(self, xpath, resource_id, desc, x, y, index = None, time = 5, isAssert = True): # trying to click xpath if (xpath is not None and (resource_id is None or resource_id == '') and "android.webkit.WebView" in xpath): if x>0 and y>0: try: self.longtap(x,y,time) return True except: pass raise Exception("click point (%d, %d) failed" % (x, y)) elif (xpath is not None and xpath != '') or \ (resource_id is not None and resource_id != '') or \ (desc is not None and desc != ''): try: appium_action = TouchAction(self.driver) appium_element = self.wait_for_element(xpath=xpath, id=resource_id, text=desc, index=index) appium_action.long_press(appium_element, None, None, time * 1000).perform() if isAssert : self.log("assert", "true") return True except: pass if isAssert : self.log("assert", "false") raise Exception("click element id[%s] text[%s] not found" % (resource_id, desc)) else: #trying to click position if x>0 and y>0: try: self.longtap(x,y,time) return True except: pass raise Exception("click point (%d, %d) failed" % (x, y))
def test_edit_sound_add(self): """剪辑-配音-添加.""" sc.logger.info('剪辑-配音-添加') fun_name = 'test_edit_sound_add' start_x = self.width - self.width // 4 start_bottom = self.height - self.height // 10 time.sleep(1) sc.logger.info('点击创作中心主按钮') sc.driver.find_element_by_id( 'com.quvideo.xiaoying:id/img_creation').click() sc.logger.info('点击“更多草稿”') sc.driver.find_element_by_android_uiautomator('text("更多草稿")').click() sc.logger.info('点击草稿封面') el_draft = sc.driver.find_element_by_id( 'com.quvideo.xiaoying:id/xiaoying_studio_img_project_thumb') el_draft.click() sc.logger.info('点击“剪辑”') sc.driver.find_element_by_android_uiautomator('text("剪辑")').click() time.sleep(1) sc.swipe_by_ratio(start_x, start_bottom, 'left', 0.6, 500) el_edit_list = sc.driver.find_elements_by_id( 'com.quvideo.xiaoying:id/title') for el_item in el_edit_list: if el_item.text == '配音': sc.logger.info('开始点击配音') el_item.click() break el_record = sc.driver.find_element_by_id( 'com.quvideo.xiaoying:id/dub_panel_audio_record_btn') # 长按录制 sc.logger.info('长按拍摄5s') actions = TouchAction(sc.driver) actions.long_press(el_record, None, None, 5000).release().perform() sc.capture_screen(fun_name, self.img_path) """ x = record.location.get('x') y = record.location.get('y') sc.driver.swipe(x, y, x, y, 5000) """ sc.capture_screen(fun_name, self.img_path) sc.driver.find_element_by_id( 'com.quvideo.xiaoying:id/xiaoying_ve_imgbtn_add_audio_dub').click( ) time.sleep(2) el_audio_name = sc.driver.find_element_by_id( 'com.quvideo.xiaoying:id/musiclist_title') el_audio_name.click() sc.driver.find_element_by_id( 'com.quvideo.xiaoying:id/btn_add_music').click() sc.driver.find_element_by_id( 'com.quvideo.xiaoying:id/xiaoying_com_btn_right').click() sc.logger.info('返回创作中心主界面') for i in range(4): time.sleep(1) sc.driver.press_keycode(4) sc.logger.info('剪辑-配音-添加测试完成')
def default_unpinch(self): window_info = self.window_info() height = window_info[1] weight = window_info[2] # 起点横坐标为屏幕中点, 纵坐标为屏幕中点 head_x = int(weight * 0.5) head_y = int(height * 0.5) # 终点横坐标为屏幕中点(与起点横坐标一致), 纵坐标为屏幕下方三分之一 tail_x = head_x + 400 tail_y = head_y line_center_x = (head_x + tail_x) / 2 line_center_y = (head_y + tail_y) / 2 action_head = TouchAction(self.driver) action_tail = TouchAction(self.driver) # 放大 unpinch action_head.long_press(x=line_center_x, y=line_center_y, duration=200).move_to(x=100, y=0).release() action_tail.long_press(x=line_center_x, y=line_center_y, duration=200).move_to(x=-100, y=0).release() multi_action = MultiAction(self.driver) multi_action.add(action_head) multi_action.add(action_tail) multi_action.perform()
def long_press(self, locator, duration=1000): """ Долгий тап по элементу :param locator: Локатор для элемента :param duration: Продолжительность нажатия :return: """ element = self.find_element_helper.get_element(locator) action = TouchAction(self.driver) platform = self.service_function_helper.get_device_capabilities( 'platformName') if platform == "iOS": duration = duration * 0.0010 self.log.info( "Производим долгий тап по элементу с локатором: '{0}'".format( locator)) try: action.long_press(element, None, None, duration).perform() self.log.info( "Долгий тап по элементу c локатором: '{0}' прошел успешно". format(locator)) except error: message = "Не удалось произвести долгий тап по элементу с локатором: '{0}' из-за ошибки: {1}".\ format(locator, error) self.log.critical(message) assert False, message
def select_elements_and_long_press_on_first(self, elements, duration=1000): """ Выбрать несколько элементов (долгий тап по первому и обычные по остальным) :param elements: Локатор для элементов :param duration: Продолжительность нажатия :return: """ action = TouchAction(self.driver) platform = self.service_function_helper.get_device_capabilities( 'platformName') if platform == "iOS": duration = duration * 0.0010 self.log.info("Выбираем несколько элементов: '{0}'".format(elements)) try: action.long_press(elements[0], None, None, duration).perform() for e in range(1, len(elements)): elements[e].click() self.log.info( "Долгий тап по элементам: '{0}' прошел успешно".format( elements)) except error: message = "Не удалось произвести долгий тап по первому элементу: '{0}' из-за ошибки: '{1}'".\ format(elements, error) self.log.critical(message) assert False, message
def long_press(dr, s=None): try: em = dr.find_element_by_xpath(s) action = TouchAction(dr) action.long_press(em).release().perform() except: print 'failed to long press element'
def get_details_message_by_copy_past_item(self, x, y, copy_item_path, time_out=60): message = None touch_action = TouchAction(self.driver) current = time.time() logger.info("信息的坐标是 x = {}, y = {}".format(x, y)) while time.time() - current < time_out: touch_action.long_press(x=int(x), y=int(y), duration=500).release().perform() time.sleep(1) current_screenshot = os.path.join(copy_item_path, "current_screenshot_copy.png") self.driver.save_screenshot(current_screenshot) time.sleep(1) loc = Utils.match_image_by_match_template_func( current_screenshot, os.path.join(copy_item_path, "copy_item.png")) if loc: self.tap(loc["x"], loc["y"]) time.sleep(1) message = self.driver.get_clipboard_text() break if message: logger.info("成功获取到信息: {}".format(message)) else: logger.error("在60s内获取信息失败") return message
def click_point(self,x,y,duration=None): action = TouchAction(self) if duration: action.long_press(x=x, y=y, duration=duration).release() else: action.tap(x=x, y=y) action.perform() return self
def click_point(self,x,y,duration=None): self.logger.log("[action]click_point(x=%s,y=%s,duration=%s)" %(x,y,duration)) action = TouchAction(self) if duration: action.long_press(x=x, y=y, duration=duration).release() else: action.tap(x=x, y=y) action.perform() return self
def drag_and_drop(self, origin_el, destination_el): """Drag the origin element to the destination element :Args: - originEl - the element to drag - destinationEl - the element to drag to """ action = TouchAction(self) action.long_press(origin_el).move_to(destination_el).release().perform() return self
def remove_hub(self, card_name): card_title = self.driver.find_element_by_name(card_name.upper()) action = TouchAction(self.driver) action.long_press(card_title).release().perform() delete_hub_button = self.driver.find_element_by_xpath(DELETE_HUB_BUTTON) print('User removes hub') delete_hub_button.click() print('Check if hub is removed') self.search_hub(card_name) add_hub_button = self.driver.find_element_by_xpath(ADD_HUB_BUTTON % card_name.upper()) add_hub_button.is_displayed() print('%s hub is successfully removed' % card_name.upper())
def test_check_delete_collection(self): sleep(8) #滑动屏幕用以显示更多 self.scroll_screen(500, 500, 700, 70) #进入我的收藏页面 self.util.findElementByText(self.driver,"我的") self.util.findElementByText(self.driver,"我的收藏") #长按第一个收藏,并点击删除 action1 = TouchAction(self.driver) # el = self.driver.find_element_by_xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.ListView[1]/android.widget.FrameLayout[1]") el = self.driver.find_element_by_id(GD.COLLECT_PRODUCT_ID_ANDROID) action1.long_press(el).wait(1500).perform() self.util.findElementByText(self.driver,"确定")
def test_drag_and_drop(self): # first get to the right activity self.driver.start_activity("io.appium.android.apis", ".view.DragAndDropDemo") start = self.driver.find_element_by_id("io.appium.android.apis:id/drag_dot_3") end = self.driver.find_element_by_id("io.appium.android.apis:id/drag_dot_2") action = TouchAction(self.driver); action.long_press(start).move_to(end).release().perform() sleep(.5) text = self.driver.find_element_by_id("io.appium.android.apis:id/drag_result_text").text self.assertEqual(text, "Dropped!")
def long_press(self, locator, duration=1000): """ Tap and hold on an element for a given duration. :param locator: :param duration: :return: """ element = None if type(locator) == tuple: element = self.find_element(locator) elif 'appium.webdriver.webelement.WebElement' in str(type(locator)): element = locator action = TouchAction(self.driver) action.long_press(element, None, None, duration).perform()
def removeHub(self, card_name): card_title = self.driver.find_element_by_id(CARD_TITLE) action = TouchAction(self.driver) action.long_press(card_title).release().perform() delete_hub_button = self.driver.find_element_by_id(DELETE_HUB_BUTTON) print('User removes hub') delete_hub_button.click() print('Check if hub is removed') CardsNavigationPage.search_hub(self, card_name) add_hub_button = self.driver.find_element_by_xpath(ADD_HUB_BUTTON % card_name) if add_hub_button.is_displayed(): print('%s hub is successfully removed' % card_name) else: self.fail('%s hub is not removed' % card_name) sleep(3)
def testpushtotalk(self): sleep(1) self.driver.swipe(1100,300,110,300,200) sleep(3) self.driver.find_element_by_xpath("//android.widget.LinearLayout[@index = 1]").click() sleep(1) self.driver.find_element_by_xpath("//android.widget.Button[@index = 2]").click() sleep(1) self.driver.find_element_by_id("mobi.mmdt.ott.soroush:id/imageButton2").click() el_id = self.driver.find_element_by_xpath("//android.widget.LinearLayout[@index = 2]") el_id.find_element_by_id("mobi.mmdt.ott.soroush:id/imageView001").click() # el_id.find_element_by_xpath("//android.widget.RelativeLayout[@index = 0]").click() push_el = self.driver.find_element_by_id("mobi.mmdt.ott.soroush:id/push_to_talk_imageView") print push_el t= TouchAction TouchAction.long_press(self.t, push_el,800,2100,1000).perform()
def test_check_delete_collection(self): sleep(8) #滑动屏幕用以显示更多 self.util.scroll_screen(self.driver,500, 500, 700, 70) #进入我的收藏页面 self.util.findElementByText(self.driver,"我的") self.util.findElementByText(self.driver,"我的收藏") if(self.driver.current_activity == ".activity.user.NewLoginActivity"): self.util.logIn(self.driver) try: #长按第一个收藏,并点击删除 action1 = TouchAction(self.driver) # el = self.driver.find_element_by_xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.ListView[1]/android.widget.FrameLayout[1]") el = self.driver.find_element_by_id(GD.COLLECT_PRODUCT_ID_ANDROID) action1.long_press(el).wait(1500).perform() self.util.findElementByText(self.driver,"确定") except: print("没有收藏,删除失败")
def test_005(self): '''验证long_press方法''' width=self.driver.get_window_size()['width'] height=self.driver.get_window_size()['height'] t.sleep(5) self.driver.swipe(width*9/10,height/2,width/20,height/2,0) t.sleep(2) self.driver.swipe(width*9/10,height/2,width/20,height/2,0) t.sleep(2) self.driver.swipe(width*9/10,height/2,width/20,height/2,0) t.sleep(2) self.driver.swipe(width*9/10,height/2,width/20,height/2,0) touch=TouchAction(self.driver) t.sleep(5) element=self.driver.find_element_by_id('com.baozoumanhua.android:id/channel_tv') touch.long_press(element).perform() t.sleep(4) actual_text=self.driver.find_element_by_id('com.baozoumanhua.android:id/tv_channel_title').text self.assertEqual(actual_text,u'暴走大事件第四季')
def test_DelAnni_LongPress(self): try: anndateexist = self.driver.find_element_by_id(me.ann_date_exist) except NoSuchElementException as nee: print("No anniversary can delete!\n") ss.screenshot(self.driver) raise nee while 1: action1 = TouchAction(self.driver) action1.long_press(anndateexist).perform() if self.driver.find_element_by_id(me.ann_del_title).text == '删除提示': self.driver.find_element_by_id(me.confirm_btn_id).click() try: anndateexist = self.driver.find_element_by_id(me.ann_date_exist) except: print("Anniversaries were all deleted!\n") break else: continue
def test_drag_and_drop(self): el1 = self.driver.find_element_by_name('Content') el2 = self.driver.find_element_by_name('Animation') self.driver.scroll(el1, el2) el = self.driver.find_element_by_name('Views') action = TouchAction(self.driver) action.tap(el).perform() el = self.driver.find_element_by_name('Drag and Drop') action.tap(el).perform() dd3 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_3') dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2') # dnd is stimulated by longpress-move_to-release action.long_press(dd3).move_to(dd2).release().perform() el = self.driver.find_element_by_id('com.example.android.apis:id/drag_result_text') self.assertEqual('Dropped!', el.get_attribute('text'))
def test_drag_and_drop(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') self.driver.scroll(el1, el2) el = self.driver.find_element_by_accessibility_id('Views') action = TouchAction(self.driver) action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop') action.tap(el).perform() dd3 = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_dot_3') dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2') # dnd is stimulated by longpress-move_to-release action.long_press(dd3).move_to(dd2).release().perform() el = self.driver.find_element_by_id('com.example.android.apis:id/drag_text') self.assertTrue('drag_dot_3' in el.text)
class NB(): def __init__(self, driver=None): """ @type driver:WebDriver """ self.driver = driver self.action = TouchAction(self.driver) self.aw = action_word.ActionWord(driver) def add_book(self, topic): self.driver.find_element_by_name("NB.BookShelf.SearchField").click() self.driver.find_element_by_name("NB.BookShelf.SearchField").set_value(self.aw.get_par_list(topic)[1]) self.driver.find_element_by_name("搜索").click() # self.driver.find_element_by_name(self.aw.get_par_list(topic)[1]).click() self.driver.find_element_by_xpath('//*[@name="' + "加入书架" + '"]').click() self.aw.delete_windows() self.driver.find_element_by_name("Menu").click() self.driver.find_element_by_name("我的小说").click() def delete_book(self, topic): el1 = self.driver.find_element_by_name(self.aw.get_par_list(topic)[1]) time = 2000 # 毫秒 self.action.long_press(el1, time).wait(time).perform() self.driver.find_element_by_name("NB.BookShelf.Delete").click() self.driver.find_element_by_name("删除选中小说").click() def shelf_init(self, topic): self.deleteAll_books(0) #tst self.driver.find_element_by_name("孙子兵法").click() self.aw.click_mid(self.driver) try: self.driver.implicitly_wait(3) self.driver.find_element_by_name("bookReader_setting") except Exception, ex: self.aw.click_mid(self.driver) self.driver.implicitly_wait(10) self.driver.find_element_by_name("NB.Back.Boo.Shelf.Button").click()
def test_long_press(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el1).move_to(el2).perform() el = self.driver.find_element_by_accessibility_id('Views') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Custom Adapter') action.tap(el).perform() el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("People Names")') action.long_press(el).perform() # 'Sample menu' only comes up with a long press, not a tap el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Sample menu")') self.assertIsNotNone(el)
def test_long_press_x_y(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el1).move_to(el2).perform() el = self.driver.find_element_by_accessibility_id('Views') action.tap(el).perform() el = self.driver.find_element_by_accessibility_id('Expandable Lists') action.tap(el).perform() el = self.driver.find_element_by_accessibility_id('1. Custom Adapter') action.tap(el).perform() # the element "People Names" is located at 430:310 (top left corner) # location can be changed by phone resolusion, OS version action.long_press(x=430, y=310).perform() # 'Sample menu' only comes up with a long press, not a tap el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Sample menu")') self.assertIsNotNone(el)
def test_multitouch(self): driver = self.driver driver.implicitly_wait(90) action1 = TouchAction(driver) action1.long_press(None,1181,665).wait(500).release() action2 = TouchAction(driver) action2.long_press(None,838,1104).wait(500).release() action3 = TouchAction(driver) action3.long_press(None,588,1652).wait(500).release() multi = MultiAction(driver) multi.add(action1,action2,action3) multi.perform()
class ActionWord(): def __init__(self, driver): """ @type driver:WebDriver """ self.driver = driver self.action = TouchAction(self.driver) def click(self, topic): el1 = self.driver.find_element_by_name(self.get_par_list(topic)[1]) if self.get_par_list(topic).__len__() == 2: count = 1 else: count = int(self.get_par_list(topic)[2]) for i in range(0, count): if el1.is_displayed() == False: self.action.long_press(el1, 100).perform() else: self.driver.find_element_by_name(self.get_par_list(topic)[1]).click() def long_press(self, topic): """ 长按 eg: topic = long_press:ele_name:2 长按ele_name控件 2秒 """ el1 = self.driver.find_element_by_name(self.get_par_list(topic)[1]) time = int(self.get_par_list(topic)[2])*1000 #秒 self.action.long_press(el1, time).wait(time).perform() def move_to(self, topic): """ 长按一个控件拖至另一个控件位置(包括TableCell控件) eg: topic = move_to:ele_1:ele_2 长按ele_1然后移动至ele_2 """ el0 = self.driver.find_elements_by_name(self.get_par_list(topic)[1])[0] if el0.tag_name != "UIATableCell": el1 = self.driver.find_elements_by_name(self.get_par_list(topic)[2])[0] self.action.long_press(el0).wait(2000).move_to(el1).release().perform() else: self.cell_move(topic) def cell_move(self, topic): el0 = self.driver.find_elements_by_name(self.get_par_list(topic)[1])[0] el1 = self.driver.find_elements_by_name(self.get_par_list(topic)[2])[0] move_x = el0.size["width"]*0.9 move_y = el0.location["y"] + el0.size["height"]*0.5 to_x = el1.size["width"]*0.9 to_y = el1.location["y"] + el1.size["height"]*0.5 self.action.long_press(x=move_x, y=move_y).wait(2000).move_to(x=0, y=(to_y - move_y)).release().perform() def cell_swipe(self, topic): el0 = self.driver.find_elements_by_name(self.get_par_list(topic)[1])[0] start_x = el0.size["width"]*0.7 start_y = el0.location["y"] + el0.size["height"]*0.5 end_x = el0.size["width"]*0.2 end_y = start_y self.driver.swipe(start_x, start_y, end_x, end_y) def cell_del(self, topic): cell_name = self.get_par_list(topic)[1] del_lable = '''确认“''' + cell_name.encode('utf-8') + '''”上的删除''' try: self.driver.find_element_by_name("删除").click() except Exception,ex: #兼容6.x self.driver.find_element_by_name(del_lable).click()
def test_appiumfb(self): driver = self.driver driver.implicitly_wait(90) driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.android.dialer:id/contact_tile_name").text("Indiald")').click() driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.android.dialer:id/dialpadButton")').click() time.sleep(12) a1 = TouchAction(driver) a1.long_press(None,300,1141,100).release().perform() time.sleep(1) a1.long_press(None,1130,1703,100).release().perform() a1.long_press(None,300,1141,100).release().perform() a1.long_press(None,1130,1703,100).release().perform() a1.long_press(None,718,1703,100).release().perform() a1.long_press(None,718,1703,100).release().perform() a1.long_press(None,306,1421,100).release().perform() a1.long_press(None,720,1990,100).release().perform() a1.long_press(None,300,1141,100).release().perform() a1.long_press(None,1136,1415,100).release().perform() a1.long_press(None,1136,1415,100).release().perform() a1.long_press(None,1138,1136,100).release().perform() a1.long_press(None,721,1415,100).release().perform()
from appium.webdriver.common.touch_action import TouchAction action = TouchAction(android_caps.self) android_caps.self.find_element_by_id("maintab_layout_contact").click() android_caps.self.find_element_by_id("friend_action_search").click() android_caps.self.find_element_by_id("toolbar_search_edittext").send_keys("220850234") try: android_caps.self.find_element_by_id("section_title").click() except: print("没有搜素到用户") android_caps.self.find_element_by_id("profile_layout_start_chat").click() android_caps.self.find_element_by_id("message_ed_msgeditor").send_keys("recall message") android_caps.self.find_element_by_id("message_btn_sendtext").click() msgtext = android_caps.self.find_element_by_id("message_tv_msgtext") action.long_press(el=msgtext).perform() android_caps.self.find_element_by_android_uiautomator('new UiSelector().text("撤回")').click() try: android_caps.self.find_element_by_id("button1").is_displayed() android_caps.self.find_element_by_id("button1").click() try: android_caps.self.find_element_by_android_uiautomator('new UiSelector().text("你撤回了一条消息")').is_displayed() print("消息撤回成功") except: print("消息撤回失败") except: try: android_caps.self.find_element_by_android_uiautomator('new UiSelector().text("你撤回了一条消息")').is_displayed() print("消息撤回成功") except: print("消息撤回失败")
def long_press(self, locator, duration=1000): element = self.get_element(locator) action = TouchAction(self.driver) action.long_press(element, None, None, duration).perform()
android_caps.self.find_element_by_id("section_title").click() except: print("没有搜素到用户") android_caps.self.find_element_by_id("profile_layout_start_chat").click() # <---------文本消息发送测试---------> android_caps.self.find_element_by_id("message_ed_msgeditor").send_keys("text") android_caps.self.find_element_by_id("message_btn_sendtext").click() try: sleep(5) android_caps.self.find_element_by_android_uiautomator('new UiSelector().text("送达")') print("文本消息已送达") except: print("文本消息送达失败") msgtext = android_caps.self.find_element_by_id("message_tv_msgtext") action.long_press(el=msgtext).perform() android_caps.self.find_element_by_android_uiautomator('new UiSelector().text("删除消息")').click() sleep(2) try: android_caps.self.find_element_by_android_uiautomator('new UiSelector().text("text")').is_displayed() print("删除文本消息失败") except: print("删除文本消息成功,进行下一步") # <---------小表情发送测试---------> android_caps.self.find_element_by_id("message_btn_openemotes").click() android_caps.self.tap([(252, 1355), (252, 1355)], None) android_caps.self.find_element_by_id("message_btn_sendtext").click() try: sleep(5) android_caps.self.find_element_by_android_uiautomator('new UiSelector().text("送达")') print("小表情已送达")
def deal_gestures_password(self,case_element_name,gestures,nocheck=False): elem = self.super_find(case_element_name,nocheck=nocheck) points = self.parseGestures(elem.location,elem.size) action = TouchAction(self) for index,ges in enumerate(gestures): x,y = points[ges] if index == 0: action = action.long_press(x=x,y=y) else: action = action.move_to(x=x,y=y) action.release().perform() return self