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()
示例#3
0
def move(base, to):
    action = TouchAction(driver)
    action.press(**base)
    action.move_to(**to)
    action.wait(10)
    action.release()
    action.perform()
示例#4
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()
示例#5
0
def pinch_or_zoom(driver, action):
    """
    Zoom or Pinch the maximum
    :param driver: Appium driver
    :param action: String Type. Value can be 'zoom' or 'pinch'
    :return:
    """

    # Get Mid point of the screen
    width_mid_pnt, height_mid_pnt = get_screen_mid_points(driver)

    # Variables
    finger1 = TouchAction()
    finger2 = TouchAction()
    multi_touch_action = MultiAction(driver)

    # Zoom
    if action is "zoom":
        LOGGER.info("Start zoom")

        finger1.press(None, width_mid_pnt, height_mid_pnt)
        finger1.move_to(None, width_mid_pnt, height_mid_pnt+200)
        finger1.release()

        # Note: Between the press and move one has to introduce delay as only then the element responds to multiperform
        finger2.press(None, width_mid_pnt, height_mid_pnt-10)
        finger2.wait(100)
        finger2.move_to(None, width_mid_pnt, 60)
        finger2.release()

        LOGGER.info("Zoom screen")

    # Pinch
    elif action is "pinch":
        LOGGER.info("Start pinch")

        finger1.press(None, width_mid_pnt, int(height_mid_pnt*2*.75))
        finger1.move_to(None, width_mid_pnt, height_mid_pnt+5)
        finger1.release()

        # Note: Between the press and move one has to introduce delay as only then the element responds to multiperform
        finger2.press(None, width_mid_pnt, int(height_mid_pnt*.25))
        finger2.wait(100)
        finger2.move_to(None, width_mid_pnt, height_mid_pnt-5)
        finger2.release()

        LOGGER.info("Pinch screen")

    # Throw error
    else:
        sys.exit("Incorrect action value! Action can be 'zoom' or 'pinch'")

    multi_touch_action.add(finger1, finger2)
    multi_touch_action.perform()
示例#6
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)
示例#7
0
def scrolldownpage():
    windowSize = driver.get_window_size()
    w = windowSize['width']
    h = windowSize['height']

    actions = TouchAction(driver)
    actions.press(x=w / 2, y=h * 8 / 10)
    actions.wait(3000)
    actions.move_to(x=w / 2, y=0)
    actions.wait(1000)
    actions.release()
    actions.perform()
    print('scrolldownpage')
    sleep(1)
示例#8
0
def unlock(driver,passwd):
    #driver = get_driver()      #实例化get_driver方法并赋值给driver
    ta = TouchAction(driver)
    driver.swipe(200, 500, 200, 200, 200)  # 向上滑动,弹出九宫格
    time.sleep(2)
    p = [[232, 956], [445, 956], [661, 956],  # 将九个点的坐标写上,并封装成一个列表
        [232, 1174], [445, 1174], [661, 1174],
        [232, 1392], [445, 1392], [661, 1392]]
    ta.press(x=p[passwd[0]][0], y=p[passwd[0]][1])  # 通过索引找到第一个点按压
    ta.wait(1000)
    for n in passwd[1:]:  # 通过循环取值
        ta.move_to(x=p[n][0], y=p[n][1])
    ta.release()  # 释放
    ta.perform()  # 提交
示例#9
0
def unlock(password):
    # driver=tenxunxinwen()
    action = TouchAction(tenxunxinwen())
    p=[
            [230,960],[450,960],[660,960],
           [230,1180],[450,1180],[660,1180],
           [230,1390],[450,1390],[660,1390]
        ]
    # password=[1,2,3,5,7,8,9]
    #按住第一个键
    action.press(x=p[password[0]-1][0],y=p[password[0]-1][1])
    #移动
    for i in password[1:]:
        action.move_to(x=p[i-1][0],y=p[i-1][1])
        action.wait(500)
    action.release()
    # 提交
    action.perform()
