1 from __future__ import print_function
2 from aurum_pb2 import *
3 from aurum_pb2_grpc import BootstrapStub
8 def findElementTest(stub):
9 response = stub.findElement(ReqFindElement(isClickable=True))
10 for el in response.elements:
14 def getValueTest(stub):
15 response = stub.findElement(ReqFindElement(textField='Button'))
16 print("els", response)
17 for el in response.elements:
18 response = stub.getValue(ReqGetValue(elementId=el.elementId))
19 return response.stringValue == 'Button'
22 def setValueClearTest(stub):
24 if size.x < 0: return False
25 if size.y < 0: return False
26 if size.x >= 720: return False
27 if size.y >= 1280: return False
30 for tryCnt in range(10):
31 stub.flick(ReqFlick(startPoint=Point(x=160, y=350), endPoint=Point(x=160, y=10), durationMs=500))
32 response = stub.findElement(ReqFindElement(textField='Entry'))
33 if len(response.elements) <= 0: continue
34 targetObj = response.elements[0].elementId
35 response = stub.getSize(ReqGetSize(elementId=targetObj))
36 if inScreen(response.size):
37 stub.click(ReqClick(type='ELEMENTID', elementId=targetObj))
40 for tryCnt in range(10):
41 stub.flick(ReqFlick(startPoint=Point(x=160, y=350), endPoint=Point(x=160, y=10), durationMs=500))
42 response = stub.findElement(ReqFindElement(textField='Singleline Entry'))
43 if len(response.elements) <= 0: continue
44 targetObj = response.elements[0].elementId
45 response = stub.getSize(ReqGetSize(elementId=targetObj))
46 isShowing = stub.getAttribute(ReqGetAttribute(elementId=targetObj, attribute='SHOWING')).boolValue
47 if inScreen(response.size) or isShowing:
48 stub.click(ReqClick(type='ELEMENTID', elementId=targetObj))
51 response = stub.findElement(ReqFindElement(widgetType='Elm_Entry'))
52 if len(response.elements) <= 0: return False
53 targetObj = response.elements[0].elementId
55 testString = 'set test string by calling SetValue Method'
56 stub.setValue(ReqSetValue(elementId=targetObj, stringValue=testString))
57 response = stub.getValue(ReqGetValue(elementId=targetObj))
58 if response.stringValue != testString:
61 stub.clear(ReqClear(elementId=targetObj))
63 response = stub.getValue(ReqGetValue(elementId=targetObj))
64 if response.stringValue != '':
69 def getSizeTest(stub):
70 response = stub.findElement(ReqFindElement(textField='Button'))
71 print("els", response)
72 for el in response.elements:
73 response = stub.getSize(ReqGetSize(elementId=el.elementId))
75 return response.size.width + response.size.height > 0
78 def getAttributeTest(stub):
79 response = stub.findElement(ReqFindElement(textField='Button'))
80 if len(response.elements) <= 0: return False
88 ['SCROLLABLE', False],
96 for el in response.elements:
97 for attr in checkList:
98 if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute=attr[0])).boolValue != attr[1]:
101 if isFailed == True: return False
103 response = stub.findElement(ReqFindElement(textField='Check'))
104 if len(response.elements) <= 0: return False
112 ['SCROLLABLE', False],
113 ['CHECKABLE', False],
116 ['SELECTABLE', True],
120 for el in response.elements:
121 for attr in checkList:
122 if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute=attr[0])).boolValue != attr[1]:
125 return isFailed == False
128 response = stub.findElement(ReqFindElement(textField='Accessibility'))
129 if len(response.elements) <= 0: return False
131 for el in response.elements:
132 stub.click(ReqClick(elementId=el.elementId, type='ELEMENTID'))
134 response = stub.findElement(ReqFindElement(textField='Screen Reader'))
135 if len(response.elements) <= 0: return False
137 for el in response.elements:
138 stub.click(ReqClick(coordination=Point(x=320, y=130), type='COORD'))
140 response = stub.findElement(ReqFindElement(textField='UI Descriptions'))
141 if len(response.elements) <= 0: return False
145 def longClickTest(stub):
146 response = stub.sendKey(ReqKey(type='HOME', actionType='STROKE'))
147 stub.click(ReqClick(coordination=Point(x=160, y=160), type='COORD'))
148 # TODO : find out something changed
152 response = stub.findElement(ReqFindElement(textField='Bg', isShowing=True))
153 if len(response.elements) <= 0: return False
154 targetObj = response.elements[0].elementId
156 for tryCnt in range(10):
157 print('Flick to bottom to find "Spinner" item @ tries:', tryCnt)
158 stub.flick(ReqFlick(startPoint=Point(x=160, y=359), endPoint=Point(x=160, y=1), durationMs=110))
159 response = stub.findElement(ReqFindElement(textField='Spinner'))
162 if len(response.elements) > 0:
163 for el in response.elements:
164 if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute='SHOWING')).boolValue: return True
169 res = stub.touchDown(ReqTouchDown(coordination=Point(x=160,y=640)))
172 if seq < 0: return False
173 for yy in range(640, 30, -10):
174 stub.touchMove(ReqTouchMove(coordination=Point(x=160,y=yy), seqId=seq))
175 stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=seq))
180 def get_file_chunks(filename):
181 CHUNK_SIZE = 1024 * 1024
182 with open(filename, 'rb') as f:
184 piece = f.read(CHUNK_SIZE)
187 yield ReqInstallApp(package=piece)
190 def installAppTest(stub):
191 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
192 if (response.isInstalled): return True
194 tpkFile = './org.tizen.uicomponents.arm.tpk'
195 binaryChunk = get_file_chunks(tpkFile)
196 response = stub.installApp(binaryChunk)
198 for waitCnt in range(10):
199 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
200 print('tries:', waitCnt, 'isInstalled:', response.isInstalled)
202 if response.isInstalled: return True
205 def removeAppTest(stub):
206 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
207 if (response.isInstalled): response = stub.removeApp(ReqRemoveApp(packageName='org.example.uicomponents'))
208 for waitCnt in range(10):
209 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
210 print('tries:', waitCnt, 'isInstalled:', response.isInstalled)
212 if response.isInstalled != True: return True
215 def getAppInfoTest(stub):
216 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning
218 def launchAppTest(stub):
219 print('launch result', stub.launchApp(ReqLaunchApp(packageName='org.example.uicomponents')))
221 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning
223 def closeAppTest(stub):
224 print('close result',stub.closeApp(ReqCloseApp(packageName='org.example.uicomponents')))
225 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning != True
227 def sendKeyTest(stub):
228 response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE'))
230 response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE'))
232 response = stub.sendKey(ReqKey(type='WHEELDOWN', actionType='STROKE'))
234 response = stub.sendKey(ReqKey(type='POWER', actionType='STROKE'))
236 response = stub.sendKey(ReqKey(type='POWER', actionType='STROKE'))
238 response = stub.sendKey(ReqKey(type='BACK', actionType='STROKE'))
240 response = stub.sendKey(ReqKey(type='MENU', actionType='STROKE'))
244 def getDeviceTimeTest(stub):
245 response1 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK'))
246 response2 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK'))
247 print(response1, response2)
248 return response2.timestampUTC > response1.timestampUTC;
250 def getLocationTest(stub):
251 response = stub.getLocation(ReqGetLocation())
253 if response.alt < 0: return False
254 if response.lat < 0: return False
257 def takeScreenshotTest(stub):
258 responses = stub.takeScreenshot(ReqTakeScreenshot())
259 image = open("screenshot.png", "wb")
260 for response in responses:
261 image.write(response.image)
265 def defaultSetup(stub):
266 if stub.getAppInfo(ReqGetAppInfo(packageName='org.tizen.elm-demo-tizen-mobile')).isRunning:
267 stub.closeApp(ReqCloseApp(packageName='org.tizen.elm-demo-tizen-mobile'))
269 stub.launchApp(ReqLaunchApp(packageName='org.tizen.elm-demo-tizen-mobile'))
271 def defaultTearDown(stub):
272 stub.closeApp(ReqCloseApp(packageName='org.tizen.elm-demo-tizen-mobile'))
274 def runTest(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown, alwaySucceed=False):
275 print("Testing started :", testFunc)
278 result = testFunc(stub)
281 print("Testing result :", result)
282 if alwaySucceed: return True
283 assert True == result
285 def runTestWithoutSetupAndTearDown(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown):
289 runTest(stub, testFunc, Empty, Empty)
293 with grpc.insecure_channel('127.0.0.1:50051') as channel:
294 stub = BootstrapStub(channel)
296 runTest(stub, getDeviceTimeTest)
297 runTest(stub, findElementTest)
298 runTest(stub, getValueTest)
299 runTest(stub, getSizeTest)
300 runTest(stub, getAttributeTest)
301 runTest(stub, clickTest)
302 runTest(stub, flickTest)
303 runTest(stub, touchTest)
304 runTest(stub, sendKeyTest)
305 runTest(stub, setValueClearTest)
306 runTest(stub, takeScreenshotTest)
307 runTest(stub, longClickTest, alwaySucceed=True)
308 runTest(stub, getLocationTest, alwaySucceed=True)
310 runTestWithoutSetupAndTearDown(stub, installAppTest)
311 runTestWithoutSetupAndTearDown(stub, launchAppTest)
312 runTestWithoutSetupAndTearDown(stub, getAppInfoTest)
313 runTestWithoutSetupAndTearDown(stub, closeAppTest)
314 runTestWithoutSetupAndTearDown(stub, removeAppTest)
316 if __name__ == '__main__':
317 logging.basicConfig()