示例#1
0
    def MoveTo(cls):

        element = cls.__wait()
        action = TouchAction(p_env.MOBILE)
        action.move_to(element)
        action.perform()
        cls.__clearup()
示例#2
0
    def update_item(self, idx, name):
        try:
            elements = self.driver.find_elements(AppiumBy.ID, 'textView')
        except:
            print('ID textView인 위젯을 찾을 수 있음')
            return False

        if idx >= len(elements):
            return False

        actions = TouchAction(self.driver)
        actions.long_press(elements[idx])
        actions.perform()

        try:
            edit = self.driver.find_element(AppiumBy.XPATH, '//android.widget.TextView[@text="Edit"]')
            edit.click()
        except:
            print('Edit를 찾을 수 없음')
            return False

        try:
            ok = self.driver.find_element(AppiumBy.ID, 'buttonOK') # AppiumBy.XPATH, '//android.widget.Button[@text="OK"]')
            editText = self.driver.find_element(AppiumBy.ID, 'editTextName')
            editText.clear()
            editText.send_keys(name)
            ok.click()
            return True
        except:
            print('OK 버튼 또는 EditText를 찾을 수 없음')
            return False
    def test_delete_file(self):
        record_button = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.ID, "com.danielkim.soundrecorder:id/btnRecord")))
        record_button.click()

        stop_button = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.ID, "com.danielkim.soundrecorder:id/btnRecord")))
        stop_button.click()

        saved_recordings_button = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//android.widget.TextView[@text='SAVED RECORDINGS']")))
        saved_recordings_button.click()

        ## Check if there is a file present
        self.assertTrue(self.driver.find_elements_by_id('com.danielkim.soundrecorder:id/card_view'))

        actions = TouchAction(self.driver)
        actions.long_press(self.driver.find_element_by_xpath("//android.widget.FrameLayout[contains(@resource-id,'card_view')]"))
        actions.perform()

        delete_button = WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//android.widget.TextView[@text='Delete File']")))
        delete_button.click()

        confirm_yes_button =  WebDriverWait(self.driver, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//android.widget.Button[@text='YES']")))
        confirm_yes_button.click()

        ## Assert that there is more files here
        self.assertFalse(self.driver.find_elements_by_id('com.danielkim.soundrecorder:id/card_view'))
示例#4
0
    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
示例#5
0
    def tap(self, x, y, count=1):  # 点击
        time.sleep(1)
        logging.info('Tap')
        action = TouchAction(self.driver)

        action.tap(x=x, y=y, count=count)
        action.perform()
示例#6
0
	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
示例#7
0
 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()
示例#8
0
 def touch_long_press(self,
                      element,
                      xoffset=None,
                      yoffset=None,
                      duration_sconds=10,
                      is_perfrom=True):
     """
     触屏长按
     1、如果xoffset和yoffset都None,则在指定元素的正中间进行长按
     2、如果element、xoffset和yoffset都不为None,则根据元素的左上角做x和y的偏移然后进行长按
     :param element:
     :param xoffset:
     :param yoffset:
     :param duration_sconds: 长按秒数
     :param is_perfrom 是否马上执行动作,不执行可以返回动作给多点触控执行
     :return:
     """
     webElement = self._change_element_to_webElement_type(element)
     if webElement:
         actions = TouchAction(self._driver)
         actions.long_press(webElement, xoffset, yoffset,
                            duration_sconds * 1000)
         if is_perfrom:
             actions.perform()
         return actions
示例#9
0
    def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration: int = 0) -> T:
        """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: time to take the swipe, in ms.

        Usage:
            driver.swipe(100, 100, 100, 400)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        """
        # `swipe` is something like press-wait-move_to-release, which the server
        # will translate into the correct action
        action = TouchAction(self)
        action \
            .press(x=start_x, y=start_y) \
            .wait(ms=duration) \
            .move_to(x=end_x, y=end_y) \
            .release()
        action.perform()
        return self
示例#10
0
def move(base, to):
    action = TouchAction(driver)
    action.press(**base)
    action.move_to(**to)
    action.wait(10)
    action.release()
    action.perform()
 def test3(self):
     actions = TouchAction(self.driver)
     actions.tap(None, 90, 272, 1)
     actions.perform()
     sleep(3)
     self.driver.execute_script("mobile: scroll", {"direction": "down"})
     sleep(3)
