def test_parallel_actions(self):
        el1 = self.driver.find_element_by_name('Content')
        el2 = self.driver.find_element_by_name('Animation')
        self.driver.scroll(el1, el2)

        el = self.driver.find_element_by_name('Views')
        action = TouchAction(self.driver)
        action.tap(el).perform()

        el = self.driver.find_element_by_name('Expandable Lists')
        # simulate a swipe/scroll
        action.press(el).move_to(x=100, y=-1000).release().perform()

        el = self.driver.find_element_by_name('Splitting Touches across Views')
        action.tap(el).perform()

        els = self.driver.find_elements_by_class_name('android.widget.ListView')
        a1 = TouchAction()
        a1.press(els[0]) \
            .move_to(x=10, y=0).move_to(x=10, y=-75).move_to(x=10, y=-600).release()

        a2 = TouchAction()
        a2.press(els[1]) \
            .move_to(x=10, y=10).move_to(x=10, y=-300).move_to(x=10, y=-600).release()

        ma = MultiAction(self.driver, els[0])
        ma.add(a1, a2)
        ma.perform();
示例#2
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
示例#3
0
    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 test_tap_x_y(self):
        el = self.driver.find_element_by_accessibility_id('Animation')
        action = TouchAction(self.driver)
        action.tap(el, 100, 10).perform()

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Bouncing Balls')
        self.assertIsNotNone(el)
示例#5
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
示例#6
0
 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 click_a_point(self, x=0, y=0):
     """ Click on a point"""
     self._info("Clicking on a point (%s,%s)." % (x,y))
     driver = self._current_application()
     action = TouchAction(driver)
     try:
         action.tap(x=float(x), y=float(y)).perform()
     except:
         assert False, "Can't click on a point at (%s,%s)" % (x,y)
 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()
示例#10
0
    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)
示例#11
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
 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()
示例#13
0
    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)
示例#14
0
    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()
class TouchActionTests(unittest.TestCase):
    def setUp(self):
        self._touch_action = TouchAction(DriverStub())

    def test_tap_json(self):
        json = [{"action": "tap", "options": {"x": None, "y": None, "count": 1, "element": 1}}]
        self._touch_action.tap(ElementStub(1))
        self.assertEqual(json, self._touch_action.json_wire_gestures)

    def test_tap_x_y_json(self):
        json = [{"action": "tap", "options": {"x": 3, "y": 4, "count": 1, "element": 2}}]
        self._touch_action.tap(ElementStub(2), 3, 4)
        self.assertEqual(json, self._touch_action.json_wire_gestures)
示例#16
0
    def test_test(self):
        driver = webdriver.Remote(
            'http://0.0.0.0:4723/wd/hub', {
                "platformName": "Android",
                "platformVersion": "6.0",
                "appPackage": "cgtz.com.cgtz",
                "appActivity": ".ui.MainActivity",
                "deviceName": "deviceName"
            })

        # function.insert_img(driver, 'hello')
        # sleep(1)
        # print('1' + driver.current_activity) # .ui.Guide_activity
        # driver.swipe(start_x=350, start_y=250, end_x=20, end_y=250, duration=200)
        # sleep(1)
        # driver.swipe(start_x=250, start_y=250, end_x=20, end_y=250, duration=200)
        # sleep(1)
        # driver.swipe(start_x=250, start_y=250, end_x=20, end_y=250, duration=200)
        # sleep(1)
        # driver.swipe(start_x=250, start_y=250, end_x=20, end_y=250, duration=200)
        # sleep(1)
        # print('2' + driver.current_activity)

        action = TouchAction(driver)
        el_mine = driver.find_element_by_android_uiautomator(
            'new UiSelector().resourceIdMatches(".*id/layout_main_mine")')
        self.assertIsNotNone(el_mine)
        action.tap(element=el_mine).release().perform()  # 点击我的
        print('3' + driver.current_activity)  # .ui.Guide_activity
        action.tap(x=200, y=200).release().perform()  # 指引点击
        print('4' + driver.current_activity)  # .ui.LoginNewActivity
        el_button = driver.find_element_by_android_uiautomator(
            'new UiSelector().resourceIdMatches(".*id/tv_login")')
        action.tap(element=el_button).release().perform()  # 点击登录

        el_phone = driver.find_element_by_android_uiautomator(
            'new UiSelector().resourceIdMatches(".*id/et_phone_num")')
        driver.set_value(el_phone, '18658870960')  # 输入手机
        el_pass = driver.find_element_by_android_uiautomator(
            'new UiSelector().resourceIdMatches(".*id/et_pwd")')
        driver.set_value(el_pass, 'ssssss2')  # 输入密码
        action.tap(element=el_button).release().perform()  # 点击登录
        print('5' + driver.current_activity)

        el_asklater = driver.find_element_by_android_uiautomator(
            'new UiSelector().resourceIdMatches(".*id/tv_first_login_left")')
        action.tap(element=el_asklater).release().perform()  # 点击以后再说

        sleep(2)
        driver.quit()
