bootstrap/aurum: rework GetAttributeCommand
[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 getAttrById(stub, id, attr):
79    rsp = stub.getAttribute(aurum_pb2.ReqGetAttribute(attribute=attr, elementId=id))
80    print(rsp)
81
82 def run_memo(stub):
83     foundId = findElementByText(stub, 'All apps')
84     time.sleep(1)
85     if foundId != None:
86         getAttrById(stub, foundId, 'VISIBLE')
87         getAttrById(stub, foundId, 'CLICKABLE')
88         getAttrById(stub, foundId, 'FOCUSED')
89         getAttrById(stub, foundId, 'ENABLED')
90         getAttrById(stub, foundId, 'CHECKED')
91         clickById(stub, foundId)
92         time.sleep(1)
93
94         foundId = findElementByText(stub, 'Memo')
95         time.sleep(1)
96         if foundId != None:
97             clickById(stub, foundId)
98             time.sleep(2)
99
100 def set_text(stub, text):
101     foundId = findElementByText(stub, 'Title')
102     if foundId != None:
103       clickById(stub, foundId)
104       time.sleep(1.2)
105       stub.setValue(aurum_pb2.ReqSetValue(
106                elementId=foundId,
107                stringValue=text))
108     foundIds = findElementsByText(stub, "Memo")
109     if len(foundIds) >= 2:
110         stub.setValue(aurum_pb2.ReqSetValue(
111                    elementId=foundIds[1].elementId,
112                    stringValue=text))
113     time.sleep(0.2)
114     foundId = findElementByText(stub, 'DONE')
115     if foundId != None:
116       clickById(stub, foundId)
117
118
119 def run():
120     with grpc.insecure_channel('127.0.0.1:50051') as channel:
121         stub = aurum_pb2_grpc.BootstrapStub(channel)
122
123         getAppInfo(stub, 'org.tizen.memo')
124         time.sleep(1)
125         sendKey(stub, 'HOME')
126         time.sleep(1)
127         closeApp(stub, 'org.tizen.memo')
128         time.sleep(1)
129         getAppInfo(stub, 'org.tizen.memo')
130         time.sleep(1)
131         run_memo(stub)
132         time.sleep(1)
133         new_memo(stub)
134         time.sleep(1)
135         set_text(stub, 'hello')
136
137 if __name__ == '__main__':
138     logging.basicConfig()
139     run()