bootstrap: Fix dumpObject not work issue
[platform/core/uifw/aurum.git] / protocol / resources / python / legacySamples / sample04.py
1 from __future__ import print_function
2 import aurum_pb2
3 import aurum_pb2_grpc
4 import logging
5 import grpc
6 import time
7
8 def sendKey(stub, key):
9     rsp_key = stub.sendKey(aurum_pb2.ReqKey(
10                     type=key,
11                     actionType='STROKE',
12                 )
13             )
14     time.sleep(1)
15
16 def launchApp(stub, pkgname):
17     rsp_launch = stub.launchApp(aurum_pb2.ReqLaunchApp(
18            packageName=pkgname
19     ))
20
21 def closeApp(stub, pkgname):
22     rsp_launch = stub.closeApp(aurum_pb2.ReqCloseApp(
23            packageName=pkgname
24     ))
25
26 def getAppInfo(stub, pkgname):
27    rsp_info = stub.getAppInfo(aurum_pb2.ReqGetAppInfo(packageName=pkgname))
28    print(rsp_info)
29
30 def touchdown(stub, xx, yy):
31    rsp = stub.touchDown(aurum_pb2.ReqTouchDown(coordination=aurum_pb2.Point(x=xx,y=yy)))
32    print(rsp)
33
34 def touchmove(stub, xx, yy):
35    rsp = stub.touchMove(aurum_pb2.ReqTouchMove(coordination=aurum_pb2.Point(x=xx,y=yy)))
36    print(rsp)
37
38 def touchup(stub, xx, yy):
39    rsp = stub.touchUp(aurum_pb2.ReqTouchUp(coordination=aurum_pb2.Point(x=xx,y=yy)))
40    print(rsp)
41
42 def new_memo(stub):
43     touchdown(stub, 630,1140)
44     time.sleep(0.1)
45     touchup(stub, 630,1140)
46     time.sleep(0.5)
47
48 def findElementByText(stub, text):
49     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
50                 strategy='TEXT',
51                 textField=text
52             )
53         )
54     for item in rsp_find.elements:
55         return item.elementId
56     return None
57
58 def findElementsByText(stub, text):
59     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
60                 strategy='TEXT',
61                 textField=text
62             )
63         )
64     return rsp_find.elements
65
66 def clickById(stub, id):
67     stub.click(aurum_pb2.ReqClick(
68                 type='ELEMENTID',
69                 elementId=id
70             )
71         )
72
73 def run_memo(stub):
74     foundId = findElementByText(stub, 'All apps')
75     time.sleep(1)
76     if foundId != None:
77         clickById(stub, foundId)
78         time.sleep(1)
79
80         foundId = findElementByText(stub, 'Memo')
81         time.sleep(1)
82         if foundId != None:
83             clickById(stub, foundId)
84             time.sleep(2)
85
86 def set_text(stub, text):
87     foundId = findElementByText(stub, 'Title')
88     if foundId != None:
89       clickById(stub, foundId)
90       time.sleep(1.2)
91       stub.setValue(aurum_pb2.ReqSetValue(
92                elementId=foundId,
93                stringValue=text))
94     foundIds = findElementsByText(stub, "Memo")
95     if len(foundIds) >= 2:
96         stub.setValue(aurum_pb2.ReqSetValue(
97                    elementId=foundIds[1].elementId,
98                    stringValue=text))
99     time.sleep(0.2)
100     foundId = findElementByText(stub, 'DONE')
101     if foundId != None:
102       clickById(stub, foundId)
103
104 def clear_text(stub, el):
105     print(stub.clear(aurum_pb2.ReqClear(elementId=el)))
106
107 def run():
108     with grpc.insecure_channel('127.0.0.1:50051') as channel:
109         stub = aurum_pb2_grpc.BootstrapStub(channel)
110
111         foundId = findElementByText(stub, 'Title')
112         print(foundId)
113         clear_text(stub, foundId)
114
115 #       foundId = findElementByText(stub, 'Photos')
116 #       print(foundId)
117 #       foundId = findElementByText(stub, 'Resume')
118 #       print(foundId)
119 #       if foundId != None:
120 #           clickById(stub, foundId)
121
122 #       time.sleep(1.35)
123
124 #       foundId = findElementByText(stub, 'STOP')
125 #       print(foundId)
126 #       if foundId != None:
127 #           clickById(stub, foundId)
128
129 if __name__ == '__main__':
130     logging.basicConfig()
131     run()