示例#10
0
def L_unlock(driver):
    jiu = 'com.asiainfo.wcs:id/lockPatternView'
    local = driver.find_element_by_id(jiu).location
    size = driver.find_element_by_id(jiu).size
    x = local["x"]
    y = local["y"]  # 元素的宽和高
    width = size["width"]
    height = size["height"]
    print(x, y, width / 3, height / 3)
    num1x = x + width / 6
    num1y = y + height / 6
    unlock1 = TouchAction(driver).press(None, num1x, num1y).wait(200).move_to(
        None, num1x, num1y + width / 3).wait(200).move_to(
            None, num1x, num1y + width * 2 / 3).wait(200).move_to(
                None, num1x + height / 3,
                num1y + width * 2 / 3).wait(200).move_to(
                    None, num1x + height * 2 / 3,
                    num1y + width * 2 / 3).wait(200).release()
    unlock1.wait(200).perform()
    def testTouchActions(self):
        self.driver.implicitly_wait(30)
        
        self.driver.find_element_by_id("io.selendroid.testapp:id/touchTest").click()
        self.driver.find_element_by_id("io.selendroid.testapp:id/canvas_button").click()
		
        el = self.driver.find_element_by_id("io.selendroid.testapp:id/finger_view")
		
        actions = TouchAction(self.driver)
        actions.press(el, 300, 500)
        actions.move_to(el, 300, 800)
        actions.move_to(el, 600, 800)
        actions.move_to(el, 600, 500)
        actions.move_to(el, 300, 500)
        actions.move_to(el, 450, 300)
        actions.move_to(el, 750, 300)
        actions.move_to(el, 750, 600)
        actions.move_to(el, 600, 800)
        actions.move_to(el, 600, 500)
        actions.move_to(el, 750, 300)
        actions.wait(10000)
        actions.release()
        actions.perform()
示例#12
0
文件: tp_app.py 项目: chinapnr/agbot
    def _do_execute(self, driver, actions):
        touch_action = TouchAction(driver)
        for action in actions:
            a = getattr(touch_action, action['action'])
            if action['action'] == 'wait':
                touch_action.wait(action['ms'])
            else:
                el = self._find_element(driver, action)
                a(el)
        if len(actions) > 0:
            touch_action.perform()

        inspect_elements = self.tp_conf.get('inspect_elements')
        if inspect_elements is not None:
            for ie in inspect_elements:
                ele = self._find_element(driver, ie)
                if ele is not None:
                    attr = ele.get_attribute(ie['attr'])
                else:
                    attr = None
                self._inspect_results[ie['alias']] = attr

        return self._inspect_results, ''
示例#13
0
    def manage_notification_center(self, show):
        yMargin = 5
        xMid = self.driver.get_window_size()['width'] / 2

        print(xMid)

        top = Point(xMid, yMargin)
        bottom = Point(xMid, self.driver.get_window_size()['height'] - yMargin)

        action = TouchAction(self.driver)

        if show:
            action.press(None, top.x, top.y)
        else:
            action.press(None, bottom.x, bottom.y)

        action.wait(1000)

        if show:
            action.move_to(None, bottom.x, bottom.y)
        else:
            action.move_to(None, top.x, bottom.y)

        action.perform()
# Test for developer to check found element with expected elements in activity
assert developer_list == found_list, "TestError: Found List Doesn't Match Application List"


# Testing elements in the buttons class list
for elements_counting in found_list:
    i = 1
    found_list[i].click()

    try:
        check_shelf_result = driver.find_element_by_id('com.walmart.android:id/shelf_result_count')
        check_shelf_result.is_enabled()
        # call search function.. EditText Class.

        # Check Sort and Filter
        user_action.wait(6000)
        user_action.press(x=475, y=1062).move_to(x=475, y=491).release().perform()
        time.sleep(3)

        user_action.wait(3000)
        user_action.press(x=475, y=491).move_to(x=475, y=862).release().perform()
        time.sleep(6)
        driver.find_element_by_id('com.walmart.android:id/shelf_results_sort_filter').click()

        # Test a submenu function
        user_action.wait(3000)
        user_action.tap(x=1348, y=1052).perform()
        time.sleep(3)
        user_action.wait(3000)
        user_action.tap(x=558, y=1408).perform()
        time.sleep(3)
 def press_long_element(self, element: WebElement, milliseconds):
     actions = TouchAction(self.driver)
     actions.long_press(el=element)
     actions.wait(milliseconds)
     actions.release().perform()
 def press_long_position(self, pos_x, pos_y, milliseconds):
     actions = TouchAction(self.driver)
     actions.long_press(x=pos_x, y=pos_y)
     actions.wait(milliseconds)
     actions.release().perform()
示例#17
0
        logger.error('garden take water error. maybe not find water bottle!')

    try_times = 3
    while True:
        try_times = try_times - 1
        if try_times == 0:
            break
        # 狂会场
        try:
            market = garden.find_element_by_xpath(
                '//android.view.View[8]/android.view.View[4]/android.widget.ImageView'
            )
            logger.info('goto market %s, %s', market.is_displayed(),
                        market.location)
            action.tap(market).perform()
            action.wait(2000)
            time.sleep(10)
            adb_shell('swipe 100 600 100 300')
            time.sleep(5)
            break
        except:
            logger.error('goto market error. maybe not jump market activity!')
            # 返回上一个页面 重新进入会场
            ad.press_keycode(4)
            time.sleep(5)
            action.tap(seed_bean_text).perform()
            time.sleep(5)

    #返回花园
    ad.press_keycode(4)
