def click_exit(): driver = config.driver action = TouchAction(driver) ele1 = driver.find_element_by_id("sessionid") ele2 = driver.find_element_by_id("no_instance") action.press(ele2).move_to(ele1).release().perform() driver.find_element_by_id("close_control").click()
def swipe(self,begin,end,duration=None): """Swipe from one point to another point, for an optional duration. :Args: - start_x - x-coordinate at which to start - start_y - y-coordinate at which to start - end_x - x-coordinate at which to stop - end_y - y-coordinate at which to stop - duration - (optional) time to take the swipe, in ms. :Usage: driver.swipe((100, 100), (100, 400)) """ # `swipe` is something like press-wait-move_to-release, which the server # will translate into the correct action self.logger.log("[action]swipe(begin=%s,end=%s,duration=%s)" %(begin,end,duration)) start_x, start_y = begin end_x, end_y = end self.logger.log("%s %s %s %s" %(start_x,start_y,end_x,end_y)) action = TouchAction(self) self.logger.log("action:%s" %action) action \ .press(x=start_x, y=start_y) \ .wait(ms=duration) \ .move_to(x=end_x, y=end_y) \ .release() action.perform() return self
def test_press_and_immediately_release_x_y(self): el = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el, 100, 10).release().perform() el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Bouncing Balls') self.assertIsNotNone(el)
def test_unlock(self): print "start" self.driver.find_element_by_id("com.paic.mo.client:id/pattern_to_login").click() common.wait_appear_by_id(self, "com.paic.mo.client:id/lockPattern", 10) action = TouchAction(self.driver) # 道理一样,就只写两个点了,用的test app的手势密码区域是一整张图片,只能使用坐标进行点击,效果见截图 action.press(x=298, y=1034).wait(1000).move_to(x=719, y=1034).release().perform()
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 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_find_elements(self): e1 = TouchAction() e1.press(x=110, y=200) \ .move_to(x=1, y=1) e1.release() sleep(8) elm_category = [] #elm.append(self.driver.find_element_by_xpath("//*[@text='穷游精选']")) textlist = ['分类','自由行'] for i in range (len(textlist)): #print(i) #elm.append(self.driver.find_element_by_xpath("//*[@text=%s"%textlist[i])) elm_category.append(self.driver.find_element_by_xpath("//*[@text='%s']"%textlist[i])) for i in range(len(elm_category)): elm_category[i].click() sleep(1) sleep(1) els_booking = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)') els_booking[6].click() #self.loop_for_list(els_booking) sleep(2) self.driver.find_element_by_xpath("//*[@text='立即预订']").click() sleep(2) self.book_detail() self.driver.find_element_by_xpath("//*[@text='提交订单']").click()
def tap(self, locator=None, x=None, y=None): """ Taps an element. :param locator: :return: """ element = None if locator is not None: if type(locator) == tuple: element = self.wait_present(locator) elif type(locator) == list: for l in locator: try: element = self.wait_present(l) break except NoSuchElementException: pass except TimeoutException: pass else: raise Exception('Cannot click element. Invalid locator type.') if element is None: raise Exception('Could not tap. Element not found.') action = TouchAction(self.driver) # try tapping again if it fails the first time twice try: action.tap(element, x=x, y=y).perform() return True except WebDriverException: action.tap(element, x=x, y=y).perform() return True
def target(**kwargs): try: driver = kwargs['driver'] startTag = kwargs['startTag'] temp_args = 'app-mitm.py %d' % kwargs['id'] log = kwargs['stdout'] err = kwargs['stderr'] args = ['mitmproxy','-s'] args.append(temp_args) print str(args) self.process = subprocess.Popen(args,stdout=log,stderr=err) if startTag == True: sleep(5) startTag = False else: sleep(2) els = driver.find_elements_by_id('com.cnn.mobile.android.phone:id/broadsheet_headline') el = els[0] location = el.location size = el.size el_x = location['x'] + size['width']/2 el_y = location['y'] + size['height']/2 action = TouchAction(driver) action.press(x=el_x, y=el_y).release().perform() self.process.wait() except: self.status = -1
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 test_find_single_element(self): el = self.driver.find_element_by_accessibility_id('Media') action = TouchAction(self.driver) action.tap(el).perform() sleep(SLEEPY_TIME) el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("MediaPlayer")') self.assertIsNotNone(el) sleep(SLEEPY_TIME)
def test_tap_x_y(self): el = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.tap(el, 100, 10).perform() sleep(SLEEPY_TIME) el = self.driver.find_element_by_accessibility_id('Bouncing Balls') self.assertIsNotNone(el)
def test_press_and_immediately_release_x_y(self): el = self.driver.find_element_by_accessibility_id('Animation') action = TouchAction(self.driver) action.press(el, 100, 10).release().perform() sleep(SLEEPY_TIME) el = self.driver.find_element_by_accessibility_id('Bouncing Balls') self.assertIsNotNone(el)
def test_scroll_element_position(self): els = self.driver.find_elements_by_class_name('android.widget.Button') self.assertEqual(4, len(els)) action = TouchAction(self.driver) action.press(els[-1]).move_to(x=10).release().perform() el = self.driver.find_element_by_name('Button7') self.assertIsNotNone(el)
def tap(self, locator, x=None, y=None, count=1): """ Tap on element """ driver = self._current_application() el = self._element_find(locator, True, True) action = TouchAction(driver) if x is None or y is None: action.tap(el).perform() else: action.tap(el, x, y, count).perform()
def test_services_map_tap(self): enter_menu(self) self.driver.find_element_by_android_uiautomator('textContains("Map")').click() el = self.driver.find_element_by_accessibility_id('Google Map') els = el.find_elements_by_class_name('android.view.View') action = TouchAction(self.driver) action.tap(els[0]).perform() self.driver.back() self.driver.back()
def long_click(self, locator, dur): """ Long press the element :Args: locator, duration(ms) - added by songz """ driver = self._current_application() element = self._element_find(locator, True, True) long_press = TouchAction(driver).press(element,x=None,y=None).wait(dur).release() long_press.perform()
def click_a_point(self, x=0, y=0, duration=100): """ Click on a point""" self._info("Clicking on a point (%s,%s)." % (x,y)) driver = self._current_application() action = TouchAction(driver) try: action.press(x=float(x), y=float(y)).wait(float(duration)).release().perform() except: assert False, "Can't click on a point at (%s,%s)" % (x,y)
def test_simpleLauncher(self): time.sleep(3) #testing begin from the simpleLauncher package='org.coolx.htvlauncher' try: el0 = self.driver.find_element_by_id(package+':id/btn_live') except: self.driver.keyevent(82) time.sleep(3) self.driver.find_element_by_id(package+':id/menu_tosimpleLauncher').click() else: action = TouchAction(self.driver) action.tap(el0).perform() time.sleep(3) self.driver.keyevent(4) #check notifications self.driver.keyevent(82) time.sleep(3) self.driver.keyevent(4) time.sleep(3) #live add icon #a=input('输入当前页面元素数目: ') #num =range(int(a)) #el = self.driver.find_element_by_class_name('android.widget.GridView') #els =el.find_elements_by_android_uiautomator('new UiSelector().resource_id('package+':id/gv_show_app')') #self.assertIsInstance(els, list) #els[1].click #find_elements_by_android_uiautomator('new UiSelector().class_name('android.widget.GridView').clickable(true)') # self.driver.find_element_by_xpath("//android.widget.GridView/android.widget.RelativeLayout[@index=1]").click() #time.sleep(3) #self.driver.find_element_by_xpath("//android.widget.GridView/android.widget.RelativeLayout[contains(@index,'0')]").click() #live remove icon #self.driver.find_element_by_xpath("//android.widget.GridView/android.widget.RelativeLayout[contains(@index,num[-1])]").click() #self.driver.find_element_by_xpath("//android.widget.GridView/android.widget.RelativeLayout[contains(@index,'1')]").click() #time.sleep(3) #self.driver.find_element_by_xpath("//android.widget.GridView/android.widget.RelativeLayout[contains(@index,'0')]").click() try: self.driver.find_element_by_id(package+':id/btn_vod') except: print('No vod Element' ) else: self.driver.find_element_by_id(package+':id/btn_vod').click() time.sleep(3) try: self.driver.find_element_by_id(package+':id/btn_playback') except: print('No playback Element' ) else: self.driver.find_element_by_id(package+':id/btn_playback').click() time.sleep(3) try: self.driver.find_element_by_id(package+':id/btn_other') except: print('No other Element' ) else: self.driver.find_element_by_id(package+':id/btn_other').click() time.sleep(3)
def test_press_and_moveto_x_y(self): el1 = self.driver.find_element_by_accessibility_id('Content') el2 = self.driver.find_element_by_accessibility_id('App') action = TouchAction(self.driver) action.press(el1).move_to(el2, 100, 100).release().perform() el = self.driver.find_element_by_accessibility_id('Views') self.assertIsNotNone(el)
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 test_driver_swipe(self): el = self.driver.find_element_by_accessibility_id('Views') action = TouchAction(self.driver) action.tap(el).perform() self.assertRaises(NoSuchElementException, self.driver.find_element_by_accessibility_id, 'ImageView') self.driver.swipe(100, 1000, 100, 100, 800) el = self.driver.find_element_by_accessibility_id('ImageView') self.assertIsNotNone(el)
def tap(self, x = None, y = None, count = 1): # Tap a coordinates (x,y) if (x == None) | (y == None) | (x > self.X) | (y > self.Y): raise AssertionError('Please input a correct coordinate') while count > 0: action = TouchAction(self.driver) action.press(x = x, y = y).release() action.perform() count-=1 sleep(constant.INTERVAL_1)
def touchxy(self, el): p = el.location s = el.size p_x = int(p["x"] + s["width"] / 2) p_y = int(p["y"] + s["height"] / 2) # print p_x,p_y # self.dr.tap([(p_x, p_y)],10) action = TouchAction(self.dr) action.press(x=p_x, y=p_y) action.perform() sleep(2)
def scroll(self, origin_el, destination_el): """Scrolls from one element to another :Args: - originalEl - the element from which to being scrolling - destinationEl - the element to scroll to :Usage: driver.scroll(el1, el2) """ action = TouchAction(self) action.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 tap(self, locator, x_offset=None, y_offset=None, count=1): """ Tap element identified by ``locator``. Args: - ``x_offset`` - (optional) x coordinate to tap, relative to the top left corner of the element. - ``y_offset`` - (optional) y coordinate. If y is used, x must also be set, and vice versa - ``count`` - can be used for multiple times of tap on that element """ driver = self._current_application() el = self._element_find(locator, True, True) action = TouchAction(driver) action.tap(el,x_offset,y_offset, count).perform()
def gesture(driver): """ 画手势密码,现在为第一排一横线,华为nexus6P手机,其他手机需要更换坐标点 :param driver: 初始化获取的webdriver :return:no """ action = TouchAction(driver) # move_to一定是相对坐标 unlock = action.press(x=240, y=915).wait(ms=100)\ .move_to(x=480, y=0).wait(ms=100)\ .move_to(x=480, y=0).wait(ms=100)\ .release() unlock.perform()
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,"确定")
# This sample code uses the Appium python client # pip install Appium-Python-Client # Then you can paste this into a file and simply run with Python from appium import webdriver from appium.webdriver.common.touch_action import TouchAction caps = {} caps["platformName"] = "Android" caps["deviceName"] = "PD2717C" caps["appPackage"] = "com.zybang.kousuan" caps["appActivity"] = ".activity.InitActivity" driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) TouchAction(driver).tap(x=792, y=1923).perform() TouchAction(driver).tap(x=792, y=1916).perform() TouchAction(driver).tap(x=536, y=792).perform() TouchAction(driver).tap(x=795, y=1920).perform() TouchAction(driver).tap(x=540, y=1883).perform() TouchAction(driver).tap(x=536, y=1879).perform() TouchAction(driver).tap(x=999, y=1868).perform() TouchAction(driver).tap(x=100, y=614).perform() TouchAction(driver).tap(x=544, y=1879).perform() TouchAction(driver).tap(x=751, y=1076).perform() TouchAction(driver).tap(x=288, y=1091).perform() TouchAction(driver).tap(x=939, y=1650).perform() TouchAction(driver).press(x=1036, y=1675).move_to(x=41, y=1687).release().perform() TouchAction(driver).tap(x=510, y=847).perform()
from platform import release from appium import webdriver import time from appium.webdriver.common.touch_action import TouchAction desired_caps = {} # 设备信息 desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '5.1' desired_caps['deviceName'] = '192.168.56.101:5555' # app信息 desired_caps['appPackage'] = 'com.android.settings' desired_caps['appActivity'] = '.Settings' # 声明driver对象 driver = webdriver.Remote('http://*****:*****@text,'WLAN')]") TouchAction(driver).press(wlan).release().perform() name = driver.find_element_by_xpath("//*[contains(@text,'486')]") TouchAction(driver).press(name).wait(1000).release().perform() # # 暂停5秒 time.sleep(5) driver.quit()
def move_to_camera(self): sleep(3) TouchAction(self.driver).tap(x=Camera.CAMERA_BUTTON_COOR[0], y=Camera.CAMERA_BUTTON_COOR[1]).perform()
def test_smiley_face(self): # just for the fun of it. # this doesn't really assert anything. # paint eye1 = TouchAction() eye1.press(x=150, y=100).release() eye2 = TouchAction() eye2.press(x=250, y=100).release() smile = TouchAction() smile.press(x=110, y=200) \ .move_to(x=1, y=1) \ .move_to(x=1, y=1) \ .move_to(x=1, y=1) \ .move_to(x=1, y=1) \ .move_to(x=1, y=1) \ .move_to(x=2, y=1) \ .move_to(x=2, y=1) \ .move_to(x=2, y=1) \ .move_to(x=2, y=1) \ .move_to(x=2, y=1) \ .move_to(x=3, y=1) \ .move_to(x=3, y=1) \ .move_to(x=3, y=1) \ .move_to(x=3, y=1) \ .move_to(x=3, y=1) \ .move_to(x=4, y=1) \ .move_to(x=4, y=1) \ .move_to(x=4, y=1) \ .move_to(x=4, y=1) \ .move_to(x=4, y=1) \ .move_to(x=5, y=1) \ .move_to(x=5, y=1) \ .move_to(x=5, y=1) \ .move_to(x=5, y=1) \ .move_to(x=5, y=1) \ .move_to(x=5, y=0) \ .move_to(x=5, y=0) \ .move_to(x=5, y=0) \ .move_to(x=5, y=0) \ .move_to(x=5, y=0) \ .move_to(x=5, y=0) \ .move_to(x=5, y=0) \ .move_to(x=5, y=0) \ .move_to(x=5, y=-1) \ .move_to(x=5, y=-1) \ .move_to(x=5, y=-1) \ .move_to(x=5, y=-1) \ .move_to(x=5, y=-1) \ .move_to(x=4, y=-1) \ .move_to(x=4, y=-1) \ .move_to(x=4, y=-1) \ .move_to(x=4, y=-1) \ .move_to(x=4, y=-1) \ .move_to(x=3, y=-1) \ .move_to(x=3, y=-1) \ .move_to(x=3, y=-1) \ .move_to(x=3, y=-1) \ .move_to(x=3, y=-1) \ .move_to(x=2, y=-1) \ .move_to(x=2, y=-1) \ .move_to(x=2, y=-1) \ .move_to(x=2, y=-1) \ .move_to(x=2, y=-1) \ .move_to(x=1, y=-1) \ .move_to(x=1, y=-1) \ .move_to(x=1, y=-1) \ .move_to(x=1, y=-1) \ .move_to(x=1, y=-1) smile.release() ma = MultiAction(self.driver) ma.add(eye1, eye2, smile) ma.perform() # so you can see it sleep(10)
def click_with_offset(self, x, y): action = TouchAction(self.driver) action.tap(self.ref(), x=x, y=y) action.perform()
# 设备信息 desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '5.1' desired_caps['deviceName'] = '192.168.56.101:5555' # 输入中文 desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True # app的信息 desired_caps['appPackage'] = 'com.android.settings' desired_caps['appActivity'] = '.Settings' # 声明我们的driver对象 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) """ 目标:模拟手势高级操作--按下,等待,释放 需求:1.打开设置 2.按下wlan5秒 方法:1.press 按下 2.wait等待 3.release:释放 4.perform:执行 """ # 定位wlan wlan = driver.find_element_by_xpath("//*[@text='WLAN']") # 单独测试按下 TouchAction(driver).press(wlan).perform() sleep(2) driver.quit()
def press_and_move_to_el(self, locator1, locator2): """按住并滑动""" element1 = self.get_element(self.__locators[locator1]) TouchAction(self.driver).long_press(element1).move_to(self.get_element(self.__locators[locator2])).wait( 2).release().perform()
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_send_txt(self): '''撤回离线文本、语音、图片、视频等消息''' try: logout.test_logout(self)#退出登录 except: print u"未登录,无需执行退出登录操作" time.sleep(2) login.test_login(self,phoneid="13311267857") time.sleep(2) driver= self.driver clear_massage(self,name=u"qiuqiu") clear_allmassage(self,id="com.yuntongxun.eckuailiao:id/nickname_tv") self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_address_list").click() time.sleep(2) self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/search").send_keys("13366778604") #self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_my").click()#点击搜索 中文输入时无需收回键盘 self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/account").click()#点击账号 #print "Start : %s" % time.ctime() time.sleep(2) self.driver.find_element_by_name(u"发消息").click()#点击发消息 #发送文本消息 set.set1() text1=get.get3() self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_content_et").send_keys(text1)#hello tester self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_send_btn").click()#发送 time.sleep(2) #撤销发送的消息 driver.swipe(600,300,600,1500,500)#下划 time.sleep(2) driver.swipe(600,300,600,1500,500)#下划 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_content_itv") action1 = TouchAction(self.driver) action1.long_press(el,duration=5000).perform() self.driver.find_element_by_name(u"撤销").click() #删除撤销的信息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_time_tv").get_attribute("text") assert_equal(el,u"你撤回了一条消息",msg=u'撤回消息消息验证失败') print u"撤回超长2048个字符消息成功" driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_right").click()#点击聊天详情 driver.find_element_by_name(u"清空聊天记录").click()#点击聊天详情 driver.press_keycode('4') #发送混合消息 driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_content_et").send_keys(u'中文1234567890ABCDEFGHIJKLMNOPQRSTUCWXYZabcdefghijklmnopqrstuvwxyz!#¥%……')#输入特殊字符 driver.find_element_by_id("com.yuntongxun.eckuailiao: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() #删除撤销的信息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_time_tv").get_attribute("text") assert_equal(el,u"你撤回了一条消息",msg=u'撤回消息消息验证失败') print u"撤回表情文本混合消息成功" driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_right").click()#点击聊天详情 driver.find_element_by_name(u"清空聊天记录").click()#点击聊天详情 driver.press_keycode('4') #发送消息表情 self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_smiley_btn").click()#点击切换表情 self.driver.find_element_by_name("😄").click()#点击表情 driver.find_element_by_id("com.yuntongxun.eckuailiao: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() #删除撤销的信息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_time_tv").get_attribute("text") assert_equal(el,u"你撤回了一条消息",msg=u'撤回消息消息验证失败') print u"撤回表情消息成功" driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_right").click()#点击聊天详情 driver.find_element_by_name(u"清空聊天记录").click()#点击聊天详情 driver.press_keycode('4') #发送语音消息 self.driver.find_element_by_id("chatting_mode_btn").click()#左下角语音按钮 action1 = TouchAction(self.driver) el = self.driver.find_element_by_id("voice_record_imgbtn") action1.long_press(el,duration=62000).perform() #撤销发送的消息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/tv_read_unread")#已读状态 action1 = TouchAction(self.driver) action1.long_press(el,duration=5000).perform() self.driver.find_element_by_name(u"撤销").click() #删除撤销的信息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_time_tv").get_attribute("text") assert_equal(el,u"你撤回了一条消息",msg=u'撤回消息消息验证失败') print u"撤回语音消息成功" driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_right").click()#点击聊天详情 driver.find_element_by_name(u"清空聊天记录").click()#点击聊天详情 driver.press_keycode('4') #成员发送图片 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()#点击选中 time.sleep(1) self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_send").click()#点击发送 #撤销发送的消息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/tv_read_unread")#已读状态 action1 = TouchAction(self.driver) action1.long_press(el,duration=5000).perform() self.driver.find_element_by_name(u"撤销").click() driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_right").click()#点击聊天详情 driver.find_element_by_name(u"清空聊天记录").click()#点击聊天详情 driver.press_keycode('4') #删除撤销的信息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_time_tv").get_attribute("text") assert_equal(el,u"你撤回了一条消息",msg=u'撤回消息消息验证失败') print u"撤回图片消息成功" #发送短视频 self.driver.find_element_by_id("chatting_attach_btn").click()#点击加号 self.driver.find_element_by_name(u"短视频").click() time.sleep(2) action1 = TouchAction(self.driver) el = self.driver.find_element_by_xpath("//android.widget.FrameLayout//android.view.View[2]") action1.long_press(el,duration=9000).perform() self.driver.find_element_by_xpath("//android.widget.FrameLayout//android.view.View[2]").click()#点击发送 #撤销发送的消息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/tv_read_unread")#已读状态 action1 = TouchAction(self.driver) action1.long_press(el,duration=5000).perform() self.driver.find_element_by_name(u"撤销").click() #删除撤销的信息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_time_tv").get_attribute("text") assert_equal(el,u"你撤回了一条消息",msg=u'撤回消息消息验证失败') print u"撤回短视频消息成功" ''' driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_right").click()#点击聊天详情 driver.find_element_by_name(u"清空聊天记录").click()#点击聊天详情 driver.press_keycode('4')''' time.sleep(2) driver.press_keycode('4') time.sleep(2) driver.press_keycode('4') logout.test_logout(self)#退出登录 login.test_login(self,phoneid="13366778604") self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_address_list").click() time.sleep(2) self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/search").send_keys("13311267857") self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/account").click()#点击账号 time.sleep(2) self.driver.find_element_by_name(u"发消息").click()#点击发消息 #撤销发送的消息 el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_time_tv").get_attribute("text") assert_equal(el,u'13311267857撤销了一条消息',msg=u'接收的消息验证失败') el = self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/chatting_time_tv") action1.long_press(el,duration=5000).perform() self.driver.find_element_by_name(u"删除").click() self.driver.find_element_by_id("dilaog_button3").click() driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_right").click()#点击聊天详情 driver.find_element_by_name(u"清空聊天记录").click()#点击聊天详情 self.driver.press_keycode('4')#点击返回键 print u"撤回的消息没有推送"
def test_send_voicemessage(self): '''发送惊悚变声语音消息''' clear_massage(self, name=u"qiuqiu") #删除消息页面,昵称为**的聊天记录 self.driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/btn_address_list").click() time.sleep(2) self.driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/search").send_keys("13311267857") #self.driver.find_element_by_id("com.yuntongxun.eckuailiao:id/btn_my").click()#点击搜索 self.driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/account").click() #点击账号 self.driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/phone_chat").click() #点击发消息 #发送变声语音 self.driver.find_element_by_id("chatting_mode_btn").click() #左下角语音按钮 time.sleep(2) self.driver.swipe(810, 1600, 54, 1600, 500) action1 = TouchAction(self.driver) el = self.driver.find_element_by_id("voice_record_imgbtn_biansheng") action1.long_press(el, duration=10000).perform() self.driver.find_element_by_name(u"惊悚").click() self.driver.find_element_by_id("layout_send_changevoice").click() time.sleep(6) #删除 el = self.driver.find_element_by_id("tv_read_unread").get_attribute( "text") assert_equal(el, u"已读", msg=u"状态验证失败") print el + u" 阅读状态验证成功" el = self.driver.find_element_by_id("tv_read_unread") #状态 action1 = TouchAction(self.driver) action1.long_press(el, duration=5000).perform() print "Start : %s" % time.ctime() #输出当前时间 time.sleep(2) print "Stop : %s" % time.ctime() #输出当前时间 self.driver.find_element_by_name(u"删除").click() self.driver.find_element_by_id("dilaog_button3").click() #确认删除 self.driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/chatting_voice_play_content").click( ) time.sleep(5) #删除接收语音 action1 = TouchAction(self.driver) el = self.driver.find_element_by_id( "com.yuntongxun.eckuailiao:id/chatting_time_tv") #时间 action1.long_press(el, duration=5000).perform() self.driver.find_element_by_name(u"删除").click() self.driver.find_element_by_id("dilaog_button3").click() #确认删除
driver.implicitly_wait(15) pop = driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.Button[2]') pop.click() driver.implicitly_wait(15) driver.find_element_by_id('com.vaultize.mobility:id/textUsername').send_keys('*****@*****.**') driver.implicitly_wait(15) driver.find_element_by_id('com.vaultize.mobility:id/textPasswd').send_keys('vault@123') driver.implicitly_wait(15) driver.find_element_by_id('com.vaultize.mobility:id/textUrl').send_keys('https://pune.vaultize.com') driver.implicitly_wait(15) driver.find_element_by_id('com.vaultize.mobility:id/buttonLogin').click() driver.implicitly_wait(15) #pop = driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.ScrollView/android.widget.LinearLayout') #driver.set_value(pop,'ALLOW') driver.implicitly_wait(15) actions = TouchAction(driver) driver.implicitly_wait(15) actions.tap(driver.find_element_by_id('com.vaultize.mobility:id/buttonOne')) actions.tap(driver.find_element_by_id('com.vaultize.mobility:id/buttonOne')) actions.tap(driver.find_element_by_id('com.vaultize.mobility:id/buttonOne')) actions.tap(driver.find_element_by_id('com.vaultize.mobility:id/buttonOne')) actions.tap(driver.find_element_by_id('com.vaultize.mobility:id/buttonOne')) actions.tap(driver.find_element_by_id('com.vaultize.mobility:id/buttonOne')) actions.tap(driver.find_element_by_id('com.vaultize.mobility:id/buttonOne')) actions.tap(driver.find_element_by_id('com.vaultize.mobility:id/buttonOne')) driver.implicitly_wait(15) actions.perform() driver.implicitly_wait(20) actions.scroll_from_element(element, 10, 100) actions.scroll(10, 100) actions.perform()
# Create Driver Instance driver = webdriver.Remote("http://*****:*****@text='OFF']").click() time.sleep(5) actions = TouchAction(driver) time.sleep(5) actions.press(x=375, y=2237) actions.move_to(x=434, y=910) actions.release() actions.perform() #actions.tap(x=1279,) driver.find_element_by_xpath("//hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[5]/android.widget.RelativeLayout").click() #go_back_button driver.find_element_by_class_name("android.widget.ImageButton").click() video_rawdata = driver.stop_recording_screen() video_name = driver.current_activity + time.strftime("%Y_%m_%d_%H%M%S")
#driver.implicitly_wait(40) driver.find_element_by_xpath("//android.widget.Button[@text='Próximo']").click() sleep(5) #driver.implicitly_wait(40) driver.find_element_by_xpath("//android.widget.Button[@text='Próximo']").click() sleep(5) #driver.implicitly_wait(40) driver.find_element_by_xpath("//android.widget.Button[@text='Vamos começar']").click() driver.implicitly_wait(40) driver.find_element_by_xpath("//android.view.View[@text='Já tenho conta']").click() sleep(5) driver.find_element_by_xpath("//android.widget.EditText[@text='Seu e-mail']").click() sleep(5) # Preenchimento do email:teste. Em suas respectivas posições no teclado! touch = TouchAction(driver) touch.tap(x=475, y=1240).perform() touch.tap(x=212, y=1398).perform() touch.tap(x=480, y=1251).perform() driver.find_element_by_xpath("//android.widget.EditText[@text='Senha']").click() sleep(5) # Preenchimento da senha: qee123. Em suas respectivas posições no teclado. touch.tap(x=57, y=1235).perform() touch.tap(x=271, y=1239).perform() touch.tap(x=273, y=1237).perform() for i in range(3): driver.find_element_by_class_name("android.widget.Button").click() sleep(3) print(driver.find_element_by_xpath("//android.widget.Button[@text='Recuperar minha senha']").get_attribute('displayed'))
click_title.click() click_title.send_keys('calendar1') ## pick up time and date. driver.find_element_by_id('com.ticktick.task:id/pick_up_time').click() driver.find_element_by_id('com.ticktick.task:id/item1').click() ## pick priority toggle. driver.find_element_by_id('com.ticktick.task:id/priority_toggle').click() driver.find_element_by_xpath( '//android.widget.RelativeLayout/android.widget.RadioButton').click() ## add tag. driver.find_element_by_id('com.ticktick.task:id/tag_toggle').click() # touch. action = TouchAction(driver) action.tap(x=645, y=1392).release().perform() time.sleep(1) action.tap(x=808, y=1236).release().perform() ## choose inbox. driver.find_element_by_id('com.ticktick.task:id/project_layout').click() driver.find_element_by_xpath( "//android.widget.RelativeLayout/android.widget.TextView[@text='Inbox']" ).click() save_btn = driver.find_element_by_id( 'com.ticktick.task:id/save_btn').click() except: print('TC-06 error of create new task in calendar with string.')
def long_click_element(self, locator): actions = TouchAction(An) actions.long_press(element) actions.perform()
def __touch_action(self): return TouchAction(self.driver)
def test_send_readrurn(self): '''发送阅后即焚,相册选取图片''' try: logout.test_logout(self) #退出登录 except: print "未登录,无需执行退出登录操作" login.test_login(self, phoneid="13311267857") self.driver.find_element_by_name(u"温强").click() time.sleep(2) #验证并删除上次发送的图片 el = self.driver.find_element_by_id("tv_read_unread").get_attribute( "text") assert_equal(el, u"已读", msg=u"状态验证失败") print el + u" 阅读状态验证成功" 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() #确认删除 #发送阅后即焚图片 self.driver.find_element_by_id("chatting_attach_btn").click() self.driver.find_element_by_name(u"阅后即焚").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() #点击发送 self.driver.press_keycode('4') #点击返回键 #self.driver.find_element_by_id("chatting_content_itv").click() time.sleep(2) logout.test_logout(self) #退出登录 login.test_login(self, phoneid="13366778604") #使用账号receive登录 time.sleep(2) self.driver.find_element_by_name("[图片]").click() self.driver.find_element_by_id("chatting_content_iv").click() time.sleep(2) self.driver.press_keycode('4') #点击返回键 print "Start : %s" % time.ctime() #输出当前时间 time.sleep(2) print "Stop : %s" % time.ctime() #输出当前时间 #获取点击后的图片 #self.test_get_screen_by_element() #对比焚毁的图片 #self.test_same_as() time.sleep(2) print u"接收图片成功" #发送阅后即焚图片 x1 = self.driver.find_element_by_id( "chatting_content_iv").location.get('x') y1 = self.driver.find_element_by_id( "chatting_content_iv").location.get('y') print x1, y1 x1 = int(x1) + 400 y1 = int(y1) + 100 print x1, y1 self.driver.tap([(x1, y1)], 5000) self.driver.find_element_by_name(u"删除").click() self.driver.find_element_by_id("dilaog_button3").click() #确认删除 self.driver.press_keycode('4') #点击返回键 logout.test_logout(self) #退出登录
def delete_optional(self, stock_name): ele = self.driver.find_element(By.XPATH, "//*[contains(@resource-id, 'portfolio_stockName') and @text='" + stock_name + "']") if ele: TouchAction(self.driver).long_press(el=ele, duration=3000).release().perform() # 长按 self.driver.find_element(By.XPATH, "//*[@text='删除']").click()
def test_resetpaypsw(self): try: try: publicmethods(self.driver).wait(page.AlertPage.确定['type'], 15, page.AlertPage.确定['value']) publicmethods(self.driver).findelement( page.AlertPage.确定['type'], page.AlertPage.确定['value']).click() publicmethods(self.driver).tapPage( dataes.Coordinate.行情页坐标['valuex'], dataes.Coordinate.行情页坐标['valuey']) except: pass publicmethods(self.driver).findelement( page.MinePage.我的['type'], page.MinePage.我的['value']).click() time.sleep(1) publicmethods(self.driver).tapPage( dataes.Coordinate.我的页坐标['valuex'], dataes.Coordinate.我的页坐标['valuey']) publicmethods(self.driver).wait(page.MinePage.资产总览['type'], 5, page.MinePage.资产总览['value']) try: # 上滑页面 publicmethods(self.driver).swipeUpDown(0.5, 0.8, 0.2) publicmethods(self.driver).hideWait(5) publicmethods(self.driver).findelement(page.MinePage.退出登录['type'], page.MinePage.退出登录['value'])\ .click() publicmethods(self.driver).findelement( page.AlertPage.确定['type'], page.AlertPage.确定['value']).click() # 下拉页面 publicmethods(self.driver).swipeUpDown(0.5, 0.2, 0.8) publicmethods(self.driver).hideWait(5) except: # 下拉页面 publicmethods(self.driver).swipeUpDown(0.5, 0.2, 0.8) publicmethods(self.driver).hideWait(5) publicmethods(self.driver).findelement( page.MinePage.登录['type'], page.MinePage.登录['value']).click() publicmethods(self.driver).wait(page.LoginPage.登录xpath['type'], 5, page.LoginPage.登录xpath['value']) publicmethods(self.driver).findelement( page.LoginPage.手机号切换按钮['type'], page.LoginPage.手机号切换按钮['value']).click() publicmethods(self.driver).wait(page.LoginPage.登录手机号['type'], 5, page.LoginPage.登录手机号['value']) publicmethods(self.driver).findelement( page.LoginPage.登录手机号['type'], page.LoginPage.登录手机号['value']).clear() publicmethods(self.driver).findelement(page.LoginPage.登录手机号['type'],page.LoginPage.登录手机号['value']).send_keys\ (str(dataes.PhoneAccount.重置支付密码手机号['value'])) publicmethods(self.driver).findelement( page.LoginPage.发送登录验证码['type'], page.LoginPage.发送登录验证码['value']).click() publicmethods(self.driver).findelement(page.LoginPage.登录验证码['type'],page.LoginPage.登录验证码['value']).send_keys\ (str(dataes.VerificationCode.验证码['value'])) publicmethods(self.driver).findelement(page.LoginPage.登录['type'], page.LoginPage.登录['value'], num=1).click() try: publicmethods(self.driver).findelement( page.AlertPage.确定['type'], page.AlertPage.确定['value']).click() except: pass publicmethods(self.driver).wait(page.MinePage.我的信息['type'], 5, page.MinePage.我的信息['value']) publicmethods( self.driver).findelement(page.MinePage.我的信息['type'], page.MinePage.我的信息['value']).click() publicmethods(self.driver).hideWait(5) # 获取九宫格起始位置坐标 loc = publicmethods(self.driver).findelement( page.JiuGongGe.九宫格['type'], page.JiuGongGe.九宫格['value']).location # 获取九宫格宽高 jiu_s = publicmethods(self.driver).findelement( page.JiuGongGe.九宫格['type'], page.JiuGongGe.九宫格['value']).size # 将获取的九宫格九个点的坐标列表传给gongge gongge = publicmethods(self.driver).jiu(loc, jiu_s) # print(gongge) # print(gongge[1][1]) # print(type(publicmethods(self.driver).pianyi(1,2,gongge)[0])) # 执行解锁(滑动操作) gongge[x]为元组,使用*gongge[x]将元组中的元素提取出来作为参数传入 # move_to中坐标为绝对坐标,至于到底使用相对偏移量还是绝对坐标,需要查看方法源码 TouchAction(self.driver).press(*gongge[1]).wait(300).move_to(*gongge[2]).wait(300)\ .move_to(*gongge[3]).wait(300).move_to(*gongge[6]).wait(300)\ .move_to(*gongge[9]).wait(300).release().perform() publicmethods(self.driver).wait(page.MineInfoPage.密码管理['type'], 15, page.MineInfoPage.密码管理['value']) publicmethods(self.driver).findelement(page.MineInfoPage.密码管理['type'],page.MineInfoPage.密码管理['value'])\ .click() publicmethods(self.driver).wait( page.MineInfoPage.忘记理财支付密码['type'], 15, page.MineInfoPage.忘记理财支付密码['value']) publicmethods(self.driver).findelement( page.MineInfoPage.忘记理财支付密码['type'], page.MineInfoPage.忘记理财支付密码['value']).click() publicmethods(self.driver).wait( page.ForgetPayPswPage.忘记理财支付密码主页['type'], 5, page.ForgetPayPswPage.忘记理财支付密码主页['value']) # 切换webview之前获取页面宽高 x = self.driver.get_window_size()['width'] # 获取屏幕宽度 y = self.driver.get_window_size()['height'] # 获取屏幕高度 contexts = self.driver.contexts # print(contexts) # chromedriver与手机webview中的chrome版本必须一致,否则switch_to会报错 # 切换到webview self.driver.switch_to.context(contexts[1]) # print(self.driver.current_context) publicmethods(self.driver).wait(page.ForgetPayPswPage.持卡人['type'], 15, page.ForgetPayPswPage.持卡人['value']) publicmethods(self.driver).findelement(page.ForgetPayPswPage.持卡人['type'],page.ForgetPayPswPage.持卡人['value'])\ .send_keys(dataes.ForgetPayPswInfo.持卡人['fullname']) publicmethods(self.driver).findelement(page.ForgetPayPswPage.身份证['type'],page.ForgetPayPswPage.身份证['value'])\ .send_keys(str(dataes.ForgetPayPswInfo.身份证['idno'])) publicmethods(self.driver).findelement(page.ForgetPayPswPage.卡号['type'],page.ForgetPayPswPage.卡号['value'])\ .send_keys(str(dataes.ForgetPayPswInfo.卡号['cardno'])) publicmethods(self.driver).findelement(page.ForgetPayPswPage.手机号['type'],page.ForgetPayPswPage.手机号['value'])\ .send_keys(str(dataes.ForgetPayPswInfo.手机号['phone'])) publicmethods(self.driver).findelement( page.ForgetPayPswPage.获取验证码['type'], page.ForgetPayPswPage.获取验证码['value']).click() time.sleep(2) publicmethods(self.driver).findelement(page.ForgetPayPswPage.验证码['type'],page.ForgetPayPswPage.验证码['value'])\ .send_keys(str(dataes.ForgetPayPswInfo.验证码['code'])) publicmethods(self.driver).findelement( page.ForgetPayPswPage.确定['type'], page.ForgetPayPswPage.确定['value']).click() publicmethods(self.driver).wait( page.ForgetPayPswPage.支付密码['type'], 5, page.ForgetPayPswPage.支付密码['value']) publicmethods(self.driver).findelement( page.ForgetPayPswPage.支付密码['type'], page.ForgetPayPswPage.支付密码['value']).click() # time.sleep(1) publicmethods(self.driver).wait( page.ForgetPayPswPage.安全软键盘页['type'], 5, page.ForgetPayPswPage.安全软键盘页['value']) # 自定义软键盘太恶心了,我还是服气了。暴力解决吧。。。 # adb = 'adb shell input tap 179 1355' # os.system(adb) # 将获取的软键盘按键坐标点的坐标字典传给numbutton numbutton = publicmethods(self.driver).H5keyboard(x, y) # 点击按键1 btn1 = 'adb shell input tap %s %s' % (numbutton[1][0], numbutton[1][1]) os.system(btn1) # 点击按键4 btn4 = 'adb shell input tap %s %s' % (numbutton[4][0], numbutton[4][1]) os.system(btn4) # 点击按键7 btn7 = 'adb shell input tap %s %s' % (numbutton[7][0], numbutton[7][1]) os.system(btn7) # 点击按键2 btn2 = 'adb shell input tap %s %s' % (numbutton[2][0], numbutton[2][1]) os.system(btn2) # 点击按键5 btn5 = 'adb shell input tap %s %s' % (numbutton[5][0], numbutton[5][1]) os.system(btn5) # 点击按键8 btn8 = 'adb shell input tap %s %s' % (numbutton[8][0], numbutton[8][1]) os.system(btn8) publicmethods(self.driver).findelement( page.ForgetPayPswPage.确认密码['type'], page.ForgetPayPswPage.确认密码['value']).click() publicmethods(self.driver).wait( page.ForgetPayPswPage.安全软键盘页['type'], 5, page.ForgetPayPswPage.安全软键盘页['value']) # 点击按键1 btn1 = 'adb shell input tap %s %s' % (numbutton[1][0], numbutton[1][1]) os.system(btn1) # 点击按键4 btn4 = 'adb shell input tap %s %s' % (numbutton[4][0], numbutton[4][1]) os.system(btn4) # 点击按键7 btn7 = 'adb shell input tap %s %s' % (numbutton[7][0], numbutton[7][1]) os.system(btn7) # 点击按键2 btn2 = 'adb shell input tap %s %s' % (numbutton[2][0], numbutton[2][1]) os.system(btn2) # 点击按键5 btn5 = 'adb shell input tap %s %s' % (numbutton[5][0], numbutton[5][1]) os.system(btn5) # 点击按键8 btn8 = 'adb shell input tap %s %s' % (numbutton[8][0], numbutton[8][1]) os.system(btn8) publicmethods(self.driver).findelement( page.ForgetPayPswPage.下一步['type'], page.ForgetPayPswPage.下一步['value']).click() # 切换回native再找toast元素 self.driver.switch_to.context(contexts[0]) try: publicmethods(self.driver).wait(page.ToastPage.密码重置成功['type'], 5, page.ToastPage.密码重置成功['value']) publicmethods(self.driver).getScreenShot('忘记支付密码', '成功') time.sleep(2) # 返回至我的页面 publicmethods(self.driver).backKey() publicmethods(self.driver).backKey() time.sleep(1) # 上滑页面 publicmethods(self.driver).swipeUpDown(0.5, 0.8, 0.2) publicmethods(self.driver).hideWait(5) publicmethods(self.driver).findelement( page.MinePage.退出登录['type'], page.MinePage.退出登录['value']).click() publicmethods(self.driver).findelement( page.AlertPage.确定['type'], page.AlertPage.确定['value']).click() except: print('未找到指定控件,案例失败') self.assertEqual(1, 2) except: # 当在H5页面报错时,要切回appium驱动进行操作 self.driver.switch_to.context(contexts[0]) publicmethods(self.driver).getScreenShot('忘记支付密码', '失败') # 报错信息 raise
desired_caps['resetKeyboard'] = "True" driver = webdriver.Remote('http://*****:*****@text='Security & Location']") #找到Security & Location按钮 TouchAction(driver).tap(security_button).perform() #执行点击功能 #进入安全界面后点击锁屏菜单 screen_lock_button = driver.find_element_by_xpath( "//*[@text='Screen lock']") #找到Security & Location按钮 TouchAction(driver).tap(screen_lock_button).perform() #执行点击功能 #输入正确的手势密码 #从一个坐标移动到另外一个坐标 TouchAction(driver).press(x=100, y=351).move_to(x=300, y=456).move_to( x=688, y=4677).move_to(x=988, y=688).release().perform() #从一个元素移动到另外一个元素
def test_LoginWithRightCredential(): driver.find_element_by_id("com.ATG.World:id/getStartedTv").click() driver.find_element_by_id("com.ATG.World:id/login_email").click() email = driver.find_element_by_id("com.ATG.World:id/email") email.send_keys("*****@*****.**") password = driver.find_element_by_id("com.ATG.World:id/password") password.send_keys("Pass@123") signin = driver.find_element_by_id("com.ATG.World:id/email_sign_in_button") signin.click() print("test_LoginWithRightCredential passed") test_LoginWithRightCredential() time.sleep(3) TouchAction(driver).tap(None, 221, 1122).perform() time.sleep(3) TouchAction(driver).tap(None, 228, 1303).perform() time.sleep(3) TouchAction(driver).tap(None, 716, 2185).perform() time.sleep(3) TouchAction(driver).tap(None, 944, 966).perform() time.sleep(3) driver.find_element_by_id( "com.android.permissioncontroller:id/permission_allow_foreground_only_button" ).click() time.sleep(3) driver.find_element_by_id( "com.android.permissioncontroller:id/permission_allow_button").click() Btn = driver.find_element_by_xpath( "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.appcompat.widget.LinearLayoutCompat/android.widget.FrameLayout/android.widget.ListView/android.widget.TextView[1]"
caps["app"] = "C:\\Users\\Administrator\\Desktop\\App\\yidongzixishi_4.6.1.apk" caps["appPackage"] = "com.offcn.yidongzixishi" caps["appActivity"] = "com.offcn.yidongzixishi.SplashActivity" caps["noReset"] = False driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) time.sleep(3) driver.find_element_by_id("com.offcn.yidongzixishi:id/skip").click() driver.find_element_by_id("com.offcn.yidongzixishi:id/et_phone").send_keys( "13242849900") driver.find_element_by_id("com.offcn.yidongzixishi:id/et_pwd").click() driver.find_element_by_id("com.offcn.yidongzixishi:id/et_pwd").send_keys( "13242849900qjx~") driver.find_element_by_id("com.offcn.yidongzixishi:id/btn_login").click() time.sleep(3) q = TouchAction(driver) q.press(x=521, y=1155) q.move_to(x=61, y=-768) q.release() q.perform() time.sleep(3) driver.find_element_by_xpath("/hierarchy" "/android.widget.FrameLayout" "/android.widget.LinearLayout" "/android.widget.FrameLayout" "/android.widget.LinearLayout" "/android.widget.FrameLayout" "/android.widget.LinearLayout" "/android.widget.LinearLayout" "/android.widget.RelativeLayout" "/android.support.v7.widget.RecyclerView"
caps = {} caps["deviceName"] = "sanxing" caps["appPackage"] = "com.xueqiu.android" caps["appActivity"] = ".view.WelcomeActivityAlias" caps["platformName"] = "Android" caps["autoGrantPermissions"] = "true" driver = webdriver.Remote("http://*****:*****@resource-id,'appbar')]//*[@text='基金']").click() time.sleep(2) rect = driver.get_window_rect() actions = TouchAction(driver) def swipe(): for i in range(5): actions.press(x=rect['width'] * 0.8, y=rect['height'] * 0.8)\ .move_to(x=rect['width'] * 0.2,y=rect['height'] * 0.2)\ .release()\ .perform() # 忘记写x=, y= 了 def left_swipe(): actions.press(x=rect['width'] * 0.8, y=rect['height'] * 0.5)\ .move_to(x=rect['width'] * 0, y=rect['height'] * 0.5)\ .release()\ .perform()
def tap_at(self, _x=0, _y=0, t=1): TouchAction(self.driver).tap(x=_x * self.dev_window_size['width'] / WIN_SIZE_RN8P['width'], y=_y).perform() time.sleep(t)
try: driver.find_element_by_id('com.ticktick.task:id/skip_tutorial').click() except: print('initial error.') # tag try: click_button = driver.find_element_by_id('com.ticktick.task:id/add_task_btn').click() click_title = driver.find_element_by_id('com.ticktick.task:id/quick_add_title') click_title.click() click_title.send_keys('normal_tag') ## add tag. driver.find_element_by_id('com.ticktick.task:id/tag_toggle').click() # touch. action = TouchAction(driver) action.tap(x=645,y=1392).release().perform() time.sleep(1) action.tap(x=808,y=1236).release().perform() # save task and show . save_btn = driver.find_element_by_id('com.ticktick.task:id/save_btn').click() driver.find_element_by_xpath("//android.support.v7.widget.RecyclerView/android.view.View[@index='0']").click() driver.find_element_by_xpath("//android.widget.ImageButton").click() except: print('error of create new task with string.') # null tag. try: click_button = driver.find_element_by_id('com.ticktick.task:id/add_task_btn').click() click_title = driver.find_element_by_id('com.ticktick.task:id/quick_add_title')
def longpress(self): base = Base(self.driver) el = base.findElements( [By.ID, "com.cnmts.smart_message:id/text_message"])[0] TouchAction(self.driver).long_press(el, 1000).perform()
def testGetStats(self): # search_button = self.driver.find_element_by_xpath('//android.widget.ImageView[@content-desc="Search"]') # while not (self.existsByAccessibilityId('Account')): # pass time.sleep(7) account_button = self.driver.find_element_by_accessibility_id( 'Account') account_button.click() while not (self.existsByXpath('/hierarchy/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.support.v7.widget.RecyclerView/android.widget.LinearLayout[6]' )): pass settings_button = self.driver.find_element_by_xpath( '/hierarchy/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.support.v7.widget.RecyclerView/android.widget.LinearLayout[6]' ) settings_button.click() while not (self.existsByXpath('/hierarchy/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/\ android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ListView/\ android.widget.LinearLayout[1]/android.widget.RelativeLayout')): pass general_settings_button = self.driver.find_element_by_xpath( '/hierarchy/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/\ android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ListView/\ android.widget.LinearLayout[1]/android.widget.RelativeLayout') general_settings_button.click() while not (self.existsByXpath( '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/\ android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/\ android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.widget.ListView/android.widget.LinearLayout[7]/android.widget.LinearLayout/\ android.widget.Switch')): pass enable_stats_switch = self.driver.find_element_by_xpath( '/hierarchy/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/\ android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/\ android.widget.LinearLayout/android.widget.ListView/android.widget.LinearLayout[7]/\ android.widget.LinearLayout/android.widget.Switch') enable_stats_switch.click() navigate_up = self.driver.find_element_by_accessibility_id( 'Navigate up') navigate_up.click() navigate_up.click() search_button = self.driver.find_element_by_accessibility_id('Search') search_button.click() search_box = self.driver.find_element_by_id( 'com.google.android.youtube:id/search_edit_text') search_box.send_keys(VIDEO_SEARCH) self.driver.press_keycode(66) # time.sleep(5) while not (self.existsByXpath( '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/\ android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/\ android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/\ android.widget.FrameLayout[2]/android.widget.FrameLayout/android.support.v7.widget.RecyclerView/\ android.widget.FrameLayout[1]/android.widget.LinearLayout')): pass video = self.driver.find_element_by_xpath( '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/\ android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout/\ android.view.ViewGroup/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.FrameLayout/\ android.support.v7.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.LinearLayout' ) video.click() time.sleep(1) # more_options = self.driver.find_element_by_xpath('//android.widget.ImageView[@content-desc="More options"]') # tap_video = self.driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout\ # /android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout\ # /android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup\ # /android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup\ # /android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.FrameLayout\ # /android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.View') # tap_video.click() # more_options.click() if (self.constant_quality): action1 = TouchAction(self.driver) action1.tap(None, 1365, 175) action1.perform() action2 = TouchAction(self.driver) action2.tap(None, 1365, 175) action2.perform() while not (self.existsByXpath( '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/\ android.widget.RelativeLayout[2]')): pass quality_button = self.driver.find_element_by_xpath( '/hierarchy/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.widget.ListView/android.widget.RelativeLayout[2]') quality_button.click() while not (self.existsByXpath( '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/\ android.widget.RelativeLayout[2]')): pass quality = self.driver.find_element_by_xpath( '/hierarchy/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/\ android.widget.ListView/android.widget.RelativeLayout[2]') quality.click() action1 = TouchAction(self.driver) action1.tap(None, 1365, 175) action1.perform() action2 = TouchAction(self.driver) action2.tap(None, 1365, 175) action2.perform() while not (self.existsByXpath( '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/\ android.widget.RelativeLayout[4]')): pass stats_button = self.driver.find_element_by_xpath( '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/\ android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/\ android.widget.RelativeLayout[4]') stats_button.click() # copy_info_button = self.driver.find_element_by_id('com.google.android.youtube:id/copy_debug_info_button') # copy_info_button.click() # text = self.driver.get_clipboard_text() # with open(RESULT_FILE, 'w') as f: # f.write("TimeStamp" + '\t' + "VideoFormat" + '\t' + "AudioFormat" + '\t' + "ReadAhead" + '\t' + "Viewport" + '\t' + "BandwidthEstimate" + \ # '\t' + "DroppedFrames" + '\n') with open(RESULT_FILE, 'w') as f: f.write("TimeStamp" + '\t' + "VideoFormat" + '\t' + "BandwidthEstimate" + '\t' + "DroppedFrames" + '\n') # readahead_num = -1 output_list = [] # current_time_obj = 0 # total_time_obj = 1 while True: try: video_format = self.driver.find_element_by_id( 'com.google.android.youtube:id/video_format').text audio_format = self.driver.find_element_by_id( 'com.google.android.youtube:id/audio_format').text readahead = self.driver.find_element_by_id( 'com.google.android.youtube:id/readahead').text viewport = self.driver.find_element_by_id( 'com.google.android.youtube:id/viewport').text bandwidth_estimate = self.driver.find_element_by_id( 'com.google.android.youtube:id/bandwidth_estimate').text dropped_frames = self.driver.find_element_by_id( 'com.google.android.youtube:id/dropped_frames').text # if not (self.existsById('com.google.android.youtube:id/time_bar_current_time')): # action3 = TouchAction(self.driver) # action3.tap(None, 565, 175) # action3.perform() # current_time = self.driver.find_element_by_id('com.google.android.youtube:id/time_bar_current_time').text # total_time = self.driver.find_element_by_id('com.google.android.youtube:id/time_bar_total_time').text # current_time_obj = datetime.strptime(current_time, '%M:%S') # total_time_obj = datetime.strptime(total_time, '%M:%S') # readahead_num = float(readahead[:-2]) # print datetime.now().strftime("%M:%S") # output_list.append(str(current_time_obj.time()) + '\t' + video_format + '\t' + audio_format + '\t' + readahead + '\t' + viewport + '\t' + \ # bandwidth_estimate + '\t' + dropped_frames) output_list.append(str(datetime.now().strftime("%M:%S")) + '\t' + video_format + '\t' + audio_format + '\t' + readahead + '\t' + viewport + '\t' + \ bandwidth_estimate + '\t' + dropped_frames) # output_list.append(str(datetime.now().strftime("%M:%S")) + '\t' + video_format + '\t' + dropped_frames) if (self.existsById('com.google.android.youtube:id/countdown') ): break except NoSuchElementException: # with open(RESULT_FILE, 'a') as f: # for row in output_list: # f.write(row + '\n') continue with open(RESULT_FILE, 'a') as f: for row in output_list: f.write(row + '\n')
def _tap(self, el): actions = TouchAction(self.driver) actions.tap(el) actions.perform()
def press(self, el, times=3000): """按压操作""" TouchAction(self.driver).long_press(el, duration=times).wait(1).perform()
# 短按(press) # 长按(longPress) # 点击(tap) # 移动到(move_to) x,y为相对上一个坐标的移动距离 # 等待(wait) # 释放(release) # 执行(perform) # 取消(cancel) # ####正方形视图处理 ele = driver.find_element_by_id("") #元素的大小 size = ele.size #均分的步长 高和宽一样。 step = size["width"] / 6 #元素的起点坐标 - 左上角 ori = ele.location point1 = (ori["x"] + step, ori["y"] + step) point2 = (point1[0] + step * 2, point1[1]) ##相对于pointl, X轴增加了2*step point3 = (point2[0] + step * 2, point2[1]) ##相对于point2, X轴增加了2*step point4 = (point3[0] - step * 2, point3[1] + step * 2 ) #相对于point3, X轴减少了2*step,Y轴增加了2*step point5 = (point4[0], point4[1] + step * 2) #相对于point4, X轴不变, Y轴增加了2*step TouchAction(driver).\ press(x=point1[0], y=point1[1]).wait(200).\ move_to(x=point2[0], y=point2[1]). wait(200).\ move_to(x=point3[0], y=point3[1]). wait(200).\ move_to(x=point4[0], y=point4[1]). wait(200).\ move_to(x=point5[0], y=point5[1]). wait (200).\ release().\ perform()
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