示例#12
0
def login(username, password):
    actions = TouchAction(page().driver)
    actions.tap(page().debug_login_link())
    actions.perform()

    # page().debug_login_link().click()

    page().debug_username_input_box().send_keys(username)
    page().debug_password_input_box().send_keys(password)
    # page().debug_login_button().click()

    actions.tap(page().debug_login_button())
    actions.perform()

    # page().wait_for_activity('com.ef.core.engage.ui.screens.activity.OnBoardingActivity', WAITING_TIME)
    # time.sleep(10)
    # print(page().get_element('//android.widget.RelativeLayout/android.widget.TextView[2]').text)
    page().wait_for_text('//android.widget.RelativeLayout/android.widget.TextView[2]', '10 fundamental classes in 90 days.')
    # print(page().get_element('//android.widget.RelativeLayout/android.widget.TextView[2]').text)
    # time.sleep(10)
    page().driver.swipe(900, 1200, 200, 1200)
    page().wait_for_text('//android.widget.RelativeLayout/android.widget.TextView[2]',
                         'Online preview and review for each class.')
    # time.sleep(10)
    page().driver.swipe(900, 1200, 200, 1200)
    page().wait_for_text('//android.widget.RelativeLayout/android.widget.TextView[2]',
                         'Improve your English in 3 dimensions.')

    page().get_element('//androidx.viewpager.widget.ViewPager/android.widget.RelativeLayout/android.widget.Button').click()
    time.sleep(10)
 def test(self):
     element = self.driver.find_element_by_accessibility_id(
         'Google Account')
     actions = TouchAction(self.driver)
     actions.tap(element)
     actions.perform()
     sleep(3)
示例#14
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()
示例#15
0
    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
示例#16
0
 def swipe_to_element_visible(self, *locator, x1, y1, x2, y2, wait_time):
     """
     Swipe given coordinates until element is visible, try to swipe for maximum of 5 attempts
     :param locator: dict - element locator
     :param x1: int - x1 coordinate
     :param y1: int - y1 coordinate
     :param x2: int - x2 coordinate
     :param y2: int - y2 coordinate
     :param wait_time: int - time to pause in ms (longer time means slower swipe distance)
     :return: None
     """
     el_visible = False
     count = 0
     while el_visible is not True and count < 5:
         try:
             action = TouchAction(self.driver)
             action \
                 .press(x=x1, y=y1) \
                 .wait(ms=wait_time) \
                 .move_to(x=x2, y=y2) \
                 .release()
             action.perform()
             el_visible = self.is_element_visible(*locator, wait_time=2)
         except InvalidElementStateException:
             pass
         count += 1
示例#17
0
文件: base.py 项目: xiaoxiayu/XXUIA
 def tem1(self, x):
     print(x)
     action = TouchAction(self.driver)
     els = self.find_element_by_xpath('//XCUIElementTypeImage')
     action.move_to(els.ele, x=-150, y=0)
     action.perform()
     print('END1')
示例#18
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()
示例#19
0
 def swipe(self, points):
     automationName = self.driver.capabilities.get('automationName')
     last_x = 0
     last_y = 0
     if (automationName == 'Appium'):
         action_appium = TouchAction(self.driver)
         for i in range(0, len(points)):
             x = float(points[i][0]) * self.ratioX
             y = float(points[i][1]) * self.ratioY
             if (i == 0):
                 action_appium = action_appium.press(None, x, y).wait(200)
             elif (i == (len(points) - 1)):
                 action_appium = action_appium.move_to(None, x - last_x, y - last_y).wait(200).release()
                 action_appium.perform()
             else:
                 action_appium = action_appium.move_to(None, x - last_x, y - last_y).wait(200)
             last_x = x
             last_y = y
     else:
         action_selendroid = TouchActions(self.driver)
         for i in range(0, len(points)):
             x = float(points[i][0]) * self.ratioX
             y = float(points[i][1]) * self.ratioY
             if (i == 0):
                 action_selendroid.tap_and_hold(x, y)
             elif (i == (len(points) - 1)):
                 action_selendroid.move(x, y).release(x, y).perform()
             else:
                 action_selendroid.move(x, y)
示例#20
0
文件: base.py 项目: xiaoxiayu/XXUIA
 def tem0(self, x):
     print(x)
     action = TouchAction(self.driver)
     action \
         .long_press(x=self.s_w/2, y=self.s_h/2, duration=500)
     action.perform()
     print('END0')
