Beispiel #1
0
 def wifi(self):
   device.screen.on()
   device.press.menu()
   device(text ="Settings").click()
   device(text ="Wireless & networks").down(className="android.widget.TextView").click()
   device.screenshot("home.png")
   device.swipe(591,191,688,245)
   device.press.home()
Beispiel #2
0
def prepare_tap(use_case):
    use_case.install_app()
    use_case.open_app()
    use_case.elements = [
        device(description="Button One"),
        device(description="Button Two"),
        device(description="Button Three"),
        device(description="Button Fab"),
    ]
    def on_mouse(event, x, y, flags, param):
        layout, downpos, ismove = param

        # record downpos
        if event == cv2.EVENT_LBUTTONDOWN:
            print 'click at', x*2, y*2 # picture is half-sized.
            param[1] = (x, y)
            param[2] = False
            return
        # check if is moving
        if event == cv2.EVENT_MOUSEMOVE:
            if ismove: return
            if downpos is None:
                param[2] = False
                return
            _x, _y = downpos
            if (_x-x)**2 + (_y-y)**2 > 64:
                param[2] = True
            return
        if event != cv2.EVENT_LBUTTONUP:
            return

        # update layout.highlight
        b = layout.tree.bounds
        l, t = b.left, b.top
        w, h = b.right - b.left, b.bottom - b.top
        highlight = np.zeros((h, w, 3), np.uint8)

        if downpos and ismove: # drag
            node = layout.find_scrollable_node(x*2+l, y*2+t)
            print 'scroll to', x*2, y*2
            if node:
                b = node.bounds
                print 'scrollable node', b, node.index, node.className,
                print 'resource_id:', node.resourceId,
                print 'text:', node.text.encode(encoding, 'ignore'),
                print 'desc:', node.description.encode(encoding, 'ignore')
                cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,255,255), 4)
        else:
            node = layout.find_clickable_node(x*2+l, y*2+t)
            if node:
                b = node.bounds
                print 'clickable node', b, node.index, node.className,
                print 'resource_id:', node.resourceId,
                print 'text:', node.text.encode(encoding, 'ignore'),
                print 'desc:', node.description.encode(encoding, 'ignore')
                print device(className=node.className, index=node.index).info
                cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,0,255), 4)
                cond, order = layout.find_selector(node)
                if cond:
                    print 'selector', cond, order
                    subnode = layout._filter_nodes(cond)[order or 0]
                    b = subnode.bounds
                    cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,180,255), 4)

        param[0].highlight = highlight
        param[1], param[2] = None, False
def set_display_time():
    if get_screen_off_time() == '1800000':
        print 'screen off time is already 30 mins'
    else:
        os.system('adb shell am start -a android.settings.DISPLAY_SETTINGS')
        device(text="Sleep").click()
        device(text="30 minutes").click()
        time.sleep(1)
        os.system("adb shell am force-stop com.android.settings")
Beispiel #5
0
    def on_mouse(event, x, y, flags, param):
        layout, downpos, ismove = param

        # record downpos
        if event == cv2.EVENT_LBUTTONDOWN:
            print 'click at', x*2, y*2 # picture is half-sized.
            param[1] = (x, y)
            param[2] = False
            return
        # check if is moving
        if event == cv2.EVENT_MOUSEMOVE:
            if ismove: return
            if downpos is None:
                param[2] = False
                return
            _x, _y = downpos
            if (_x-x)**2 + (_y-y)**2 > 64:
                param[2] = True
            return
        if event != cv2.EVENT_LBUTTONUP:
            return

        # update layout.highlight
        b = layout.tree.bounds
        l, t = b.left, b.top
        w, h = b.right - b.left, b.bottom - b.top
        highlight = np.zeros((h, w, 3), np.uint8)

        if downpos and ismove: # drag
            node = layout.find_scrollable_node(x*2+l, y*2+t)
            print 'scroll to', x*2, y*2
            if node:
                b = node.bounds
                print 'scrollable node', b, node.index, node.className,
                print 'resource_id:', node.resourceId,
                print 'text:', node.text.encode(encoding, 'ignore'),
                print 'desc:', node.description.encode(encoding, 'ignore')
                cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,255,255), 4)
        else:
            node = layout.find_clickable_node(x*2+l, y*2+t)
            if node:
                b = node.bounds
                print 'clickable node', b, node.index, node.className,
                print 'resource_id:', node.resourceId,
                print 'text:', node.text.encode(encoding, 'ignore'),
                print 'desc:', node.description.encode(encoding, 'ignore')
                print device(className=node.className, index=node.index).info
                cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,0,255), 4)
                cond, order = layout.find_selector(node)
                if cond:
                    print 'selector', cond, order
                    subnode = layout._filter_nodes(cond)[order or 0]
                    b = subnode.bounds
                    cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,180,255), 4)

        param[0].highlight = highlight
        param[1], param[2] = None, False
