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='Widgets'))
16 print("els", response)
17 for el in response.elements:
18 response = stub.getValue(ReqGetValue(elementId=el.elementId))
19 return response.stringValue == 'Widgets'
22 def setValueClearTest(stub):
23 response = stub.findElement(ReqFindElement(textField='Widgets'))
24 if len(response.elements) <= 0: return False
25 stub.click(ReqClick(type='ELEMENTID', elementId=response.elements[0].elementId))
28 if size.x < 0: return False
29 if size.y < 0: return False
30 if size.x >= 360: return False
31 if size.y >= 360: return False
34 for tryCnt in range(10):
35 stub.flick(ReqFlick(startPoint=Point(x=160, y=350), endPoint=Point(x=160, y=10), durationMs=500))
36 response = stub.findElement(ReqFindElement(textField='Entry/Editfield.*'))
37 if len(response.elements) <= 0: continue
38 targetObj = response.elements[0].elementId
39 response = stub.getSize(ReqGetSize(elementId=targetObj))
40 if inScreen(response.size):
41 stub.click(ReqClick(type='ELEMENTID', elementId=targetObj))
44 for tryCnt in range(10):
45 stub.flick(ReqFlick(startPoint=Point(x=160, y=350), endPoint=Point(x=160, y=10), durationMs=500))
46 response = stub.findElement(ReqFindElement(textField='Editable'))
47 if len(response.elements) <= 0: continue
48 targetObj = response.elements[0].elementId
49 response = stub.getSize(ReqGetSize(elementId=targetObj))
50 isShowing = stub.getAttribute(ReqGetAttribute(elementId=targetObj, attribute='SHOWING')).boolValue
51 if inScreen(response.size) or isShowing:
52 stub.click(ReqClick(type='ELEMENTID', elementId=targetObj))
55 response = stub.findElement(ReqFindElement(textField='editable'))
56 if len(response.elements) <= 0: return False
57 targetObj = response.elements[0].elementId
59 testString = 'set test string by calling SetValue Method'
60 stub.setValue(ReqSetValue(elementId=targetObj, stringValue=testString))
61 response = stub.getValue(ReqGetValue(elementId=targetObj))
62 if response.stringValue != testString:
65 stub.clear(ReqClear(elementId=targetObj))
67 response = stub.getValue(ReqGetValue(elementId=targetObj))
68 if response.stringValue != 'editable':
73 def getSizeTest(stub):
74 response = stub.findElement(ReqFindElement(textField='Widgets'))
75 print("els", response)
76 for el in response.elements:
77 response = stub.getSize(ReqGetSize(elementId=el.elementId))
79 return response.size.width + response.size.height > 0
82 def getAttributeTest(stub):
83 response = stub.findElement(ReqFindElement(textField='Widgets'))
84 if len(response.elements) <= 0: return False
92 ['SCROLLABLE', False],
100 for el in response.elements:
101 for attr in checkList:
102 if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute=attr[0])).boolValue != attr[1]:
105 if isFailed == True: return False
107 response = stub.findElement(ReqFindElement(textField='Internal Legacy'))
108 if len(response.elements) <= 0: return False
116 ['SCROLLABLE', False],
117 ['CHECKABLE', False],
120 ['SELECTABLE', True],
124 for el in response.elements:
125 for attr in checkList:
126 if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute=attr[0])).boolValue != attr[1]:
129 return isFailed == False
132 response = stub.findElement(ReqFindElement(textField='Widgets'))
133 if len(response.elements) <= 0: return False
135 for el in response.elements:
136 stub.click(ReqClick(elementId=el.elementId, type='ELEMENTID'))
138 response = stub.findElement(ReqFindElement(textField='Box'))
139 if len(response.elements) <= 0: return False
141 for el in response.elements:
142 stub.click(ReqClick(coordination=Point(x=160, y=160), type='COORD'))
144 response = stub.findElement(ReqFindElement(textField='Vertical Box'))
145 if len(response.elements) <= 0: return False
149 def longClickTest(stub):
150 response = stub.sendKey(ReqKey(type='HOME', actionType='STROKE'))
151 stub.click(ReqClick(coordination=Point(x=160, y=160), type='COORD'))
152 # TODO : find out something changed
156 response = stub.findElement(ReqFindElement(textField='Widgets'))
157 if len(response.elements) <= 0:
160 for el in response.elements:
162 stub.click(ReqClick(elementId=el.elementId, type='ELEMENTID'))
165 response = stub.findElement(ReqFindElement(textField='Box', isShowing=True))
166 if len(response.elements) <= 0: return False
167 targetObj = response.elements[0].elementId
169 for tryCnt in range(10):
170 print('Flick to bottom to find "Spinner" item @ tries:', tryCnt)
171 stub.flick(ReqFlick(startPoint=Point(x=160, y=359), endPoint=Point(x=160, y=1), durationMs=350))
172 response = stub.findElement(ReqFindElement(textField='Spinner.*'))
175 if len(response.elements) > 0: return True
180 res = stub.touchDown(ReqTouchDown(coordination=Point(x=160,y=330)))
183 if seq < 0: return False
184 for yy in range(330, 30, -10):
185 stub.touchMove(ReqTouchMove(coordination=Point(x=160,y=yy), seqId=seq))
186 stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=seq))
191 def get_file_chunks(filename):
192 CHUNK_SIZE = 1024 * 1024
193 with open(filename, 'rb') as f:
195 piece = f.read(CHUNK_SIZE)
198 yield ReqInstallApp(package=piece)
201 def installAppTest(stub):
202 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
203 if (response.isInstalled): return True
205 tpkFile = './org.tizen.uicomponents.arm.tpk'
206 binaryChunk = get_file_chunks(tpkFile)
207 response = stub.installApp(binaryChunk)
209 for waitCnt in range(10):
210 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
211 print('tries:', waitCnt, 'isInstalled:', response.isInstalled)
213 if response.isInstalled: return True
216 def removeAppTest(stub):
217 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
218 if (response.isInstalled): response = stub.removeApp(ReqRemoveApp(packageName='org.example.uicomponents'))
219 for waitCnt in range(10):
220 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
221 print('tries:', waitCnt, 'isInstalled:', response.isInstalled)
223 if response.isInstalled != True: return True
226 def getAppInfoTest(stub):
227 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning
229 def launchAppTest(stub):
230 print('launch result', stub.launchApp(ReqLaunchApp(packageName='org.example.uicomponents')))
232 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning
234 def closeAppTest(stub):
235 print('close result',stub.closeApp(ReqCloseApp(packageName='org.example.uicomponents')))
236 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning != True
238 def sendKeyTest(stub):
239 response = stub.sendKey(ReqKey(type='POWER', actionType='STROKE'))
241 response = stub.sendKey(ReqKey(type='POWER', actionType='STROKE'))
243 response = stub.sendKey(ReqKey(type='BACK', actionType='STROKE'))
245 response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE'))
247 response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE'))
249 response = stub.sendKey(ReqKey(type='WHEELDOWN', actionType='STROKE'))
253 def scrollToTest(stub):
254 print('scrollTo command not implemented')
257 def getDeviceTimeTest(stub):
258 response1 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK'))
259 response2 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK'))
260 print(response1, response2)
261 return response2.timestampUTC > response1.timestampUTC;
263 def getLocationTest(stub):
264 response = stub.getLocation(ReqGetLocation())
266 if response.alt < 0: return False
267 if response.lat < 0: return False
270 def takeScreenshotTest(stub):
271 responses = stub.takeScreenshot(ReqTakeScreenshot())
272 image = open("screenshot.png", "wb")
273 for response in responses:
274 image.write(response.image)
278 def defaultSetup(stub):
279 if stub.getAppInfo(ReqGetAppInfo(packageName='com.samsung.ui-widget-sample')).isRunning:
280 stub.closeApp(ReqCloseApp(packageName='com.samsung.ui-widget-sample'))
282 stub.launchApp(ReqLaunchApp(packageName='com.samsung.ui-widget-sample'))
284 def defaultTearDown(stub):
285 stub.closeApp(ReqCloseApp(packageName='com.samsung.ui-widget-sample'))
287 def runTest(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown, alwaySucceed=False):
288 print("Testing started :", testFunc)
291 result = testFunc(stub)
294 if alwaySucceed: return True
295 assert True == result
297 def runTestWithoutSetupAndTearDown(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown):
301 runTest(stub, testFunc, Empty, Empty)
305 with grpc.insecure_channel('127.0.0.1:50051') as channel:
306 stub = BootstrapStub(channel)
308 runTest(stub, getDeviceTimeTest)
310 runTest(stub, findElementTest)
311 runTest(stub, getValueTest)
312 runTest(stub, getSizeTest)
313 runTest(stub, getAttributeTest)
314 runTest(stub, clickTest)
315 runTest(stub, flickTest)
316 runTest(stub, touchTest)
317 runTest(stub, sendKeyTest)
318 runTest(stub, setValueClearTest)
319 runTest(stub, takeScreenshotTest)
320 runTestWithoutSetupAndTearDown(stub, installAppTest)
321 runTestWithoutSetupAndTearDown(stub, launchAppTest)
322 runTestWithoutSetupAndTearDown(stub, getAppInfoTest)
323 runTestWithoutSetupAndTearDown(stub, closeAppTest)
324 runTestWithoutSetupAndTearDown(stub, removeAppTest)
326 runTest(stub, longClickTest, alwaySucceed=True)
327 runTest(stub, getLocationTest, alwaySucceed=True)
329 runTest(stub, scrollToTest, alwaySucceed=True)
331 if __name__ == '__main__':
332 logging.basicConfig()