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],
101 for el in response.elements:
102 for attr in checkList:
103 if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute=attr[0])).boolValue != attr[1]:
106 if isFailed == True: return False
108 response = stub.findElement(ReqFindElement(textField='Internal Legacy'))
109 if len(response.elements) <= 0: return False
117 ['SCROLLABLE', False],
118 ['CHECKABLE', False],
121 ['SELECTABLE', True],
126 for el in response.elements:
127 for attr in checkList:
128 if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute=attr[0])).boolValue != attr[1]:
131 return isFailed == False
134 response = stub.findElement(ReqFindElement(textField='Widgets'))
135 if len(response.elements) <= 0: return False
137 for el in response.elements:
138 stub.click(ReqClick(elementId=el.elementId, type='ELEMENTID'))
140 response = stub.findElement(ReqFindElement(textField='Box'))
141 if len(response.elements) <= 0: return False
143 for el in response.elements:
144 stub.click(ReqClick(coordination=Point(x=160, y=160), type='COORD'))
146 response = stub.findElement(ReqFindElement(textField='Vertical Box'))
147 if len(response.elements) <= 0: return False
151 def longClickTest(stub):
152 response = stub.sendKey(ReqKey(type='HOME', actionType='STROKE'))
153 stub.click(ReqClick(coordination=Point(x=160, y=160), type='COORD'))
154 # TODO : find out something changed
158 response = stub.findElement(ReqFindElement(textField='Widgets'))
159 if len(response.elements) <= 0:
162 for el in response.elements:
164 stub.click(ReqClick(elementId=el.elementId, type='ELEMENTID'))
167 response = stub.findElement(ReqFindElement(textField='Box', isShowing=True))
168 if len(response.elements) <= 0: return False
169 targetObj = response.elements[0].elementId
171 for tryCnt in range(10):
172 print('Flick to bottom to find "Spinner" item @ tries:', tryCnt)
173 stub.flick(ReqFlick(startPoint=Point(x=160, y=359), endPoint=Point(x=160, y=1), durationMs=350))
174 response = stub.findElement(ReqFindElement(textField='Spinner.*'))
177 if len(response.elements) > 0: return True
182 stub.touchDown(ReqTouchDown(coordination=Point(x=160,y=330)))
183 for yy in range(330, 30, -10):
184 stub.touchMove(ReqTouchMove(coordination=Point(x=160,y=yy)))
185 stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30)))
190 def get_file_chunks(filename):
191 CHUNK_SIZE = 1024 * 1024
192 with open(filename, 'rb') as f:
194 piece = f.read(CHUNK_SIZE)
197 yield ReqInstallApp(package=piece)
200 def installAppTest(stub):
201 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
202 if (response.isInstalled): return True
204 tpkFile = './org.tizen.uicomponents.arm.tpk'
205 binaryChunk = get_file_chunks(tpkFile)
206 response = stub.installApp(binaryChunk)
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: return True
215 def removeAppTest(stub):
216 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
217 if (response.isInstalled): response = stub.removeApp(ReqRemoveApp(packageName='org.example.uicomponents'))
218 for waitCnt in range(10):
219 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
220 print('tries:', waitCnt, 'isInstalled:', response.isInstalled)
222 if response.isInstalled != True: return True
225 def getAppInfoTest(stub):
226 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning
228 def launchAppTest(stub):
229 print('launch result', stub.launchApp(ReqLaunchApp(packageName='org.example.uicomponents')))
231 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning
233 def closeAppTest(stub):
234 print('close result',stub.closeApp(ReqCloseApp(packageName='org.example.uicomponents')))
235 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning != True
237 def sendKeyTest(stub):
238 response = stub.sendKey(ReqKey(type='POWER', actionType='STROKE'))
240 response = stub.sendKey(ReqKey(type='POWER', actionType='STROKE'))
242 response = stub.sendKey(ReqKey(type='BACK', actionType='STROKE'))
244 response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE'))
246 response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE'))
248 response = stub.sendKey(ReqKey(type='WHEELDOWN', actionType='STROKE'))
252 def scrollToTest(stub):
253 print('scrollTo command not implemented')
256 def getDeviceTimeTest(stub):
257 response1 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK'))
258 response2 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK'))
259 print(response1, response2)
260 return response2.timestampUTC > response1.timestampUTC;
262 def getLocationTest(stub):
263 response = stub.getLocation(ReqGetLocation())
265 if response.alt < 0: return False
266 if response.lat < 0: return False
269 def defaultSetup(stub):
270 if stub.getAppInfo(ReqGetAppInfo(packageName='com.samsung.ui-widget-sample')).isRunning:
271 stub.closeApp(ReqCloseApp(packageName='com.samsung.ui-widget-sample'))
273 stub.launchApp(ReqLaunchApp(packageName='com.samsung.ui-widget-sample'))
275 def defaultTearDown(stub):
276 stub.closeApp(ReqCloseApp(packageName='com.samsung.ui-widget-sample'))
278 def runTest(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown, alwaySucceed=False):
279 print("Testing started :", testFunc)
282 result = testFunc(stub)
285 if alwaySucceed: return True
286 assert True == result
288 def runTestWithoutSetupAndTearDown(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown):
292 runTest(stub, testFunc, Empty, Empty)
296 with grpc.insecure_channel('127.0.0.1:50051') as channel:
297 stub = BootstrapStub(channel)
299 runTest(stub, getDeviceTimeTest)
301 runTest(stub, findElementTest)
302 runTest(stub, getValueTest)
303 runTest(stub, getSizeTest)
304 runTest(stub, getAttributeTest)
305 runTest(stub, clickTest)
306 runTest(stub, flickTest)
307 runTest(stub, touchTest)
308 runTest(stub, sendKeyTest)
309 runTest(stub, setValueClearTest)
310 runTestWithoutSetupAndTearDown(stub, installAppTest)
311 runTestWithoutSetupAndTearDown(stub, launchAppTest)
312 runTestWithoutSetupAndTearDown(stub, getAppInfoTest)
313 runTestWithoutSetupAndTearDown(stub, closeAppTest)
314 runTestWithoutSetupAndTearDown(stub, removeAppTest)
316 runTest(stub, longClickTest, alwaySucceed=True)
317 runTest(stub, getLocationTest, alwaySucceed=True)
319 runTest(stub, scrollToTest, alwaySucceed=True)
321 if __name__ == '__main__':
322 logging.basicConfig()