1 from __future__ import print_function
4 sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(os.path.dirname(__file__)))))
5 from __future__ import print_function
6 from aurum_pb2 import *
7 from aurum_pb2_grpc import BootstrapStub
12 def findElementTest(stub):
13 response = stub.findElement(ReqFindElement(isClickable=True))
14 for el in response.elements:
18 def getValueTest(stub):
19 response = stub.findElement(ReqFindElement(textField='Button'))
20 print("els", response)
21 for el in response.elements:
22 response = stub.getValue(ReqGetValue(elementId=el.elementId))
23 return response.stringValue == 'Button'
26 def setValueClearTest(stub):
28 if size.x < 0: return False
29 if size.y < 0: return False
30 if size.x >= 720: return False
31 if size.y >= 1280: 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'))
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='Singleline Entry'))
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(widgetType='Elm_Entry'))
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 != '':
73 def getSizeTest(stub):
74 response = stub.findElement(ReqFindElement(textField='Button'))
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='Button'))
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='Check'))
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='Accessibility'))
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='Screen Reader'))
139 if len(response.elements) <= 0: return False
141 for el in response.elements:
142 stub.click(ReqClick(coordination=Point(x=320, y=130), type='COORD'))
144 response = stub.findElement(ReqFindElement(textField='UI Descriptions'))
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='Bg', isShowing=True))
157 if len(response.elements) <= 0: return False
158 targetObj = response.elements[0].elementId
160 for tryCnt in range(10):
161 print('Flick to bottom to find "Spinner" item @ tries:', tryCnt)
162 stub.flick(ReqFlick(startPoint=Point(x=160, y=359), endPoint=Point(x=160, y=1), durationMs=110))
163 response = stub.findElement(ReqFindElement(textField='Spinner'))
166 if len(response.elements) > 0:
167 for el in response.elements:
168 if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute='SHOWING')).boolValue: return True
173 res = stub.touchDown(ReqTouchDown(coordination=Point(x=160,y=640)))
176 if seq < 0: return False
177 for yy in range(640, 30, -10):
178 stub.touchMove(ReqTouchMove(coordination=Point(x=160,y=yy), seqId=seq))
179 stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=seq))
184 def get_file_chunks(filename):
185 CHUNK_SIZE = 1024 * 1024
186 with open(filename, 'rb') as f:
188 piece = f.read(CHUNK_SIZE)
191 yield ReqInstallApp(package=piece)
194 def installAppTest(stub):
195 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
196 if (response.isInstalled): return True
198 tpkFile = './org.tizen.uicomponents.arm.tpk'
199 binaryChunk = get_file_chunks(tpkFile)
200 response = stub.installApp(binaryChunk)
202 for waitCnt in range(10):
203 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
204 print('tries:', waitCnt, 'isInstalled:', response.isInstalled)
206 if response.isInstalled: return True
209 def removeAppTest(stub):
210 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
211 if (response.isInstalled): response = stub.removeApp(ReqRemoveApp(packageName='org.example.uicomponents'))
212 for waitCnt in range(10):
213 response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents'))
214 print('tries:', waitCnt, 'isInstalled:', response.isInstalled)
216 if response.isInstalled != True: return True
219 def getAppInfoTest(stub):
220 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning
222 def launchAppTest(stub):
223 print('launch result', stub.launchApp(ReqLaunchApp(packageName='org.example.uicomponents')))
225 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning
227 def closeAppTest(stub):
228 print('close result',stub.closeApp(ReqCloseApp(packageName='org.example.uicomponents')))
229 return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning != True
231 def sendKeyTest(stub):
232 response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE'))
234 response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE'))
236 response = stub.sendKey(ReqKey(type='WHEELDOWN', actionType='STROKE'))
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='MENU', actionType='STROKE'))
248 def getDeviceTimeTest(stub):
249 response1 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK'))
250 response2 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK'))
251 print(response1, response2)
252 return response2.timestampUTC > response1.timestampUTC;
254 def getLocationTest(stub):
255 response = stub.getLocation(ReqGetLocation())
257 if response.alt < 0: return False
258 if response.lat < 0: return False
261 def takeScreenshotTest(stub):
262 responses = stub.takeScreenshot(ReqTakeScreenshot())
263 image = open("screenshot.png", "wb")
264 for response in responses:
265 image.write(response.image)
269 def defaultSetup(stub):
270 if stub.getAppInfo(ReqGetAppInfo(packageName='org.tizen.elm-demo-tizen-mobile')).isRunning:
271 stub.closeApp(ReqCloseApp(packageName='org.tizen.elm-demo-tizen-mobile'))
273 stub.launchApp(ReqLaunchApp(packageName='org.tizen.elm-demo-tizen-mobile'))
275 def defaultTearDown(stub):
276 stub.closeApp(ReqCloseApp(packageName='org.tizen.elm-demo-tizen-mobile'))
278 def runTest(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown, alwaySucceed=False):
279 print("Testing started :", testFunc)
282 result = testFunc(stub)
285 print("Testing result :", result)
286 if alwaySucceed: return True
287 assert True == result
289 def runTestWithoutSetupAndTearDown(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown):
293 runTest(stub, testFunc, Empty, Empty)
297 with grpc.insecure_channel('127.0.0.1:50051') as channel:
298 stub = BootstrapStub(channel)
300 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 runTest(stub, takeScreenshotTest)
311 runTest(stub, longClickTest, alwaySucceed=True)
312 runTest(stub, getLocationTest, alwaySucceed=True)
314 runTestWithoutSetupAndTearDown(stub, installAppTest)
315 runTestWithoutSetupAndTearDown(stub, launchAppTest)
316 runTestWithoutSetupAndTearDown(stub, getAppInfoTest)
317 runTestWithoutSetupAndTearDown(stub, closeAppTest)
318 runTestWithoutSetupAndTearDown(stub, removeAppTest)
320 if __name__ == '__main__':
321 logging.basicConfig()