示例#21
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()
示例#22
0
    def test_Play(self):
        log.starttestcase("Test case starts")

        el = self.driver.find_element_by_xpath(
            "//android.widget.RelativeLayout[@index= '0']")
        actions = TouchAction(self.driver)
        actions.tap(el)
        actions.perform()
        log.info("Video Started Playing")
        sleep(5)
        self.driver.save_screenshot(log.screenshotpath("video playback"))
        el = self.driver.find_element_by_xpath(
            "//hierarchy/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.widget.FrameLayout[1]/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.View"
        )
        actions = TouchAction(self.driver)
        actions.tap(el)
        actions.perform()
        log.info("Touch Perform")

        current_time = self.driver.find_element_by_id(
            "com.google.android.youtube:id/time_bar_current_time").text
        log.info("Video playback time")

        if "0.00" != current_time:

            log.info("playback time matches")

        else:
            log.info("Plackback time not matches")
            self.driver.save_screenshot(log.screenshotpath("Failed"))
            log.markTestfail("test case failed")
            self.skipTest("play back testcase failed")
示例#23
0
    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
示例#24
0
    def swipe(self, start_x, start_y, end_x, end_y, duration=None):
        """Swipe from one point to another point, for an optional duration.

        Args:
            start_x (int): x-coordinate at which to start
            start_y (int): y-coordinate at which to start
            end_x (int): x-coordinate at which to stop
            end_y (int): y-coordinate at which to stop
            duration (:obj:`int`, optional): time to take the swipe, in ms.

        Usage:
            driver.swipe(100, 100, 100, 400)

        Returns:
            `WebElement`
        """
        # `swipe` is something like press-wait-move_to-release, which the server
        # will translate into the correct action
        action = TouchAction(self)
        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 _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
示例#26
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()
示例#27
0
 def long_press(self, locator):
     """ Long press the element
     For mobile application testing only
     """
     driver = self._current_application()
     element = self.find_element(locator)
     long_press = TouchAction(driver).long_press(element)
     long_press.perform()
示例#28
0
 def select_about_option(self):
     element_to_press = self.app.find_element_by_xpath(self.SUPPORT_OPTION)
     element_to_move = self.app.find_element_by_xpath(self.GENERAL_OPTION)
     actions = TouchAction(self.app)
     actions.press(element_to_press)
     actions.move_to(element_to_move)
     actions.perform()
     self.app.find_element_by_xpath(self.ABOUT_OPTION).click()
示例#29
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
示例#30
0
	def click_point(self,x,y,duration=None):
		action = TouchAction(self)
		if duration:
			action.long_press(x=x, y=y, duration=duration).release()
		else:
			action.tap(x=x, y=y)
		action.perform()
		return self
示例#31
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()
示例#32
0
 def click_point(self, x, y, duration=None):
     action = TouchAction(self)
     if duration:
         action.long_press(x=x, y=y, duration=duration).release()
     else:
         action.tap(x=x, y=y)
     action.perform()
     return self
示例#33
0
 def element_double_tap(self, locator):
     try:
         actions = TouchAction(self.driver)
         actions.double_tap(self.find_element(locator))
         actions.perform()
         self.logger.info('元素双击成功:' + locator[0] + ':' + locator[1])
     except:
         self.logger.error('元素双击失败:' + locator[0] + ':' + locator[1])
         self.handle_exception()
示例#34
0
 def swipe(self, start_x, start_y, end_x, end_y, duration=None):
     action = TouchAction(self.driver)
     action \
         .press(x=start_x, y=start_y) \
         .wait(ms=duration) \
         .move_to(x=end_x, y=end_y) \
         .release()
     action.perform()
     return self
示例#35
0
	def click_point(self,x,y,duration=None):
		self.logger.log("[action]click_point(x=%s,y=%s,duration=%s)" %(x,y,duration))
		action = TouchAction(self)
		if duration:
			action.long_press(x=x, y=y, duration=duration).release()
		else:
			action.tap(x=x, y=y)
		action.perform()
		return self
示例#36
0
 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()
示例#37
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()
示例#38
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()
示例#39
0
def SwipeDown(driver):
    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']
    x1 = int(x * 0.5)
    y1 = int(y / 4)
    y2 = int(y * 3 / 4)
    action = TouchAction(driver)
    action.press(x=x1, y=y1).wait(ms=500).move_to(x=x1, y=y2).release()
    action.perform()
    pass
示例#40
0
 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)
示例#41
0
 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)
示例#42
0
 def swipe(self, start_x = None, start_y = None, end_x = None, end_y = None):
     # Swip from somewhere to somewhere
     if (start_x == None) | (start_y == None) | \
         (start_x > self.X) | (start_y > self.Y) | \
         (end_x == None) | (end_y == None) | \
         (end_x > self.X) | (end_y > self.Y):
             raise AssertionError('Please input a correct coordinate')
     action = TouchAction(self.driver)
     action\
         .press(x = start_x, y = start_y)\
         .wait()\
         .move_to(x = end_x, y = end_y)\
         .release()
     action.perform()