示例#17
0
    def _tap_today_and_ok(self):

        # tap on today
        today = time.strftime("%d %B %Y", time.localtime())
        el = WebDriverWait(
            self.driver,
            10).until(lambda function: self.driver.
                      find_element_by_accessibility_id(today + ' selected'))
        action = TouchAction(self.driver)
        action.tap(el).perform()

        # tap on OK
        el = self.driver.find_element_by_id('com.nineteenthmile:id/ok')
        action.tap(el).perform()
示例#18
0
    def login(self):
        """ to login """

        el = WebDriverWait(self.driver, 30).until(
            EC.presence_of_element_located(
                (By.ID, self.locators['login_user'])),
            message='element timed out: %s' % (self.locators['login_user']))
        el.send_keys(Login.user)

        self.driver.find_element_by_id(self.locators['login_pass']).send_keys(
            Login.password)
        el = self.driver.find_element_by_id('com.nineteenthmile:id/login')
        self.assertIsNotNone(el)
        action = TouchAction(self.driver)
        action.tap(el).perform()
示例#19
0
    def test_drag_and_drop(self):
        self._move_to_views()
        action = TouchAction(self.driver)

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop')
        action.tap(el).perform()

        dd3 = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_dot_3'.format(APIDEMO_PKG_NAME))
        dd2 = self.driver.find_element_by_id('{}:id/drag_dot_2'.format(APIDEMO_PKG_NAME))

        # dnd is stimulated by longpress-move_to-release
        action.long_press(dd3).move_to(dd2).release().perform()

        el = wait_for_element(self.driver, MobileBy.ID, '{}:id/drag_result_text'.format(APIDEMO_PKG_NAME))
        self.assertTrue('Dropped!' in el.text)
示例#20
0
 def Tag(self,x,y,duration):
     time.sleep(2)
     action = TouchAction(self.driver)
     try:
         if duration:
             duration = duration * 1000
             action.long_press(x=x, y=y, duration=duration).release()
         else:
             # TouchAction(self.driver).press(None, x, y).release().perform()
             action.tap(x=x, y=y)
         action.perform()
         return True
     except BaseException as e:
         print(e)
         return False
 def tap_native(self, el=None, x=None, y=None, count=1):
     '''
     触摸操作,native原生app上的元素,tap事件
     :param driver:
     :param el:  元素对象
     :param x:  x坐标
     :param y:  y坐标
     :param count: 次数
     :return:
     '''
     action = TouchAction(self.driver)
     if el:
         action.tap(element=el, count=count).perform()
     else:
         action.tap(x=x, y=y, count=count).perform()
示例#22
0
class Uc010(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['automationName'] = 'UiAutomator2'
        # desired_caps['platformVersion'] = '10.0'
        desired_caps['deviceName'] = 'emulator-5554'
        desired_caps['appPackage'] = 'org.isoron.uhabits'
        desired_caps['appActivity'] = 'org.isoron.uhabits.MainActivity'
        desired_caps['fullReset'] = False
        desired_caps['noReset'] = True
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",
                                       desired_caps)
        self.driver.implicitly_wait(5)
        self.actions = TouchAction(self.driver)
        self.driver.reset()
        self.prepare_test_data_of_one_habit()

    def prepare_test_data_of_one_habit(self):
        self.driver.find_element_by_id("org.isoron.uhabits:id/next").click()
        self.driver.find_element_by_id("org.isoron.uhabits:id/next").click()
        self.driver.find_element_by_id("org.isoron.uhabits:id/done").click()
        self.driver.find_element_by_id(
            "org.isoron.uhabits:id/actionCreateBooleanHabit").click()
        self.driver.find_element_by_id(
            "org.isoron.uhabits:id/tvName").send_keys("hello")
        self.driver.find_element_by_id(
            "org.isoron.uhabits:id/buttonSave").click()

    def habit_detail_scroll_to_bottom(self):
        self.driver.swipe(150, 1000, 150, 100, 1000)
        self.driver.swipe(150, 1000, 150, 100, 1000)

    def test_uatc012_record_habits_of_days_ago_calendar(self):
        self.driver.find_element_by_xpath(
            "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[1]/android.widget.RelativeLayout/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView"
        ).click()
        self.habit_detail_scroll_to_bottom()
        self.driver.find_element_by_id("org.isoron.uhabits:id/edit").click()
        self.driver.find_element_by_id("org.isoron.uhabits:id/parentPanel")
        self.actions.tap(x=218, y=911).perform()
        self.actions.tap(x=218, y=911).perform()
        self.actions.tap(x=213, y=1013).perform()
        self.driver.find_element_by_id("android:id/button1").click()
        # TODO assert

    def tearDown(self):
        self.driver.quit()
