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