Beispiel #6
0
    def on_mouse(event, x, y, flags, param):
        layout, downpos, ismove = param

        # record downpos
        if event == cv2.EVENT_LBUTTONDOWN:
            print 'click at', x*2, y*2 # picture is half-sized.
            param[1] = (x, y)
            param[2] = False
            return
        # check if is moving
        if event == cv2.EVENT_MOUSEMOVE:
            if ismove: return
            if downpos is None:
                param[2] = False
                return
            _x, _y = downpos
            if (_x-x)**2 + (_y-y)**2 > 64:
                param[2] = True
            return
        if event != cv2.EVENT_LBUTTONUP: 
            return

        # update layout.highlight
        b = layout.tree.bounds
        l, t = b.left, b.top
        w, h = b.right - b.left, b.bottom - b.top
        highlight = np.zeros((h, w, 3), np.uint8)

        if downpos and ismove: # drag
            node = layout.find_scrollable_rect(x*2+l, y*2+t)
            print 'scroll to', x*2, y*2
            if node:
                b = node.bounds
                print 'scrolled node', b, node.index, node.class_name, 
                print 'resource_id:', node.resource_id, 
                print 'text:', node.text, 
                print 'desc:', node.content_desc
                cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,255,255), 4)
        else:
            # node = layout.find_clickable_rect(x*2, y*2)
            node = layout.find_minimal_clickable_rect(x*2+l, y*2+t)
            if node:
                b = node.bounds
                print 'clicked node', b, node.index, node.class_name, 
                print 'resource_id:', node.resource_id, 
                print 'text:', node.text, 
                print 'desc:', node.content_desc
                print device(className=node.class_name, index=node.index).info
                cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,0,255), 4)

        param[0].highlight = highlight
        param[1], param[2] = None, False
def turn_airplane(state):

    if state == get_state('airplane_mode_on'):
        print 'airplane already turned ' + state
        return True

    for i in range(4):
        os.system(
            'adb shell am start -a android.settings.AIRPLANE_MODE_SETTINGS')
        device(text="Airplane mode").click.wait()
        time.sleep(1)
        os.system('adb shell am force-stop com.android.settings')
        if state == get_state('airplane_mode_on'):
            return True
    return False
Beispiel #8
0
def prepare_swipe(use_case):
    use_case.install_app()
    use_case.open_app()
    paint = device(description="Paint")
    set_center(paint)
    use_case.x_i, use_case.y_i = (paint.centerX,
                                  paint.info['visibleBounds']["top"])
 def enter_gallery(self):
     """Enter gallery app via activity
     """
     self._logger.debug('Begain to enter gallery app')
     device.press.home()
     device.delay(1)
     device(className="com.tct.launcher.Workspace",
            resourceId="com.tct.launcher:id/workspace").swipe.left(steps=50)
     device.delay(1)
     device.click(160, 660)
     reset_gallery_watchers(device)
     if device(resourceId='com.tct.gallery3d:id/gallery_root').wait.exists(
             timeout=10000):
         self._logger.debug('Enter gallery app successful.')
     else:
         self._logger.debug("Fail to enter gallery app.")
Beispiel #10
0
  def makeCall(self,name):

#device log info ("select phone field")
    device(text="Phone").click()

#device log info ("Type number")
    #device(text="Type a name or phone number").set_text(number)
    #mb=raw_input
    #device.click(32,226)

#device log info ("select contact number")
    device(text="Contacts").click()
    device(scrollable=True).scroll.to(text=name)
    device(text=name).click()

