示例#1
0
def line_unlock(step):
    element = step['element']
    duration = float(step['data'].get('持续时间', 0.3))
    assert isinstance(element, list) and len(
        element) > 2, '坐标格式或数量不对,正确格式如:lock_pattern|1|4|7|8|9'
    _e = locating_element(element[0])
    rect = _e.rect
    w = rect['width'] / 6
    h = rect['height'] / 6

    key = {}
    key['1'] = (rect['x'] + 1 * w, rect['y'] + 1 * h)
    key['2'] = (rect['x'] + 3 * w, rect['y'] + 1 * h)
    key['3'] = (rect['x'] + 5 * w, rect['y'] + 1 * h)
    key['4'] = (rect['x'] + 1 * w, rect['y'] + 3 * h)
    key['5'] = (rect['x'] + 3 * w, rect['y'] + 3 * h)
    key['6'] = (rect['x'] + 5 * w, rect['y'] + 3 * h)
    key['7'] = (rect['x'] + 1 * w, rect['y'] + 5 * h)
    key['8'] = (rect['x'] + 3 * w, rect['y'] + 5 * h)
    key['9'] = (rect['x'] + 5 * w, rect['y'] + 5 * h)

    action = TouchAction(g.driver)
    for i in range(1, len(element)):
        k = element[i]
        if i == 1:
            action = action.press(
                x=key[k][0], y=key[k][1]).wait(duration * 1000)
        action.move_to(x=key[k][0], y=key[k][1]).wait(duration * 1000)
    action.release().perform()
示例#2
0
    def test_contact(self):
        # xpath
        contact_ele = self.driver.find_element(
            MobileBy.XPATH,
            "//*[@text='我' and @resource-id ='com.tencent.mm:id/cns']")
        contact_ele.click()

        contact_ele2 = self.driver.find_element(
            MobileBy.XPATH,
            "//*[@text='收藏' and @resource-id ='android:id/title']")
        contact_ele2.click()
        self.driver.implicitly_wait(20)
        contact_ele2 = self.driver.find_element(
            MobileBy.XPATH,
            "//*[@text='新国都集团开年大吉-2021接力跑挑战赛' and @resource-id ='com.tencent.mm:id/bwa']"
        )
        contact_ele2.click()

        time.sleep(5)
        action0 = TouchAction(self.driver).tap(x=515, y=1419)
        action0.release()
        action0.perform()
        self.driver.implicitly_wait(10)
        var = 1
        while var == 1:
            action1 = TouchAction(self.driver)
            action2 = TouchAction(self.driver)
            mul_action = MultiAction(self.driver)
            action1.tap(x=226, y=1677)
            action2.tap(x=824, y=1707)
            mul_action.add(action1, action2)
            mul_action.perform()
示例#3
0
def get_widget_menu(driver,key='微件'):
    test = Action(driver)
    touchAction = TouchAction(driver)
    windows_height = test.get_windows_height()
    windows_width = test.get_windows_width()
    for x in range(4):
        if x == 0:
            xx = windows_width/3
            yy = windows_height/3
        elif x == 1:
            xx = windows_width / 3
            yy = windows_height * 2 / 3
        elif x == 2:
            xx = windows_width * 2 / 3
            yy = windows_height * 2 / 3
        else:
            xx = windows_width * 2 / 3
            yy = windows_height / 3
        touchAction.long_press(x=xx ,y=yy)
        time.sleep(2)
        touchAction.release().perform()
        time.sleep(0.3)
        tmp = test.find_list_byid(bubble_text,key)
        if tmp is not None:
            return tmp
    return None
示例#4
0
 def sudoku(self, draw_el, points: list, duration=200):
     """
     绘制九宫格
     :param duration: 滑动事件
     :param draw_el: 九宫格的绘制区域的元素
     :param points: 绘制的点列表的形式传入
     :return: None
     """
     app_action = TouchAction(self.driver)
     # rect能同时回获取元素的x、y、width、height,并以字典存储
     start_x = draw_el.rect['x']
     start_y = draw_el.rect['y']
     width = draw_el.rect['width']
     height = draw_el.rect['height']
     # 设置点的坐标位置
     static_point = [
         {'x': start_x + width * 1 / 6, 'y': start_y + height * 1 / 6},
         {'x': start_x + width * 3 / 6, 'y': start_y + height * 1 / 6},
         {'x': start_x + width * 5 / 6, 'y': start_y + height * 1 / 6},
         {'x': start_x + width * 1 / 6, 'y': start_y + height * 3 / 6},
         {'x': start_x + width * 3 / 6, 'y': start_y + height * 3 / 6},
         {'x': start_x + width * 5 / 6, 'y': start_y + height * 3 / 6},
         {'x': start_x + width * 1 / 6, 'y': start_y + height * 5 / 6},
         {'x': start_x + width * 3 / 6, 'y': start_y + height * 5 / 6},
         {'x': start_x + width * 5 / 6, 'y': start_y + height * 5 / 6}
     ]
     app_action.press(**static_point[points[0]-1]).wait(duration)
     for p in points[1:]:
         app_action.move_to(**static_point[p - 1]).wait(duration)
     app_action.release().perform()