示例#18
0
'''九宫格解锁'''

#获取窗口大小
size = driver.get_window_size()
print('窗口大小:', size)

#先向上滑动
start_x = size['width'] * 0.5  #起点X坐标
start_y = size['height'] * 0.9  #起点y坐标
end_x = size['width'] * 0.5  #终点x坐标
end_y = size['height'] * 0.3  #终点y坐标
driver.swipe(start_x, start_y, end_x, end_y)  #向上滑动

#解锁
ta = TouchAction(driver)  #实例化类
time.sleep(3)  #等待3秒
#九宫格
a = [[200, 800], [360, 800], [520, 800], [195, 960], [360, 960], [520, 960],
     [195, 1120], [360, 1120], [520, 1120]]

ta.press(x=a[6][0], y=a[6][1])  #第一个点,按住
ta.wait(1000)  #操作过程中等待
all = [3, 0, 4, 8, 5, 2]  #其余六个点
for i in all:  #其余六个点循环
    ta.move_to(x=a[i][0], y=a[i][1])  # i为索引
    ta.wait(1000)

ta.release()  #释放
ta.perform()  #提交
time.sleep(3)
示例#19
0
# 多点触摸
from appium.webdriver.common.multi_action import MultiAction

x1, y1, x2, y2 = 100, y + 100, 300, y + 100
ac0 = TouchAction(driver).press(x=x1, y=y1).wait(10)
ac1 = TouchAction(driver).press(x=x2, y=y2).wait(10)
for i in range(5):
    y1 += 50
    ac0.move_to(x=x1, y=y1).wait(10)
    x1 += 50
    ac0.move_to(x=x1, y=y1).wait(10)
    y2 += 50
    ac1.move_to(x=x2, y=y2).wait(10)
    x2 += 50
    ac1.move_to(x=x2, y=y2).wait(10)
ac0.wait(2000).release()
ac1.wait(5000).release()

m = MultiAction(driver)
m.add(ac0, ac1)
m.perform()
# endregion

# region 手势
# 长按
ele = driver.find_element_by_id("long_press_button")
TouchAction(driver).long_press(ele).release().perform()

# 滑动
ele = driver.find_element_by_id("seekBar1")
x = ele.rect.get("x")
示例#20
0
driver = Remote(command_executor='http://127.0.0.1:4723/wd/hub',
                desired_capabilities=desired_cap,
                )
driver.implicitly_wait(15)
# 获取屏幕大小
size = driver.get_window_size()

# 点击题库
driver.find_element_by_id('com.lemon.lemonban:id/navigation_tiku').click()

time.sleep(2)
t1 = TouchAction(driver)

t1.press(x=size["width"] * 0.5, y=size["height"] * 0.8)
t1.wait(200)
t1.move_to(x=size["width"] * 0.5, y=size["height"] * 0.7)
t1.wait(200)
t1.move_to(x=size["width"] * 0.5, y=size["height"] * 0.6)
t1.wait(200)
t1.move_to(x=size["width"] * 0.5, y=size["height"] * 0.5)
t1.wait(200)
t1.release()
t1.perform()

# ---------链式调用------------
# t1.press(x=size["width"] * 0.5, y=size["height"] * 0.8).wait(200) \
#     .move_to(x=size["width"] * 0.5, y=size["height"] * 0.7).wait(200) \
#     .move_to(x=size["width"] * 0.5, y=size["height"] * 0.6).wait(200) \
#     .move_to(x=size["width"] * 0.5, y=size["height"] * 0.5).wait(200) \
#     .release().perform()
import unittest
import time

desired_cap = desired_Cap()

# Create Test Driver
driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_cap)
driver.implicitly_wait(30)
user_action = TouchAction(driver)
time.sleep(6)
search_button = driver.find_element_by_id('com.walmart.android:id/search_mag_icon')
element_class_edit_text = driver.find_elements_by_class_name("android.widget.EditText")
search_field = driver.find_element_by_id('com.walmart.android:id/search_src_text')

search_field.click()
user_action.wait(3000)
driver.set_value(search_field, "Lenovo Flex 14 16Gb")
driver.execute_script('mobile: performEditorAction', {'action': 'done'})

time.sleep(9)
item_price = driver.find_elements_by_id('com.walmart.android:id/shop_item_price')
item_price_1 = item_price[0].text
item_price_2 = item_price[1].text
item_price_3 = item_price[2].text
print(item_price_1, item_price_2)
time.sleep(6)
user_action.press(x=439, y=895).release().perform()
user_action.wait(5000)
TouchAction(driver).tap(x=439, y=895)
time.sleep(6)
compare_price = driver.find_element_by_id('com.walmart.android:id/price_view')