示例#43
0
    def flick(self, start_x, start_y, end_x, end_y):
        """Flick from one point to another point.

        :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

        :Usage:
            driver.flick(100, 100, 100, 400)
        """
        action = TouchAction(self)
        action.press(x=start_x, y=start_y).move_to(x=end_x, y=end_y).release()
        action.perform()
        return self
示例#44
0
    def swipe(self, start_x, start_y, end_x, end_y, 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
        action = TouchAction(self)
        action.press(x=start_x, y=start_y).wait(ms=duration).move_to(x=end_x, y=end_y).release()
        action.perform()
        return self
示例#45
0
    def swipe(self, direction=Directions.down, swipe_num=1, to_element=None):
        if type(direction) is not Enum and direction not in Directions:
            raise SwipeError("Unknown direction to swipe to")

        location = self.element.location
        size = self.element.size

        swipe_num = self._calculate_swipe_nums(size, direction, to_element) or swipe_num
        start_x, start_y, end_x, end_y = self._calculate_coordinates(location, size, direction)

        for num in range(swipe_num):
            action = TouchAction(self.driver)
            action \
                .press(x=start_x, y=start_y) \
                .wait(ms=self._swipe_duration) \
                .move_to(x=end_x, y=end_y) \
                .release()
            action.perform()
            sleep(self._swipe_pause)
示例#46
0
	def flick(self, begin, end):
		"""Flick from one point to another point.
		: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
		:Usage:
			driver.flick(100, 100, 100, 400)
		"""
		if self.autoAcceptAlert:
			self.allow_alert()
		start_x,start_y = begin
		end_x,end_y = end
		action = TouchAction(self)
		action \
			.press(x=start_x, y=start_y) \
			.move_to(x=end_x, y=end_y) \
			.release()
		action.perform()
		return self
示例#47
0
    def test_swipe(self):
        sleep(1)

        size = self.driver.get_window_size()
        width = size["width"]
        start_x = int(width/2)
        start_y = int(size["height"]/2)

        sleep(.5)
        el = self.has_card()
        while el is not None:

            swipe_x = width-10
            if random.random() > 0.5:
                swipe_x = 10

            action = TouchAction(self.driver)
            action.press(x=start_x, y=start_y).wait(300).move_to(x=swipe_x,y=start_y).release()
            action.perform()
            sleep(.5)

            el = self.has_card()
            sleep(.5)
示例#48
0
 def long_press(self, locator, duration=1000):
     """ Long press the element with optional duration """
     driver = self._current_application()
     element = self._element_find(locator, True, True)
     long_press = TouchAction(driver).long_press(element, duration)
     long_press.perform()
示例#49
0
def my_longpress(d, element):
    action1 = TouchAction(d)
    action1.long_press(element)
    action1.perform()
 def long_press(self, locator):
     """ Long press the element """
     driver = self._current_application()
     element = self._element_find(locator, True, True)
     long_press = TouchAction(driver).long_press(element)
     long_press.perform()        
示例#51
0
    def test_browser_is_opened(self):
        sleep(.5)
        contexts = self.driver.contexts
        self.assertIsNotNone(contexts)
        self.assertEqual(contexts[0], "NATIVE_APP")
        el = self.driver.find_element_by_id("openBrowserBtt")
        self.driver.save_screenshot(PATH('./screen.png'))
        self.assertIsNotNone(el)
        el.click()
        sleep(.5)
        el = self.driver.find_element_by_id("openBrowserBtt")
        self.assertIsNotNone(el)
        el.click()
        sleep(5)

        # press home button
        self.driver.press_keycode(3)
        sleep(1)


        """
        # press switch app button
        self.driver.press_keycode(187)
        sleep(1)
        """

        # click on the launcher icon
        els = self.driver.find_elements_by_class_name("android.widget.TextView")
        el = None
        for el in els:
            if el.get_attribute("text") == "":
                break

        self.assertIsNotNone(el)
        el.click()
        sleep(.5)

        el = None
        while self.is_on_app_list():
            el = self.search_chrome_button()
            if el is not None:
                break


            action = TouchAction(self.driver)
            action.press(x=100, y=100).wait(300).move_to(400,100).release()
            action.perform()

            sleep(.6)

        print el
        # click on chrome button
        self.assertIsNotNone(el)
        el.click()
        sleep(.3)

        contexts = self.driver.contexts
        print contexts
        has_webview = False
        for i in range(0, len(contexts)):
            search = re.search('WEBVIEW', contexts[i])
            if search is not None:
                has_webview = True

        self.assertEquals(has_webview, True)
        self.driver.quit()