示例#5
0
def move(base, to):
    action = TouchAction(driver)
    action.press(**base)
    action.move_to(**to)
    action.wait(10)
    action.release()
    action.perform()
示例#6
0
    def paste(self, locator):
        """
        Paste into a locator
        :param locator:
        :return:
        """
        if self.is_android():
            touch_action = TouchAction(self.driver)

            locator.tap()

            touch_action.press(el=locator.element)
            touch_action.perform()

            sleep(3)

            touch_action.release()
            touch_action.perform()

            self.driver.keyevent(keycode=279)
            self.driver.keyevent(keycode=111)

        else:
            self.btn_paste = SlickMobileLocator("paste button", Find.by_name("Paste"))
            self.btn_select_all = SlickMobileLocator("select all button", Find.by_name("Select All"))

            locator.tap()
            locator.element.clear()

            if not self.btn_paste.exists():
                locator.tap()

            self.btn_paste.tap()
示例#7
0
    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)
示例#8
0
def test_scroll_down(driver):
    screen = driver.get_window_size()
    action = TouchAction(driver)
    action.press(x=screen['width'] / 2, y=screen['height'] / 2)
    action.move_to(x=0, y=screen['height'] / 10)
    action.release()
    action.perform()
示例#9
0
 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 _swip_find_element_and_click(self,method,message,element):
     """
     自定义滑动查找元素并点击
     :param method:
     :param message:
     :return:
     """
     self._driver.implicitly_wait(2)
     while True:
         ss = False
         try:
             element = self._find_element(method=method, message=message,element=element)
             element.click()
             ss = True
             config.case_log.info(f'swip_find_element_and_click element success (method={method},message={message})')
         except:
             pass
         if ss:
             break
         w_size = self._driver.get_window_size()
         w_x = w_size['width']
         w_y = w_size['height']
         x = int(w_x) / 2
         y1 = int(w_y) * 0.8
         y2 = int(w_y) * 0.2
         action = TouchAction(self._driver)
         action.press(x=int(x),y=int(y1))
         action.move_to(x=int(x),y=int(y2))
         action.release()
         action.perform()
     return
 def swipe(self, ini_pos_x, ini_pos_y, final_pos_x, final_pos_y,
           milliseconds):
     actions = TouchAction(self.driver)
     actions.press(x=ini_pos_x, y=ini_pos_y)
     actions.wait(milliseconds)
     actions.move_to(x=final_pos_x, y=final_pos_y)
     actions.release().perform()
 def drag_and_drop_element(self, element, final_pos_x, final_pos_y,
                           milliseconds):
     actions = TouchAction(self.driver)
     actions.long_press(element)
     actions.wait(milliseconds)
     actions.move_to(x=final_pos_x, y=final_pos_y)
     actions.release().perform()
示例#13
0
 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()