示例#23
0
def click_native(dx, dy):
    time.sleep(5)
    driver.switch_to.context('NATIVE_APP')
    print('switch to native')
    print(driver.current_context)
    x = driver.get_window_size()['width'] * dx
    y = driver.get_window_size()['height'] * dy

    actions = TouchAction(driver)
    actions.tap(x=x, y=y)
    actions.perform()

    driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
    print('switch to web')
    print(driver.current_context)
    time.sleep(3)
class Screen:
    """The base page for all other pages."""

    EXPLICIT_WAIT_TIME = 10

    def __init__(self, driver):
        self.driver = driver
        self.driver.set_explicit(self.EXPLICIT_WAIT_TIME)
        self.action = TouchAction(self.driver)

    def tap(self, element):
        try:
            self.action.tap(element).perform()
        except Exception as e:
            preporter.critical("Element Not found to tap on\n" + str(e))
            pconsole.write_line("Element Not found to tap on\n" + str(e))
示例#25
0
def open_wifi_setting(self):
    el = self.driver.find_element_by_id(
        "com.blackloud.wetti:id/system_wifi_setting")
    self.assertIsNotNone(el)
    action = TouchAction(self.driver)
    action.tap(el).perform()
    #    el.click()
    sleep(3)
    while (1):  # TODO Here is a bug. Touch "open wifi setting" no response.
        try:
            el = self.driver.find_element_by_id(
                "com.blackloud.wetti:id/system_wifi_setting")
            el.click()
            sleep(1)
        except:
            break
示例#26
0
    def tap(self, locator, **kwargs):
        """
        custom wrapped single tap method
        -> wait until display
        -> element(s)
        """
        App.is_displayed(self, locator, True)

        actions = TouchAction(self.driver)
        return {
            'element':
            lambda x: actions.tap(App.element(self, locator)).perform(),
            'elements':
            lambda x: actions.tap(
                App.elements(self, locator)[kwargs['index']]).perform()
        }[keyword_check(kwargs)]('x')
示例#27
0
文件: base.py 项目: loveiset/UItest
def export_to_album():
    '''选择一个草稿视频->保存相册'''
    sc.logger.info('点击草稿封面')
    open_draft(iOS_elements.el_home_draft)

    sc.logger.info('保存/上传')
    WebDriverWait(sc.driver, 5,
                  1).until(lambda x: x.find_element_by_name("保存/上传")).click()

    sc.logger.info('点击屏幕消除软键盘')
    actions = TouchAction(sc.driver)
    actions.tap(None, 500, 500, 1).release().perform()

    sc.logger.info('点击“保存到相册”')
    WebDriverWait(sc.driver, 5,
                  1).until(lambda x: x.find_element_by_name("保存到相册")).click()
示例#28
0
    def double_tap(self, locator, n=3, **kwargs):
        """
        custom wrapped double tap method
        -> wait for element until display
        -> element(s)
        """
        App.is_displayed(self, locator, True, n=n)

        actions = TouchAction(self.driver)
        return {
            'element':
            lambda x: actions.tap(App.element(self, locator), count=2).perform(
            ),
            'elements':
            lambda x: actions.tap(App.elements(self, locator)[kwargs['index']],
                                  count=2).perform()
        }[keyword_check(kwargs)]('x')
示例#29
0
    def exit_screen_saver(self, x='100', y='100'):
        """
        退出屏幕保护;在屏幕任意位置之中点击一下
        :return:
        """
        self.sleep('0.1')
        try:
            x = float(x)
            y = float(y)
        except:
            x = 100
            y = 100

        touchAction = TouchAction(self.driver)
        touchAction.tap(x=x, y=y).release().perform()
        self.__write_excel(True)
        return True
示例#30
0
def tap(step):
    action = TouchAction(g.driver)

    element = step['element']
    if isinstance(element, str):

        if ',' in element:
            position = element.split(',')
            x = int(position[0])
            y = int(position[1])
            position = (x, y)
            g.driver.tap([position])
        else:
            element_location = locating_element(element, 'CLICK')
            action.tap(element_location).perform()
    elif isinstance(element, list):
        if ',' in element[0]:
            for el in element:
                position = el.split(',')
                x = int(position[0])
                y = int(position[1])
                position = (x, y)
                g.driver.tap([position])
                sleep(0.5)
        else:
            for _e in element:
                element_location = locating_element(_e, 'CLICK')
                action.tap(element_location).perform()
                sleep(0.5)
    sleep(0.5)

    # 获取元素其他属性
    output = step['output']
    for key in output:
        if output[key] == 'text':
            g.var[key] = element_location.text
        elif output[key] == 'tag_name':
            g.var[key] = element_location.tag_name
        elif output[key] in ('text…', 'text...'):
            if element_location.text.endswith('...'):
                g.var[key] = element_location.text[:-3]
            else:
                g.var[key] = element_location.text
        else:
            g.var[key] = element_location.get_attribute(output[key])
