summaryrefslogtreecommitdiff
path: root/automated/android/apk-automation/benchmarkpi.py
blob: 94e198d15592a75f18043ea958a1578145b1978b (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
45
46
47
48
49
50
51
52
53
import sys
import time
from common import ApkTestRunner
from com.dtmilano.android.viewclient import ViewNotFoundException


class ApkRunnerImpl(ApkTestRunner):
    def __init__(self, config):
        self.config = config
        self.config['apk_file_name'] = "gr.androiddev.BenchmarkPi-1.apk"
        self.config['apk_package'] = "gr.androiddev.BenchmarkPi"
        self.config['activity'] = "gr.androiddev.BenchmarkPi/.BenchmarkPi"
        super(ApkRunnerImpl, self).__init__(self.config)

    def execute(self):
        time.sleep(2)
        self.dump_always()
        start_button = self.vc.findViewByIdOrRaise("gr.androiddev.BenchmarkPi:id/Button01")
        start_button.touch()

        finished = False
        while not finished:
            time.sleep(1)
            try:
                self.vc.dump(window='-1')
                self.vc.findViewByIdOrRaise("android:id/message")
                finished = True
            except ViewNotFoundException:
                pass
            except RuntimeError as e:
                self.logger.error(e)
        self.logger.info('benchmark pi finished')

    def parseResult(self):
        return_text = self.vc.findViewByIdOrRaise("android:id/message").getText().split(" ")

        flagwordA = "calculated"
        flagwordB = "Pi"

        if flagwordA in return_text and flagwordB in return_text:
            if return_text.index(flagwordB) == return_text.index(flagwordA) + 1:
                score_number = return_text[return_text.index(flagwordA) + 3]
                score_unit = return_text[return_text.index(flagwordA) + 4].split("!")[0]
                self.logger.info('Valid test result found: %s %s' % (score_number, score_unit))
                run_result = "pass"
            else:
                self.logger.error("Output string changed, parser need to be updated!")
                sys.exit(1)
        else:
            self.logger.error("Can not find keyword which is supposed to show up!")
            sys.exit(1)

        self.report_result('benchmarkpi', run_result, score_number, score_unit)