#device log info ("Dial number")
    device(text=name).down(className="android.widget.RelativeLayout").click()
 def gallery_delete(self):
     """Delete one pictures or some pictures or all pictures in gallery
     """
     self._logger.debug("Begin to delete pictures in gallery app.")
     if device(text='Camera roll',
               resourceId='com.tct.gallery3d:id/actionbar_title').exists:
         self._logger.debug(
             "Now is in the  Camera roll,can select the item")
         device(description='Open navigation drawer').click()
         device.delay(1)
         if device(text='Camera roll',
                   resourceId='com.tct.gallery3d:id/tx').wait.exists(
                       timeout=10000):
             self._logger.debug(
                 "Enter the item to select the Camera roll,Albums...")
             device(text='Camera roll',
                    resourceId='com.tct.gallery3d:id/tx').click()
             device.delay(1)
             device.long_click(80, 200)
             if device(description='Delete').wait.exists(timeout=10000):
                 self._logger.debug(
                     "Success enter to select the ablum,There is some pictures"
                 )
                 device.click(80, 200)
             else:
                 self._logger.warning(
                     "There isn't pictures,please import some pictures")
         else:
             self._logger.debug(
                 "Fail to enter the item to select the Camera roll,Alums..."
             )
     else:
         self._logger.debug("Fail enter to gallery interface")
Beispiel #12
0
  def Screencast(self):
    device.screen.on()
    device.press.home()

#device log info("select screencast")
    device(text = "Screencast").click()
    device(text = "Start Screencast").click()
    device.open.notification()
    device(text="Recording?").swipe.down()
    device(text = "Stop").click()
    device.press.home()
Beispiel #13
0
def prepare_dragndrop(use_case):
    use_case.install_app()
    use_case.open_app()
    button1 = device(description="Button One")
    button2 = device(description="Button Two")
    button3 = device(description="Button Three")
    button_fab = device(description="Button Fab")
    text_area = device(description="Text Area")

    set_center(button1)
    set_center(button2)
    set_center(button3)
    set_center(button_fab)
    set_center(text_area)

    use_case.moves = [
        (button1, button2),
        (button2, button3),
        (button_fab, button3),
        (button_fab, text_area),
    ]
def turn_bluetooth(state):

    if state == get_state('bluetooth_on'):
        print 'bluetooth already turned ' + state
        return True

    for i in range(4):
        if state == '0':
            os.system(
                'adb shell am start -a android.settings.BLUETOOTH_SETTINGS')
            time.sleep(1)
            if device(resourceIdMatches=".+/switch_widget$",
                      text="OFF").exists:
                print 'Bluetooth current state is : 0'
                os.system('adb shell am force-stop com.android.settings')
                return True
            else:
                device(resourceIdMatches=".+/switch_widget$",
                       text="ON").click.wait()
        else:
            os.system(
                'adb shell am start -a android.settings.BLUETOOTH_SETTINGS')
            if device(resourceIdMatches=".+/switch_widget$", text="ON").exists:
                print 'Bluetooth current state is : 1'
                os.system('adb shell am force-stop com.android.settings')
                return True
            else:
                device(resourceIdMatches=".+/switch_widget$",
                       text="OFF").click.wait()

        os.system('adb shell am force-stop com.android.settings')
        if state == get_state('bluetooth_on'):
            return True

    return False
def turn_gps(state):
    if state == get_gps_state():
        print 'gps already turned ' + state
        return True

    for i in range(4):
        if state == '0':
            os.system(
                'adb shell am start -a android.settings.LOCATION_SOURCE_SETTINGS'
            )
            if device(resourceIdMatches=".+/switch_widget$", text="ON").exists:
                device(resourceIdMatches=".+/switch_widget$",
                       text="ON").click.wait()
        else:
            os.system(
                'adb shell am start -a android.settings.LOCATION_SOURCE_SETTINGS'
            )
            if device(resourceIdMatches=".+/switch_widget$",
                      text="OFF").exists:
                device(resourceIdMatches=".+/switch_widget$",
                       text="OFF").click.wait()

        os.system('adb shell am force-stop com.android.settings')
        if state == get_gps_state():
            return True

    return False
Beispiel #16
0
  def deleteSMS(self,name):
    device.screen.on()
    device.press.home()

#device log info ("select message field")
    device(text ="Messaging").click()

#device log info ("select message for delete")
    device(scrollable=True).scroll.to(text=name)
    device(text=name).long_click()
    device.click(552,58)
    #device.orientation="l"

#device log info ("Delete the message")
#(In the place of "Cancel" use "Delete")
    device(text="Cancel").click()
    device.press.home()
Beispiel #17
0
  def SMSfromMessaging(self,number,message):
    device.screen.on()
    device.press.home()

#device log info ("select message field")
    device(text ="Messaging").click()
    device(className="android.widget.ImageButton",index="0").click()
    device.click(576,1136)

