e49b5832908e04f697cc3f38b808a51c06cd0067
[platform/core/uifw/aurum.git] / protocol / examples / python / sample02.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 sync(stub):
43    rsp = stub.sync(aurum_pb2.ReqEmpty())
44    print(rsp)
45
46
47 def new_memo(stub):
48     touchdown(stub, 630,1140)
49     time.sleep(0.1)
50     touchup(stub, 630,1140)
51     time.sleep(0.5)
52
53 def findElementByText(stub, text):
54     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
55                 strategy='TEXT',
56                 textField=text
57             )
58         )
59     for item in rsp_find.elements:
60         return item.elementId
61     return None
62
63 def findElementsByText(stub, text):
64     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
65                 strategy='TEXT',
66                 textField=text
67             )
68         )
69     return rsp_find.elements
70
71 def clickById(stub, id):
72     stub.click(aurum_pb2.ReqClick(
73                 type='ELEMENTID',
74                 elementId=id
75             )
76         )
77
78 def run_memo(stub):
79     foundId = findElementByText(stub, 'All apps')
80     time.sleep(1)
81     if foundId != None:
82         clickById(stub, foundId)
83         time.sleep(1)
84
85         foundId = findElementByText(stub, 'Memo')
86         time.sleep(1)
87         if foundId != None:
88             clickById(stub, foundId)
89             time.sleep(2)
90
91 def set_text(stub, text):
92     foundId = findElementByText(stub, 'Title')
93     if foundId != None:
94       clickById(stub, foundId)
95       time.sleep(1.2)
96       stub.setValue(aurum_pb2.ReqSetValue(
97                elementId=foundId,
98                stringValue=text))
99     foundIds = findElementsByText(stub, "Memo")
100     if len(foundIds) >= 2:
101         stub.setValue(aurum_pb2.ReqSetValue(
102                    elementId=foundIds[1].elementId,
103                    stringValue=text))
104     time.sleep(0.2)
105     foundId = findElementByText(stub, 'DONE')
106     if foundId != None:
107       clickById(stub, foundId)
108
109
110 def run():
111     with grpc.insecure_channel('127.0.0.1:50051') as channel:
112         stub = aurum_pb2_grpc.BootstrapStub(channel)
113
114         getAppInfo(stub, 'org.tizen.memo')
115         time.sleep(1)
116         sendKey(stub, 'HOME')
117         time.sleep(1)
118         closeApp(stub, 'org.tizen.memo')
119         time.sleep(1)
120         getAppInfo(stub, 'org.tizen.memo')
121         time.sleep(1)
122         run_memo(stub)
123         time.sleep(1)
124         new_memo(stub)
125         time.sleep(1)
126         set_text(stub, 'hello')
127
128 if __name__ == '__main__':
129     logging.basicConfig()
130     run()