示例#14
0
 def long_tap(self, x=0, y=0, wait_time=1):
     """long tap element"""
     logger.info("Tap positions x: %s, y: %s ..." % (x, y))
     action = TouchAction(self.driver)
     action.long_press(None, x, y).perform()
     time.sleep(wait_time)
     action.release().perform()
 def zh_login(self, wechat_list):
     self.driver.implicitly_wait(5)
     if self.driver.find_elements_by_name(self.element_json['allow'])!=[]:
         self.driver.find_element_by_name(self.element_json['allow']).click()
         self.driver.find_element_by_name(self.element_json['allow']).click()
     self.driver.implicitly_wait(30)
     self.driver.find_element_by_name(self.element_json['login']).click()
     self.driver.find_element_by_id(self.element_json[u'输入框ID']).click()
     os.system('adb -s %s shell input text %s' % (self.deviceid, wechat_list[0]))
     self.visualization('输入账号')
     logging.info(self.deviceid + u'-输入账号')
     self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click()
     self.visualization('下一步')
     logging.info(self.deviceid + u'-下一步')
     self.driver.find_elements_by_id(self.element_json[u'输入框ID'])[1].click()
     os.system('adb -s %s shell input text %s' % (self.deviceid, wechat_list[1]))
     self.visualization('输入密码')
     logging.info(self.deviceid + u'-输入密码')
     self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click()
     self.visualization('登录')
     logging.info(self.deviceid + u'-登录')
     self.driver.implicitly_wait(2)
     while True:
         if self.driver.find_elements_by_id(self.element_json[u'错误弹窗内容ID'])!=[]:
             self.cw = self.driver.find_element_by_id(self.element_json[u'错误弹窗内容ID']).get_attribute(('text'))
             return self.error_message()
         if self.driver.find_elements_by_id(self.element_json[u'微信四个主按钮ID']) != []:
             break
         if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("拖动下方滑块完成拼图")') != []:
             logging.info(u'%s-进入滑图页面'%self.deviceid)
             while True:
                 for j in range(100, 200, 30):
                     try:
                         a = TouchAction(self.driver)
                         a.press(x=250, y=1000)
                         for i in range(0, 5):
                             a.move_to(x=50, y=(random.randint(-500, 0))).wait(0)
                             a.move_to(x=50, y=(random.randint(0, 500))).wait(0)
                         for i in range(0, j / 10):
                             a.move_to(x=10, y=0).wait(100)
                         a.release().perform()
                     except:pass
                 if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("开始验证 ")') != []:
                     file().write('%s\n' % wechat_list[0], '新设备记录文本.txt')
                     logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0]))
                     self.driver.quit()
                     break
                 if self.driver.find_elements_by_id(self.element_json[u'输入手机号码登陆下一步']) != []:
                     self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click()
                     break
                 if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("声音锁验证 ")') != []:
                     file().write('%s\n' % wechat_list[0], '新设备记录文本.txt')
                     logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0]))
                     self.driver.quit()
                     break
         if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("开始验证 ")') != []:
             file().write('%s\n' % wechat_list[0], '新设备记录文本.txt')
             logging.info(u'%s-%s该账号出现新设备'%(self.deviceid,wechat_list[0]))
             self.driver.quit()
             break
示例#16
0
    def swipe(self):
        driver = self.driver

        screen = TouchAction(driver)
        screen.press(x=855, y=514)
        screen.move_to(x=-709, y=-15)
        screen.release().perform()
示例#17
0
    def case_new_and_change_folder(self):
        self.case_if_base()
        self.test.find_byacc(Menu).click()
        time.sleep(0.2)
        tmp_list = self.test.find_byid_list(doc_action_menu)
        for x in tmp_list:
            t = x.text
            if '新建文件夹' in t:
                x.click()
                time.sleep(0.5)
                break
        tmp_list = self.test.find_list_byclass(Edit_Text)
        if tmp_list is None:
            self.Case.fail('文件夹名称输入框不存在')
        tmp_list[0].clear()
        tmp_list[0].send_keys(f'doc_new_{self.new_name}')
        tmp_list = self.test.find_byclass(Button, '确定').click()
        time.sleep(0.3)
        tmp_list = self.test.find_byid_list(ID_title)
        isNew = False
        touchAction = TouchAction(self.driver)
        for y in tmp_list:
            t = y.text
            if f'doc_new_{self.new_name}' in t:
                isNew = True
                touchAction.long_press(y)
                time.sleep(1.5)
                touchAction.release().perform()
                break
        if not isNew:
            self.Case.fail(f'文件夹不存在:[doc_new_{self.new_name}]')

        self.test.find_byacc(Menu).click()
        time.sleep(0.2)
        tmp_list = self.test.find_byid_list(doc_action_menu)
        for x in tmp_list:
            t = x.text
            if '重命名' in t:
                x.click()
                time.sleep(0.5)
                break
        tmp_list = self.test.find_list_byclass(Edit_Text)
        if tmp_list is None:
            self.Case.fail('文件夹名称输入框不存在')

        tmp_list[0].clear()
        tmp_list[0].send_keys(f'doc_old_{self.new_name}')
        tmp_list = self.test.find_byclass(Button, '确定').click()
        time.sleep(0.3)
        tmp_list = self.test.find_byid_list(ID_title)
        isNew = False
        for y in tmp_list:
            t = y.text
            if f'doc_old_{self.new_name}' in t:
                isNew = True
                break
        if not isNew:
            self.Case.fail(f'文件夹不存在:[doc_old_{self.new_name}]')
        time.sleep(1)