#device log info ("select the number")
    device(text="To").set_text(number)
    nb=raw_input

#device log info ("write the message")
    device(text="Type message").set_text(message)
    mb=raw_input
    device.click(544,595)
    device.press.home()
Beispiel #18
0
  def deleteAllSMS(self):
    device.screen.on()
    device.press.home()

#device log info ("select message field ")
    device(text ="Messaging").click()
    device.press.menu()

#device log info ("select all the message for delete")
    device(text = "Delete all threads").click()

#device log info ("Delete all the messages")
#(In the place of "Cancel" use "Delete")
    device(text ="Cancel").click()
    device.press.home() 
Beispiel #19
0
  def SMSviaNotification(self,message):

#device log info ("open notification")
    device.open.notification() 

#device log info ("select number to send message")
    device(text="Missed call").swipe.down()
    device(text="Message").click()

#device log info ("Type Message")
    device(text="Type message").set_text(message)
    mb=raw_input

#device log info ("send message")
    device.click(544,1176)
    device.press.home()
Beispiel #20
0
def prepare_pinch_and_spread(use_case):
    use_case.install_app()
    use_case.open_app()
    use_case.paint = device(description="Paint")
Beispiel #21
0
  def SendSMSFromContacts(self,name,message):
#    device = Device('4a25b8a')
    device.screen.on()
    device.press.home()

#device log info("move to contacts")
    device(scrollable=True).scroll.horiz.forward()
    device(scrollable=True).scroll.vert.backward()
    device(text="Contacts").click()

#device log info("select contact")
    device(scrollable=True).scroll.to(text=name)
    device(text = name).click()

#device log info("create message")
    device(className="android.widget.ImageView",resourceId="com.android.contacts:id/icon_alternate").click()

#device log info("input message")
    #device.input ("Test message")
    device(text="Type message").set_text(message)
    mb=raw_input

#device log info("send message")
    #device(className="android.widget.ImageView",resourceId="com.android.mms:id/send_button_sms").click()
    device.click(544,1176)
    device.press.home()
Beispiel #22
0
 def takephoto(self):
   device.screen.on()
   device(text ="Camera").click()
   device(className="android.widget.ImageView",index="3").click()
    def count_delete(self):
        device.long_click(80, 200)
        device.delay(1)
        device(description='More options').click()
        device.delay(1)
        device(text='Select all').click()
        c = device(resourceId='com.tct.gallery3d:id/action_mode_text'
                   ).info.get('text')
        c = int(c)
        print 'The total %s pictures has been exsited' % c
        self._logger.debug("please input the deleted numbers of pictures ")
        h = raw_input(u'请输入要删除的图片的数量h:')
        h = int(h)
        device(description='More options').click()
        device(text='Deselect all').click()
        device.delay(1)
        g = c // 12
        for y in range(g + 1):
            device.swipe(240, 180, 240, 820, steps=100)
        device(description='More options').click()
        device.delay(1)
        device(text='Select item').click()
        device.delay(1)
        if h > c:
            self._logger.debug("failed to delete pictures ")
        else:
            self._logger.debug("can start to delete pictures")
            if h > 15:
                for b in range(5):
                    for a in range(3):
                        device.click(80 + 160 * a, 200 + 160 * b)
                f = h - 15
                j = f // 3
                i = f % 3
                x, y, t = 0, 0, 0
                for x in range(j + 1):
                    if f > 0:
                        if y == 0:
                            device.swipe(240, 690, 240, 480, steps=50)
                        else:
                            device.swipe(240, 689, 240, 530, steps=50)
                        y = y + 1
                        device.delay(1)
                        if x < j:
                            for t in range(3):
                                device.click(80 + 160 * t, 774)
                        f = f - 3
                    else:
                        pass
                for m in range(i):
                    device.click(80 + 160 * m, 774)
                device(description='Delete').click()
                device(text='OK').click()
                if device(description='More options').exists:
                    device(description='More options').click()
                    device.delay(1)
                    device(text='Select item').click()
                    device(description='More options').click()
                    device.delay(1)
                    device(text='Select all').click()
                    delc = device(
                        resourceId='com.tct.gallery3d:id/action_mode_text'
                    ).info.get('text')
                    delc = int(delc)
                    if delc < c:
                        print("%s pictures delete successful" % h)
                        self._logger.debug('delete pictures successful')
                        device(description='More options').click()
                        device(text='Deselect all').click()
                    else:
                        self._logger.debug("fail to delete pictures")
                else:
                    self._logger.debug("fail to delete pictures")

            elif h <= 15:
                i = h % 3
                j = h // 3
                for b in range(j):
                    for a in range(3):
                        device.click(80 + 160 * a, 200 + 160 * b)
                for t in range(i):
                    device.click(80 + 160 * t, 200 + 160 * j)
                device(description='Delete').click()
                device(text='OK').click()
                if device(description='More options').exists:
                    device(description='More options').click()
                    device.delay(1)
                    device(text='Select item').click()
                    device(description='More options').click()
                    device.delay(1)
                    device(text='Select all').click()
                    delc = device(
                        resourceId='com.tct.gallery3d:id/action_mode_text'
                    ).info.get('text')
                    delc = int(delc)
                    if delc < c:
                        print("%s pictures delete successful" % h)
                        self._logger.debug('delete pictures successful')
                        device(description='More options').click()
                        device(text='Deselect all').click()

                    else:
                        self._logger.debug("fail to delete pictures")
                else:
                    self._logger.debug("fail to delete pictures")
            else:
                pass
