aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/androidTest/monkeys/customizable_monkey.py
blob: 45a80ed832efb96dc6abce54c80801111ba21092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import re
import sys
import os
import time
import random
import shlex
import subprocess

sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
from com.dtmilano.android.viewclient import ViewClient, View
FLAG_ACTIVITY_NEW_TASK = 0x10000000


class CMonkey:
    def __init__(self):
        self.package = 'org.wordpress.android'
        self.activity = '.ui.themes.ThemeBrowserActivity'
        self.component = self.package + '/' + self.activity
        self.init_device()
        
    def init_device(self):
        self.device, self.serialno = ViewClient.connectToDeviceOrExit()
        self.vc = ViewClient(self.device, self.serialno)

    def start_activity(self):
        self.device.startActivity(component=self.component,
                             flags=FLAG_ACTIVITY_NEW_TASK)

    def random_tap(self):
        x, y = random.randint(0, 2000), random.randint(0, 2000)
        self.device.touch(x, y)

    def test_comments(self):
        for i in range(20):
            self.random_tap()

def test():
    cm = CMonkey()
    for i in range(1000):
        cm.start_activity()
        args = shlex.split("adb shell monkey -p org.wordpress.android 500")
        p = subprocess.Popen(args)

test()