示例#18
0
 def _replay_muisc_skip(self):
     progress_loc = self.test.find_byid(music_video_music_detail_progress)
     loc = progress_loc.location
     actions = TouchAction(self.driver)
     actions.long_press(x=(self.test.get_windows_height() * 0.3),
                        y=loc['y'])
     actions.move_to(x=(self.test.get_windows_width() * 0.98), y=loc['y'])
     actions.release().perform()
示例#19
0
 def swipe_screen(self, pressX, pressY, MoveX, MoveY):
     screen = TouchAction(self.driver)
     screen.press(x=int(pressX), y=int(pressY))
     screen.move_to(x=int(MoveX), y=int(MoveY))
     screen.release().perform()
     time.sleep(2)
     print("Se hizo Swipe: " + " x:" + pressX + " Y" + pressY + " MoveX:" +
           MoveX + " MoveY:" + MoveY)
示例#20
0
 def dragdrop(self, px1, px2, py1, py2):
     x1, y1, x2, y2 = self.calc_percent_to_coords(px1, px2, py1, py2)
     actions = TouchAction(self.driver)
     actions.press(None, x1, y1)
     actions.move_to(None, x2, y2)
     actions.release()
     actions.perform()
     return True
示例#21
0
 def swipe(self, x1, y1, x2, y2):
     swipe = TouchAction(self.driver)
     swipe.press(x=x1, y=y1)
     time.sleep(.5)
     swipe.move_to(x=x2, y=y2)
     time.sleep(.5)
     swipe.release()
     swipe.perform()
示例#22
0
 def _swipe_from_coordinates(self, x1, y1, x2, y2, num_loops, wait_time):
     for i in range(num_loops):
         action = TouchAction(self.driver)
         action.press(x=x1, y=y1)
         action.wait(wait_time)
         action.move_to(x=x2, y=y2)
         action.release()
         action.perform()
     self._take_screenshot_click()
示例#23
0
def drag_name_to_coords(context, name, coords):
    coords = eval(coords)
    el = find_device_element_by_name_or_id(context, name)
    assert el, u'Element not found'
    action = TouchAction(context.device)
    action.press(el)
    for pair in coords:
        action.move_to(x=pair[0], y=pair[1])
    action.release()
    action.perform()
示例#24
0
def drag_name_to_coords(context, name, coords):
    coords = eval(coords)
    el = find_device_element_by_name_or_id(context, name)
    assert el, u'Element not found'
    action = TouchAction(context.device)
    action.press(el)
    for pair in coords:
        action.move_to(x=pair[0], y=pair[1])
    action.release()
    action.perform()
示例#25
0
def drag_drop(locator, position_origin, position_target):
    appiumLib = BuiltIn().get_library_instance('AppiumLibrary')
    driver = appiumLib._current_application()
    element_origin = driver.find_elements_by_id(locator)[int(position_origin)]
    element_target = driver.find_elements_by_id(locator)[int(position_target)]

    actions = TouchAction(driver)
    actions.long_press(element_origin).move_to(element_target)
    actions.release()
    actions.perform()
示例#26
0
 def scroll_down(self):
     screen = self.driver.get_window_size()
     try:
         action = TouchAction(self.driver)
         action.press(x=screen['width'] / 2, y=screen['height'] / 2)
         action.move_to(x=0, y=screen['height'] / 10)
         action.release()
         action.perform()
     except Exception as e:
         logger.error('向下滑动屏幕失败:{}'.format(e))