示例#31
0
 def clickTopic(self):
     # 关闭升级弹窗
     self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[4]/UIAButton[1]').click()
     sleep(3)
     # 点击专题,进入专题列表页
     element = self.driver.find_element_by_xpath(
         '//UIAApplication[1]/UIAWindow[1]/UIATabBar[1]/UIAScrollView[1]/UIAImage[2]')
     act = TouchAction(self.driver)
     act.tap(element).perform()
     #进入专题,上滑翻到底部
     sleep(3)
     self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]').click()
     width = self.driver.get_window_size()['width']
     height = self.driver.get_window_size()['height']
     #self.driver.swipe(start_x=width / 2, start_y=50, end_x=width / 2, end_y=500, duration=1000)
     elWebView = self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]')
     act.press(elWebView, width / 2, height * 3/4).move_to(width / 2, height/4).release().perform()
     sleep(10)
示例#32
0
    def _add_notes_routine(self, notes='blablabla'):

        action = TouchAction(self.driver)
        # up swipe
        self.driver.swipe(100, 400, 100, 100, 800)

        # notes
        el = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(
                (By.ID, 'com.nineteenthmile:id/lw_step4_add_notes')))
        action.tap(el).perform()
        el.send_keys(notes)
        self.driver.hide_keyboard('Done')

        el = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(
                (By.ID, 'com.nineteenthmile:id/lead_wizard_button_done')))
        action.tap(el).perform()
    def tap_on_element_wda(self, element: WebElement, x: int = None, y: int = None):

        """
        Taps element without random position within this element.
        WebDriver method, could be used in iOS and Android app
        """

        tc = TouchAction(self.driver)
        if x is None and y is None:
            tc.tap(element)
            statement = f'\nTapped at element'
        else:
            assert x and y, 'You should set x and y'
            tc.tap(x=x, y=y)
            statement = f'\nTapped at: \n width: {x} \n height: {y} \n relative to screen borders'
        tc.perform()
        print(statement)
        return tc
示例#34
0
    def _sign_out(self):
        """ to sign out from app """

        action = TouchAction(self.driver)

        el = self.driver.find_element_by_accessibility_id('Menu_button')
        action.tap(el).perform()

        el = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(
                (By.ID, 'com.nineteenthmile:id/logout_view_logout_icon')))
        action.tap(el).perform()

        el = WebDriverWait(self.driver, 30).until(
            EC.presence_of_element_located(
                (By.ID, 'com.nineteenthmile:id/edit_username')))

        return el
示例#35
0
    def _sign_out(self):
        """ to sign out from app """

        action = TouchAction(self.driver)

        el = self.driver.find_element_by_accessibility_id('Menu_button')
        action.tap(el).perform()

        el = WebDriverWait(self.driver,
                           10).until(EC.presence_of_element_located(
                               (By.ID, self.locators['logout_icon'])),
                                     message='logout locator timed out')
        action.tap(el).perform()

        WebDriverWait(self.driver, 30).until(EC.presence_of_element_located(
            (By.ID, self.locators['login_user'])),
                                             message='element timed out: %s' %
                                             (self.locators['login_user']))
示例#36
0
    def test_export_06_giveup(self):
        """导出-保存到相册-导出取消."""
        sc.logger.info('导出-保存到相册-导出取消')
        fun_name = 'test_export_giveup'

        sc.logger.info('进入我的工作室')
        sc.driver.find_element_by_name("更多草稿").click()
        time.sleep(0.5)

        sc.logger.info('保存并上传')
        el_publish = sc.driver.find_element_by_name("保存/上传")
        el_publish.click()
        time.sleep(0.5)

        sc.logger.info('点击屏幕消除软键盘')
        actions = TouchAction(sc.driver)
        actions.tap(None, 500, 500, 1).release().perform()

        sc.logger.info('点击“保存到相册”')
        sc.driver.find_element_by_name('保存到相册').click()
        time.sleep(0.5)

        sc.logger.info('确认视频是否已导出')
        try:
            sc.driver.find_element_by_name("重新导出").click()
            time.sleep(0.5)
        except NoSuchElementException:
            sc.logger.info('该视频未导出过,直接选择要导出的尺寸')

        sc.logger.info('点击“高清 720P”')
        sc.driver.find_element_by_name("高清 720P").click()
        time.sleep(1)

        sc.logger.info('放弃导出')
        sc.driver.find_element_by_name('icon exit close n').click()
        sc.capture_screen(fun_name, self.img_path)
        sc.driver.find_element_by_name("不等了").click()

        sc.logger.info('点击“存草稿”按钮')
        sc.driver.find_element_by_name("存草稿").click()

        sc.logger.info('点击左上角返回按钮退回创作中心')
        time.sleep(1)
        sc.driver.find_element_by_name("vivavideo com nav back n").click()