Beispiel #24
0
def prepare_input_text(use_case):
    use_case.install_app()
    use_case.open_app()
    use_case.text_field = device(
        resourceId="com.tqrg.physalia.testapp:id/text_field")
Beispiel #25
0
  def SendContactsviaSMS(self,numsend,sendnum):

    device.screen.on()
    device.press.home()

#device log info("move to contacts")
    device(text="Contacts").click()
    device(text = "All contacts").click()
    #device(scrollable=True).scroll.to(text=name)

#device log info("number to send")
    device(scrollable=True).scroll.to(text=numsend)
    device(text = numsend).click()
    device.press.menu()
    device(text="Send contact via SMS").click()
    device.click(640,242)

#device log info("send message")
    #device(text="To").set_text(str3)
    #mb=raw_input
    device(scrollable=True).scroll.to(text=sendnum)
    device(text = sendnum).click()
    device.click(552,58)
    device.press.menu()
    device(text="Send").click()
    device.press.back()
    device.press.back()
    device.press.home()
#coding=utf8
from uiautomator import device

from time import sleep
'''
Created on Jan 13, 2017

@author: Administrator
'''

d = device()
print(u"get devices")
print(d.info)

if d.screen == "off":
    d.wakeup()
    sleep(1)
    print(u"已唤醒屏幕,等待解锁")
    d.swipe('804', '670', '56', '691', steps=10)
    #d(className="android.widget.FrameLayout",index=0).swipe('804','670','56','691',steps=10)

    print(u"已解锁,等待启动app")
sleep(1)
print(u"开始启动app")
d(className="com.veclink.microcomm.healthy/.main.activity.SplashActivity",
  index="18").click()
print(u"启动app ok")
sleep(2)
d(className="com.veclink.microcomm.healthy/.main.activity.SplashActivity",
  text=u"登 录").click()
sleep(1)
Beispiel #27
0
def run_find_by_description(_):
    for _ in range(loop_count.FIND_BY_DESCRIPTION):
        device(description="Button One").exists
        device(description="Button Two").exists
        device(description="Button Three").exists
        device(description="Button Fab").exists
        device(description="Text Field").exists
        device(description="Paint").exists
        device(description="Text Area").exists
Beispiel #28
0
def run_find_by_content(_):
    for _ in range(loop_count.FIND_BY_CONTENT):
        device(text="Button 1").exists
        device(text="Button 2").exists
        device(text="Button 3").exists
Beispiel #29
0
#!/user/bin/env python
# coding=utf-8

import uiautomator
class Re
a = uiautomator.device('')
for i in range(1,10):
    print ("\n")
    for j in range(1,i+1):
        print ("%d * %d = %d"%(i,j,i*j)),

Beispiel #30
0
def run_find_by_id(_):
    for _ in range(loop_count.FIND_BY_ID):
        device(resourceId="com.tqrg.physalia.testapp:id/button_1").exists
        device(resourceId="com.tqrg.physalia.testapp:id/button_2").exists
        device(resourceId="com.tqrg.physalia.testapp:id/button_3").exists
        device(resourceId="com.tqrg.physalia.testapp:id/text_field").exists
        device(resourceId="com.tqrg.physalia.testapp:id/fab").exists
        device(resourceId="com.tqrg.physalia.testapp:id/paint").exists
        device(resourceId="com.tqrg.physalia.testapp:id/text_area").exists