示例#27
0
    def case_del_music(self):
        self.case_if_base()
        self.test.find_byacc(doc_root_menu).click()
        time.sleep(0.2)
        tmp_list = self.test.find_byid_list(ID_title)
        for x in tmp_list:
            t = x.text
            if '音频' in t:
                x.click()
                time.sleep(0.5)
                break

        tmp_list = self.test.find_byid_list(ID_title)
        touchAction = TouchAction(self.driver)
        isNew = False
        for y in tmp_list:
            t = y.text
            if f'张含韵' in t:
                isNew = True
                y.click()
                time.sleep(1)
                break
        if not isNew:
            self.Case.fail(f"未找到相关歌曲文件: 张含韵")

        tmp_list = self.test.find_byid_list(ID_title)
        for z in tmp_list:
            t = z.text
            if f'歌曲' in t:
                z.click()
                time.sleep(1)
                break

        tmp_list = self.test.find_byid_list(ID_title)
        for g in tmp_list:
            t = g.text
            if f'doc_music' in t:
                touchAction.long_press(g)
                time.sleep(1.5)
                touchAction.release().perform()
                break
        time.sleep(0.5)

        self.test.find_byid(doc_search_and_del).click()
        time.sleep(0.3)
        self.test.find_byclass(Button, '确定').click()
        time.sleep(1)
        tmp_list = self.test.find_byid_list(ID_title)
        if tmp_list is None:
            return
        for d in tmp_list:
            t = d.text
            if 'doc_music' in t:
                self.Case.fail(f'张含韵 music ,未删除')
        time.sleep(1)
示例#28
0
    def drag(self, start_x, start_y, end_x, end_y, duration=None, speed=1000):
        """
        Performs a drag from one coordinate to another using duration or speed to control
        the speed.

        The coordinates x, y can have unit suffix to represent device independent dimension.
        Example::
            x = 100 # Means x = 100 pixel coordinate in current window.
            x = '100px' # The same as x = 100.
            x = '100dp' # Means x = 100 * dpi_scale, a device independent coordinate.
            x = '10%w' # Means x = 0.1 * display_width, percent position relative to device width.
            x = '10%h' # Means x = 0.1 * display_height, percent position relative to device height.

        When using drag('10%', '10%', '20%', '20%') will add w,h suffix automatically. Like::
            drag('10%w', '10%h', '20%w', '20%h')

        You can specified duration or speed to control the swiping speed. When specified both
        this method will ignore speed argument.

        :param start_x: start coordinate
        :param start_y: start coordinate
        :param end_x: end coordinate
        :param end_y: end coordinate
        :param duration: The duration for the dragging in millisecond.
        :param speed: The speed of dragging in pixels/second, ignored when duration is not None.
        """
        start_x_px = self._pixel(start_x, 'x')
        start_y_px = self._pixel(start_y, 'y')
        end_x_px = self._pixel(end_x, 'x')
        end_y_px = self._pixel(end_y, 'y')
        speed_px = self._pixel(speed)

        diff_x = end_x_px - start_x_px
        diff_y = end_y_px - start_y_px
        dist = math.sqrt(diff_x * diff_x + diff_y * diff_y)

        dur = 0
        if speed_px is not None and speed_px > 0:
            dur = dist / speed_px * 1000.0

        if duration is not None:
            dur = duration

        if dur <= 0:
            raise Exception("Drag with negative duration: %s" % dur)

        action = TouchAction(self._driver)
        action.long_press(None, start_x_px, start_y_px)
        frame_time = 16.667
        steps = dur // frame_time
        for i in range(int(steps)):
            action.move_to(None, diff_x / steps, diff_y / steps)
        action.release().perform()
        time.sleep(self._wait_time)
        return self
示例#29
0
def drag_drop(id, origen, destino):
    appiumLib = BuiltIn().get_library_instance('AppiumLibrary')
    driver = appiumLib._current_application()

    ele_origem = driver.find_elements_by_id(id)[int(origen)]
    ele_destino = driver.find_elements_by_id(id)[int(destino)]

    acao = TouchAction(driver)
    acao.long_press(ele_origem).move_to(ele_destino)
    acao.release()
    acao.perform()
示例#30
0
 def touch_scroll_up(self):
     """ Scroll up using touch actions """
     win_size = self.driver.get_window_size()
     x_middle = int(win_size['width'] * 0.5)
     y_bottom = int(win_size['height'] * 0.8)
     y_top = int(win_size['height'] * 0.2)
     touch_chain = TouchAction(self.driver)
     touch_chain.press(x=x_middle, y=y_bottom)
     touch_chain.move_to(x=x_middle, y=y_top)
     touch_chain.release()
     touch_chain.perform()