示例#37
0
    def test_view(self):
        el = self.driver.find_element_by_xpath(
            "//android.widget.TextView[@content-desc='Views']")
        action = TouchAction(self.driver)
        action.tap(el).perform()
        self.driver.find_element_by_xpath(
            "//android.widget.TextView[@content-desc='Expandable Lists']"
        ).click()
        self.driver.find_element_by_xpath(
            "//android.widget.TextView[@content-desc='1. Custom Adapter']"
        ).click()
        el1 = self.driver.find_element_by_xpath(
            "//android.widget.TextView[@text='People Names']")
        el1.click()

        action.long_press(el1).release().perform()
        self.driver.find_element_by_xpath(
            "//android.widget.TextView[@text='Sample action']").click()
        sleep(5)
示例#38
0
    def test_driver_drag_and_drop(self):
        el1 = self.driver.find_element_by_accessibility_id('Content')
        el2 = self.driver.find_element_by_accessibility_id('Animation')
        self.driver.scroll(el1, el2)

        el = self.driver.find_element_by_accessibility_id('Views')
        action = TouchAction(self.driver)
        action.tap(el).perform()

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop')
        action.tap(el).perform()

        dd3 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_3')
        dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2')

        self.driver.drag_and_drop(dd3, dd2)

        el = self.driver.find_element_by_id('com.example.android.apis:id/drag_text')
        self.assertTrue('drag_dot_3' in el.text)
示例#39
0
    def click(self, locator, count=1):
        """基础的点击事件
        :param locator: 定位器
        :param count: 点击次数
        """
        if locator.get('index'):
            el = self._find_elements(locator)[locator['index']]
        else:
            el = self._find_element(locator)

        if count == 1:
            el.click()
        else:
            touch_action = TouchAction(self.driver)
            try:
                for x in range(count):
                    touch_action.tap(el).perform()
            except:
                pass
示例#40
0
    def click(self, locator, count=1):
        """基础的点击事件

        Args:
            locator:定位器
            count: 点击次数
        """
        el = self._find_element(locator)
        if count == 1:
            self.sleep(1)

            el.click()
        else:
            touch_action = TouchAction(self.driver)
            try:
                for x in range(count):
                    touch_action.tap(el).perform()
            except:
                pass
示例#41
0
def test_drive_settings_screen(self):

    actions = TouchAction(self.driver)
    element2 = self.driver.find_element_by_id(
        'com.mtd.usa.cubcadet:id/seekBarTractionAcc')
    self.driver.swipe(124, 669, 300, 669, 400)
    actions.tap(element2).perform()
    update_setting = self.driver.find_element_by_id('android:id/button1')
    update_setting.click()
    time.sleep(2)

    actions = TouchAction(self.driver)
    element2 = self.driver.find_element_by_id(
        'com.mtd.usa.cubcadet:id/seekBarTractionBrake')
    self.driver.swipe(124, 1098, 300, 1098, 400)
    actions.tap(element2).perform()
    update_setting = self.driver.find_element_by_id('android:id/button1')
    update_setting.click()
    time.sleep(2)
    def test_driver_drag_and_drop(self):
        el1 = self.driver.find_element_by_accessibility_id('Content')
        el2 = self.driver.find_element_by_accessibility_id('Animation')
        self.driver.scroll(el1, el2)

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views')
        action = TouchAction(self.driver)
        action.tap(el).perform()

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop')
        action.tap(el).perform()

        dd3 = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_dot_3')
        dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2')

        self.driver.drag_and_drop(dd3, dd2)

        el = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_text')
        self.assertTrue('drag_dot_3' in el.text)
    def test_driver_drag_and_drop(self):
        el1 = self.driver.find_element_by_name('Content')
        el2 = self.driver.find_element_by_name('Animation')
        self.driver.scroll(el1, el2)

        el = self.driver.find_element_by_name('Views')
        action = TouchAction(self.driver)
        action.tap(el).perform()

        el = self.driver.find_element_by_name('Drag and Drop')
        action.tap(el).perform()

        dd3 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_3')
        dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2')

        self.driver.drag_and_drop(dd3, dd2)

        el = self.driver.find_element_by_id('com.example.android.apis:id/drag_result_text')
        self.assertEqual('Dropped!', el.get_attribute('text'))
