Esempio n. 1
0
def init():
    logger.info('Conectando ao dispositivo')  # SERIAL...
    dinfo = DEVICE.info

    if dinfo['currentPackageName'].find('com.whatsapp') == -1:
        raise ExportException('É necessário abrir o aplicativo WhatsApp')

    if not dinfo['naturalOrientation']:
        DEVICE.orientation = 'n'
        DEVICE.freeze_rotation()
Esempio n. 2
0
def performEventsOnApp():
    max_iterations = 5
    i = 1
    print("Current Package")

    while (i <= max_iterations):
        d.dump("Output3.xml")
        doc = minidom.parse("Output3.xml")
        nodes = doc.getElementsByTagName("node")
        package = doc.getElementsByTagName("node")[0].getAttribute("package")
        length = nodes.length
        print(d(text="START").exists)
        num_events_iteration = 50
        for x in range(num_events_iteration):
            print(package)
            print(getCurrentPackageName())
            if (package != getCurrentPackageName()):
                d.press.back()
            node = nodes[random.randint(1, length - 1)]
            print(node.getAttribute("class"))
            axisCoordinates = node.getAttribute("bounds").split("]")
            xAxis = axisCoordinates[0].replace('[', '').split(",")
            xCoordinate = (int(xAxis[0]) + int(xAxis[1])) / 2
            yAxis = axisCoordinates[1].replace('[', '').split(",")
            yCoordinate = (int(yAxis[0]) + int(yAxis[1])) / 2
            #screenshot before event --ss1
            #d.click(xCoordinate, yCoordinate)
            randomEvent = loadRandomEvent()
            eventMessage = "No Event"
            #d.screenshot("BeforeEvent.png")
            if randomEvent == 'click':
                d.click(xCoordinate, yCoordinate)
                eventMessage = "Performed click at", str(xCoordinate), str(
                    yCoordinate)
            elif randomEvent == 'swipe':
                d.swipe(xAxis[0], xAxis[1], yAxis[0], yAxis[1])
                eventMessage = "Performed Swipe at", xAxis, yAxis
            elif randomEvent == 'press':
                d.press(xCoordinate, yCoordinate)
                eventMessage = "Performed press at", str(xCoordinate), str(
                    yCoordinate)
            elif randomEvent == 'freeze':
                d.freeze_rotation()
                eventMessage = "Performed freeze rotation"
            #d.screenshot("AfterEvent.png")
            compareImage(eventMessage)
        #screenshot after event -ss2
        #use some kind of image similarity algorithm: open cv(computer vision library) for
        #comparing these screenshots
        #identify threshold %
        i = i + 1
def rotate_unfreeze():
	"""Set to un-freeze rotation"""
	d.freeze_rotation(False)
def rotate_freeze():
	"""Set to freeze rotation"""
	d.freeze_rotation()
	rotate_info()
Esempio n. 5
0
from uiautomator import device as dut
import subprocess

orientation = dut.orientation
dut.orientation = "natural"
dut.freeze_rotation()

intent = "com.android.settings/.Settings"
_cmd = "adb shell am start -n {0}".format(intent)
process = subprocess.Popen(_cmd, shell=True)
process.wait()
package_name = intent.split("/")[0]
assert dut(packageName=package_name).exists is True
dut(text="Security").click()
dut(scrollable=True).scroll.to(text="Clear credentials")
dut(text="Clear credentials").click()
dut(text="OK").click()
dut(scrollable=True).scroll.to(text="Screen lock")
dut(text="Screen lock").click()
dut(resourceId="com.android.settings:id/password_entry").set_text("1234")
dut(resourceId="com.android.settings:id/next_button").click()
dut(text="Swipe").click()

dut.orientation = orientation
dut.freeze_rotation(False)
global_values = globals()
global_values["VERDICT"] = 0
def unlock():
    d.freeze_rotation(False)
def lock():
    d.freeze_rotation()