示例#31
0
    def jiugongge(self, e, points, duration=200):
        '''九宫格解锁'''
        # [1, 3, 4, 6, 9]
        action = TouchAction(self.driver)

        start_x = e.rect['x']
        start_y = e.rect['y']
        width = e.rect['width']
        height = e.rect['height']

        static_points = [
            {
                "x": start_x + width * 1 / 6,
                "y": start_y + height * 1 / 6
            },
            {
                "x": start_x + width * 3 / 6,
                "y": start_y + height * 1 / 6
            },
            {
                "x": start_x + width * 5 / 6,
                "y": start_y + height * 1 / 6
            },
            {
                "x": start_x + width * 1 / 6,
                "y": start_y + height * 3 / 6
            },
            {
                "x": start_x + width * 3 / 6,
                "y": start_y + height * 3 / 6
            },
            {
                "x": start_x + width * 5 / 6,
                "y": start_y + height * 3 / 6
            },
            {
                "x": start_x + width * 1 / 6,
                "y": start_y + height * 5 / 6
            },
            {
                "x": start_x + width * 3 / 6,
                "y": start_y + height * 5 / 6
            },
            {
                "x": start_x + width * 5 / 6,
                "y": start_y + height * 5 / 6
            },
        ]
        action.press(**static_points[points[0] - 1]).wait(duration)
        for point in points[1:]:
            action.move_to(**static_points[point - 1]).wait(duration)
        action.release().perform()
示例#32
0
def scrolldownsmall_quick():
    windowSize = driver.get_window_size()
    w = windowSize['width']
    h = windowSize['height']

    actions = TouchAction(driver)
    actions.long_press(x=w / 2, y=h * 4 / 5)
    actions.wait(300)
    actions.move_to(x=w / 2, y=h * 1 / 5)
    actions.release()
    actions.perform()
    print('scrolldownsmall_quick')
    sleep(1)
示例#33
0
def drag_and_drop(self, source, target, delay=1500):
    """Drags the element found with the locator ``source`` to the element found with the
    locator ``target``.

    ``Delay`` (iOS Only): Delay between initial button press and dragging, defaults to 1500ms."""
    source_element = self._element_find(source, True, True)
    target_element = self._element_find(target, True, True)
    zoomba.log('Dragging source element "%s" to target element "%s".' %
               (source, target))
    actions = TouchAction(self._current_application())
    self._platform_dependant_press(actions, source_element, delay)
    actions.move_to(target_element)
    actions.release().perform()
示例#34
0
    def test_smiley_face(self):
        # just for the fun of it.
        # this doesn't really assert anything.
        self.driver.find_element_by_accessibility_id('Graphics').click()

        els = self.driver.find_elements_by_class_name('android.widget.TextView')
        self.driver.scroll(els[len(els)-1], els[0])

        el = None
        try:
            el = self.driver.find_element_by_accessibility_id('Touch Paint')
        except Exception as e:
            els = self.driver.find_elements_by_class_name('android.widget.TextView')
            self.driver.scroll(els[len(els)-1], els[0])

        if el is None:
            el = self.driver.find_element_by_accessibility_id('Touch Paint')

        el.click()

        # paint
        e1 = TouchAction()
        e1.press(x=150, y=100).release()

        e2 = TouchAction()
        e2.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(e1, e2, smile)
        ma.perform()

        # so you can see it
        sleep(10)
    def test_scroll(self):
        sleep(2)
        els = self.driver.find_element_by_class_name('android.widget.ImageButton')
        els.click()
        sleep(10)
        
        
        
        #btn = self.driver.find_element_by_class_name('android.webkit.WebView')
        #btn.click()


        #
        selfview = self.driver.contexts[0]
        webview = self.driver.contexts[1]
        print ('>>%s<<' % webview)
        #contexts = self.driver.contexts

        self.driver.switch_to.context(webview)
        self.driver.get("http://m.nike.com/us/en_us/pd/air-zoom-pegasus-32-running-shoe/pid-10294427/pgid-10266840")

        sleep(10)

        print ('>>%s<<' % selfview)
        self.driver.switch_to.context(selfview)
        



        print ('Now trying TouchAction')
        e1 = TouchAction()
        e1.press(x=150, y=100).release()

        e2 = TouchAction()
        e2.press(x=250, y=100).release()


        smile = TouchAction()
        smile.press(x=400, y=800) \
            .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(e1,e2,smile)
        ma.perform()
        sleep(10)
    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 test_scroll(self):
        sleep(2)
        els = self.driver.find_element_by_class_name('android.widget.ImageButton')
        els.click()
        sleep(10)
        
        
        
        btn = self.driver.find_element_by_class_name('android.webkit.WebView')
        btn.click()


        sleep(10)

        webview = self.driver.contexts
        print ('>>%s<<' % len(webview))
        contexts = self.driver.contexts
        self.driver.switch_to.context('WEBVIEW')

        e1 = TouchAction()
        e1.press(x=150, y=100).release()

        e2 = TouchAction()
        e2.press(x=250, y=100).release()


        smile = TouchAction()
        smile.press(x=400, y=800) \
            .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(e1,e2,smile)
        ma.perform()
        sleep(10)
    def test_find_elements(self):
        # pause a moment, so xml generation can occur
        sleep(2)

        self.driver.get("http://m.nike.com/us/en_us/pd/air-zoom-pegasus-32-running-shoe/pid-10294427/pgid-10266840")
        #els = self.driver.find_elements_by_xpath('//android.widget.TextView')
        #Eself.assertEqual('API Demos', els[0].text)

        #el = self.driver.find_element_by_xpath('//android.widget.TextView[contains(@text, "Animat")]')
        #self.assertEqual('Animation', el.text)

        #el = self.driver.find_element_by_accessibility_id("App")
        #el.click()

        #els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')
        # there are more, but at least 10 visible
        #self.assertLess(10, len(els))
        # the list includes 2 before the main visible elements
        #self.assertEqual('Action Bar', els[2].text)

        #els = self.driver.find_elements_by_xpath('//android.widget.TextView')
        #self.assertLess(10, len(els))
        #self.assertEqual('Action Bar', els[1].text)
        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(smile)
        ma.perform()

        # so you can see it
        sleep(10)