示例#44
0
    def _move_to_splitting_touches_accros_views(self) -> None:
        el1 = self.driver.find_element_by_accessibility_id('Content')
        el2 = self.driver.find_element_by_accessibility_id('Animation')
        self.driver.scroll(el1, el2)

        el = self.driver.find_element_by_accessibility_id('Views')
        action = TouchAction(self.driver)
        action.tap(el).perform()

        # simulate a swipe/scroll
        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists')
        action.press(el).move_to(x=100, y=-1000).release().perform()
        el = self.driver.find_element_by_accessibility_id('Layouts')
        action.press(el).move_to(x=100, y=-1000).release().perform()

        el = self.driver.find_element_by_accessibility_id('Splitting Touches across Views')
        action.tap(el).perform()

        wait_for_element(self.driver, MobileBy.ID, 'io.appium.android.apis:id/list1')
示例#45
0
 def t_double_tap(self, locator: "UiLocator") -> TouchAction:
     """
     Performa dos toques seguidos sobre un elemento.
     Args:
         locator (UiLocator): define una estrategia y un valor para encontrar un elemento
     Returns:
         (TouchAction): handler con una acción para seguir encadenando gestos.
     """
     action = TouchAction(self.driver)
     return action.tap(self.find_element(locator), count=2).perform()
 def test_webview(self):
     username = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("tbUsername")')
     username.send_keys("rishi-prod")
     element = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("bSignIn")')
     element.click()
     password = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("password")')
     password.send_keys('P@55w0rd')
     self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("bSignIn")').click()
     menu = wait1(self.driver, 30).until(EC.visibility_of_element_located((MobileBy.ACCESSIBILITY_ID, 'Open navigation drawer')))
     menu.click()
     action = TouchAction(self.driver)
     window_size = self.driver.get_window_size()
     xpoint = ((window_size["width"] - 1 )/ 2)
     ypoint = ((window_size["height"] - 1) / 2)
     print(xpoint, ypoint)
     self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("Video WalkAround")').click()
     self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.mykaarma.android:id/mileage")').send_keys('1000')
     self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.mykaarma.android:id/hangTag")').send_keys('testTag')
     self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.mykaarma.android:id/skipVinBtn")').click()
     self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("android:id/button1")').click()
     self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("android:id/search_src_text")').send_keys('*****@*****.**')
     self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.mykaarma.android:id/customerSearchTextView")').click()
     self.driver.find_element_by_xpath('(//android.widget.TextView[@resource-id="com.mykaarma.android:id/vehicleDetail"])[1]').click()
     self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.mykaarma.android:id/video")').click()
     time.sleep(2)
     count = 10
     while count > 0:
         action.tap(None, xpoint, ypoint, 1).perform()
         count -= 1
         time.sleep(10)
         print("count is ", count)
     print("complete")
     self.driver.find_element_by_android_uiautomator(
         'new UiSelector().resourceId("com.mykaarma.android:id/video")').click()
     self.driver.find_element_by_android_uiautomator(
         'new UiSelector().resourceId("android:id/button1")').click()
     self.driver.find_element_by_android_uiautomator(
         'new UiSelector().resourceId("com.mykaarma.android:id/pendingInspectionsBtn")').click()
     walkaroundlabel = wait1(self.driver, 30).until(
         EC.visibility_of_element_located((MobileBy.ID, 'com.mykaarma.android:id/pastWalkaroundsLabel')))
     walkaroundlabel.is_displayed()
     self.driver.find_element_by_xpath(
         '(//android.widget.LinearLayout[@resource-id="com.mykaarma.android:id/pendingParentLayout"])[1]').click()
示例#47
0
    def test_drag_and_drop(self):
        el1 = self.driver.find_element_by_accessibility_id('Content')
        el2 = self.driver.find_element_by_accessibility_id('Animation')
        self.driver.scroll(el1, el2)

        el = self.driver.find_element_by_accessibility_id('Views')
        action = TouchAction(self.driver)
        action.tap(el).perform()

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Drag and Drop')
        action.tap(el).perform()

        dd3 = wait_for_element(self.driver, MobileBy.ID, 'com.example.android.apis:id/drag_dot_3')
        dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2')

        # dnd is stimulated by longpress-move_to-release
        action.long_press(dd3).move_to(dd2).release().perform()

        el = self.driver.find_element_by_id('com.example.android.apis:id/drag_text')
        self.assertTrue('drag_dot_3' in el.text)
    def test_drag_and_drop(self):
        el1 = self.driver.find_element_by_name('Content')
        el2 = self.driver.find_element_by_name('Animation')
        self.driver.scroll(el1, el2)

        el = self.driver.find_element_by_name('Views')
        action = TouchAction(self.driver)
        action.tap(el).perform()

        el = self.driver.find_element_by_name('Drag and Drop')
        action.tap(el).perform()

        dd3 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_3')
        dd2 = self.driver.find_element_by_id('com.example.android.apis:id/drag_dot_2')

        # dnd is stimulated by longpress-move_to-release
        action.long_press(dd3).move_to(dd2).release().perform()

        el = self.driver.find_element_by_id('com.example.android.apis:id/drag_result_text')
        self.assertEqual('Dropped!', el.get_attribute('text'))
    def test_driver_multi_tap(self):
        el = self.driver.find_element_by_name('Graphics')
        action = TouchAction(self.driver)
        action.tap(el).perform()

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

        els = self.driver.find_elements_by_class_name('android.widget.TextView')
        if els[len(els) - 1].get_attribute('name') != 'Xfermodes':
            self.driver.scroll(els[len(els) - 1], els[0])

        el = self.driver.find_element_by_name('Touch Paint')
        action.tap(el).perform()

        positions = [(100, 200), (100, 400)]

        # makes two dots in the paint program
        # THE TEST MUST BE WATCHED TO CHECK IF IT WORKS
        self.driver.tap(positions)
        sleep(10)
    def test_long_press_x_y(self):
        el1 = self.driver.find_element_by_name('Content')
        el2 = self.driver.find_element_by_accessibility_id('Animation')

        action = TouchAction(self.driver)
        action.press(el1).move_to(el2).perform()

        el = self.driver.find_element_by_accessibility_id('Views')
        # self.assertIsNotNone(el)
        action.tap(el).perform()

        el = self.driver.find_element_by_accessibility_id('Expandable Lists')
        # self.assertIsNotNone(el)
        action.tap(el).perform()

        el = self.driver.find_element_by_accessibility_id('1. Custom Adapter')
        # self.assertIsNotNone(el)
        action.tap(el).perform()

        # the element "People Names" is located at 0:110 (top left corner)
        action.long_press(x=10, y=120).perform()

        # 'Sample menu' only comes up with a long press, not a tap
        el = self.driver.find_element_by_name('Sample menu')
        self.assertIsNotNone(el)
    def test_login(self):

        action = TouchAction(self.driver)

        # Находим элемент кнопка для входа в приложение и тапом входим в приложение
        landing_goon_button = self.driver.find_element_by_id('com.wheely.wheely.dev:id/landing_goon_button')
        action.tap(landing_goon_button).perform()

        # находим поле с указанием локали для отправки смс
        region_field = self.driver.find_element_by_id('com.wheely.wheely.dev:id/countryName')
        # извлекаем текст элемента
        text_region_field = region_field.get_attribute('text')
        # так  как тест для региона Россия, если стоит другая локаль соврешаем действия для выбора локали Россия
        if text_region_field != "Russ":
            action.tap(region_field).perform()

            #list_region_name_field = self.driver.find_elements_by_class_name('android.widget.RelativeLayout')
            for i in self.driver.find_elements_by_class_name('android.widget.RelativeLayout'):
                list_region_name_field = self.driver.find_elements_by_class_name('android.widget.RelativeLayout')
                start_el_scrl = list_region_name_field[1]
                stop_el_scrl = list_region_name_field[0]
                self.driver.scroll(start_el_scrl, stop_el_scrl)
                if self.driver.find_element_by_id('com.wheely.wheely.dev:id/item_country_displayname').get_attribute('text') == "Россия":
                    right_region_field = self.driver.find_element_by_id('com.wheely.wheely.dev:id/item_country_displayname')
                    action.tap(right_region_field).perform()
    def test_press_and_wait(self):
        el1 = self.driver.find_element_by_name('Content')
        el2 = self.driver.find_element_by_accessibility_id('Animation')

        action = TouchAction(self.driver)
        action.press(el1).move_to(el2).perform()

        sleep(SLEEPY_TIME)
        el = self.driver.find_element_by_accessibility_id('Views')
        # self.assertIsNotNone(el)
        action.tap(el).perform()

        sleep(SLEEPY_TIME)
        el = self.driver.find_element_by_accessibility_id('Expandable Lists')
        # self.assertIsNotNone(el)
        action.tap(el).perform()

        sleep(SLEEPY_TIME)
        el = self.driver.find_element_by_accessibility_id('1. Custom Adapter')
        # self.assertIsNotNone(el)
        action.tap(el).perform()

        sleep(SLEEPY_TIME)
        el = self.driver.find_element_by_name('People Names')
        # self.assertIsNotNone(el)
        action.press(el).wait(2000).perform()

        sleep(SLEEPY_TIME)
        # 'Sample menu' only comes up with a long press, not a press
        el = self.driver.find_element_by_name('Sample menu')
        self.assertIsNotNone(el)
    def test_driver_zoom(self):
        el1 = self.driver.find_element_by_name('Content')
        el2 = self.driver.find_element_by_name('Animation')
        self.driver.scroll(el1, el2)

        el = self.driver.find_element_by_name('Views')
        action = TouchAction(self.driver)
        action.tap(el).perform()

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

        els = self.driver.find_elements_by_class_name('android.widget.TextView')
        if els[len(els)-1].get_attribute('name') != 'WebView':
            self.driver.scroll(els[len(els)-1], els[0])

        el = self.driver.find_element_by_name('WebView')
        action.tap(el).perform()

        sleep(SLEEPY_TIME)
        el = self.driver.find_element_by_id('com.example.android.apis:id/wv1')
        self.driver.zoom(element=el)