示例#39
-1
	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
 def zh_login(self, wechat_list):
     self.driver.implicitly_wait(5)
     if self.driver.find_elements_by_name(self.element_json['allow']) != []:
         self.driver.find_element_by_name(self.element_json['allow']).click()
         self.driver.find_element_by_name(self.element_json['allow']).click()
     self.driver.implicitly_wait(30)
     self.driver.find_element_by_name(self.element_json['login']).click()
     self.driver.find_element_by_id(self.element_json[u'输入框ID']).click()
     os.system('adb -s %s shell input text %s' % (self.deviceid, wechat_list[0]))
     self.visualization('输入账号')
     logging.info(self.deviceid + u'-输入账号')
     self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click()
     self.visualization('下一步')
     logging.info(self.deviceid + u'-下一步')
     self.driver.find_elements_by_id(self.element_json[u'输入框ID'])[1].click()
     os.system('adb -s %s shell input text %s' % (self.deviceid, wechat_list[1]))
     self.visualization('输入密码')
     logging.info(self.deviceid + u'-输入密码')
     self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click()
     self.visualization('登录')
     logging.info(self.deviceid + u'-登录')
     self.driver.implicitly_wait(2)
     while True:
         if self.driver.find_elements_by_id(self.element_json[u'错误弹窗内容ID']) != []:
             self.cw = self.driver.find_element_by_id(self.element_json[u'错误弹窗内容ID']).get_attribute(('text'))
             return self.error_message()
         if self.driver.find_elements_by_id(self.element_json[u'微信四个主按钮ID']) != []:
             break
         if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("拖动下方滑块完成拼图")') != []:
             logging.info(u'%s-进入滑图页面' % self.deviceid)
             while True:
                 for j in range(100, 200, 30):
                     try:
                         a = TouchAction(self.driver)
                         a.press(x=250, y=1000)
                         for i in range(0, 5):
                             a.move_to(x=50, y=(random.randint(-500, 0))).wait(0)
                             a.move_to(x=50, y=(random.randint(0, 500))).wait(0)
                         for i in range(0, j / 10):
                             a.move_to(x=10, y=0).wait(100)
                         a.release().perform()
                     except:
                         pass
                 if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("开始验证 ")') != []:
                     file().write('%s\n' % wechat_list[0], '新设备记录文本.txt')
                     logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0]))
                     self.driver.quit()
                     break
                 if self.driver.find_elements_by_id(self.element_json[u'输入手机号码登陆下一步']) != []:
                     self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click()
                     break
                 if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("声音锁验证 ")') != []:
                     file().write('%s\n' % wechat_list[0], '新设备记录文本.txt')
                     logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0]))
                     self.driver.quit()
                     break
         if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("开始验证 ")') != []:
             file().write('%s\n' % wechat_list[0], '新设备记录文本.txt')
             logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0]))
             self.driver.quit()
             break