示例#54
0
    def test_actions_with_waits(self):
        el1 = self.driver.find_element_by_accessibility_id('Content')
        el2 = self.driver.find_element_by_accessibility_id('Animation')
        self.driver.scroll(el1, el2)

        el = self.driver.find_element_by_accessibility_id('Views')
        action = TouchAction(self.driver)
        action.tap(el).perform()

        # simulate a swipe/scroll
        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists')
        action.press(el).move_to(x=100, y=-1000).release().perform()
        el = self.driver.find_element_by_accessibility_id('Layouts')
        action.press(el).move_to(x=100, y=-1000).release().perform()

        el = self.driver.find_element_by_accessibility_id('Splitting Touches across Views')
        action.tap(el).perform()

        wait_for_element(self.driver, MobileBy.CLASS_NAME, 'android.widget.ListView')
        els = self.driver.find_elements_by_class_name('android.widget.ListView')
        a1 = TouchAction()
        a1.press(els[0]) \
            .move_to(x=10, y=0) \
            .move_to(x=10, y=-75) \
            .wait(1000) \
            .move_to(x=10, y=-600) \
            .release()

        a2 = TouchAction()
        a2.press(els[1]) \
            .move_to(x=10, y=10) \
            .move_to(x=10, y=-300) \
            .wait(500) \
            .move_to(x=10, y=-600) \
            .release()

        ma = MultiAction(self.driver, els[0])
        ma.add(a1, a2)
        ma.perform()
示例#55
0
    def test_tap_twice(self):
        el = self.driver.find_element_by_accessibility_id('Text')
        action = TouchAction(self.driver)
        action.tap(el).perform()

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'LogTextBox')
        action.tap(el).perform()

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Add')
        action.tap(el, count=2).perform()

        els = self.driver.find_elements_by_class_name('android.widget.TextView')
        self.assertEqual('This is a test\nThis is a test\n', els[1].get_attribute("text"))
    def test_tap_twice(self):
        el = self.driver.find_element_by_name('Text')
        action = TouchAction(self.driver)
        action.tap(el).perform()
        sleep(SLEEPY_TIME)

        el = self.driver.find_element_by_name('LogTextBox')
        action.tap(el).perform()

        el = self.driver.find_element_by_name('Add')
        action.tap(el, count=2).perform()

        els = self.driver.find_elements_by_class_name('android.widget.TextView')
        self.assertEqual('This is a test\nThis is a test\n', els[1].get_attribute("text"))
示例#57
0
    def test_long_press_x_y(self):
        el1 = self.driver.find_element_by_accessibility_id('Content')
        el2 = self.driver.find_element_by_accessibility_id('Animation')

        action = TouchAction(self.driver)
        action.press(el1).move_to(el2).perform()

        el = self.driver.find_element_by_accessibility_id('Views')
        action.tap(el).perform()

        el = self.driver.find_element_by_accessibility_id('Expandable Lists')
        action.tap(el).perform()

        el = self.driver.find_element_by_accessibility_id('1. Custom Adapter')
        action.tap(el).perform()

        # the element "People Names" is located at 430:310 (top left corner)
        # location can be changed by phone resolusion, OS version
        action.long_press(x=430, y=310).perform()

        # 'Sample menu' only comes up with a long press, not a tap
        el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR,
                              'new UiSelector().text("Sample menu")')
        self.assertIsNotNone(el)
示例#58
0
    def test_press_and_wait(self):
        el1 = self.driver.find_element_by_accessibility_id('Content')
        el2 = self.driver.find_element_by_accessibility_id('Animation')

        action = TouchAction(self.driver)
        action.press(el1).move_to(el2).perform()

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Views')
        action.tap(el).perform()

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, 'Expandable Lists')
        action.tap(el).perform()

        el = wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, '1. Custom Adapter')
        action.tap(el).perform()

        el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR,
                              'new UiSelector().text("People Names")')
        action.press(el).wait(2000).perform()

        # 'Sample menu' only comes up with a long press, not a press
        el = wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR,
                              'new UiSelector().text("Sample menu")')
        self.assertIsNotNone(el)
 def tap(self, locator):
     """ Tap on element """
     driver = self._current_application()
     el = self._element_find(locator, True, True)
     action = TouchAction(driver)
     action.tap(el).perform()