From: Woochanlee Date: Thu, 27 May 2021 10:45:10 +0000 (+0900) Subject: protocol: Add mobile demo test script and application RPM X-Git-Tag: submit/tizen/20210629.075325~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=afe83c0fe49f8e41c98be8318db4a8ed6ee88bfb;p=platform%2Fcore%2Fuifw%2Faurum.git protocol: Add mobile demo test script and application RPM Change-Id: If8224d09786622c35d4e1643075c12f0a14a5770 --- diff --git a/protocol/examples/python/mobileDemoTestTM1/mobileDemoTest.py b/protocol/examples/python/mobileDemoTestTM1/mobileDemoTest.py new file mode 100644 index 0000000..622aed7 --- /dev/null +++ b/protocol/examples/python/mobileDemoTestTM1/mobileDemoTest.py @@ -0,0 +1,318 @@ +from __future__ import print_function +from aurum_pb2 import * +from aurum_pb2_grpc import BootstrapStub +import logging +import grpc +import time + +def findElementTest(stub): + response = stub.findElement(ReqFindElement(isClickable=True)) + for el in response.elements: + return True + return False + +def getValueTest(stub): + response = stub.findElement(ReqFindElement(textField='Button')) + print("els", response) + for el in response.elements: + response = stub.getValue(ReqGetValue(elementId=el.elementId)) + return response.stringValue == 'Button' + return False + +def setValueClearTest(stub): + def inScreen(size): + if size.x < 0: return False + if size.y < 0: return False + if size.x >= 720: return False + if size.y >= 1280: return False + return True + + for tryCnt in range(10): + stub.flick(ReqFlick(startPoint=Point(x=160, y=350), endPoint=Point(x=160, y=10), durationMs=500)) + response = stub.findElement(ReqFindElement(textField='Entry')) + if len(response.elements) <= 0: continue + targetObj = response.elements[0].elementId + response = stub.getSize(ReqGetSize(elementId=targetObj)) + if inScreen(response.size): + stub.click(ReqClick(type='ELEMENTID', elementId=targetObj)) + break + + for tryCnt in range(10): + stub.flick(ReqFlick(startPoint=Point(x=160, y=350), endPoint=Point(x=160, y=10), durationMs=500)) + response = stub.findElement(ReqFindElement(textField='Singleline Entry')) + if len(response.elements) <= 0: continue + targetObj = response.elements[0].elementId + response = stub.getSize(ReqGetSize(elementId=targetObj)) + isShowing = stub.getAttribute(ReqGetAttribute(elementId=targetObj, attribute='SHOWING')).boolValue + if inScreen(response.size) or isShowing: + stub.click(ReqClick(type='ELEMENTID', elementId=targetObj)) + break + + response = stub.findElement(ReqFindElement(widgetType='Elm_Entry')) + if len(response.elements) <= 0: return False + targetObj = response.elements[0].elementId + + testString = 'set test string by calling SetValue Method' + stub.setValue(ReqSetValue(elementId=targetObj, stringValue=testString)) + response = stub.getValue(ReqGetValue(elementId=targetObj)) + if response.stringValue != testString: + return False + + stub.clear(ReqClear(elementId=targetObj)) + + response = stub.getValue(ReqGetValue(elementId=targetObj)) + if response.stringValue != '': + return False + + return True + +def getSizeTest(stub): + response = stub.findElement(ReqFindElement(textField='Button')) + print("els", response) + for el in response.elements: + response = stub.getSize(ReqGetSize(elementId=el.elementId)) + print(response) + return response.size.width + response.size.height > 0 + return False + +def getAttributeTest(stub): + response = stub.findElement(ReqFindElement(textField='Button')) + if len(response.elements) <= 0: return False + + checkList = [ + ['VISIBLE', True], + ['FOCUSABLE', True], + ['FOCUSED', False], + ['ENABLED', True], + ['CLICKABLE', True], + ['SCROLLABLE', False], + ['CHECKABLE', False], + ['CHECKED', False], + ['SELECTED', False], + ['SELECTABLE',True], + ['SHOWING', True], + ] + isFailed = False + for el in response.elements: + for attr in checkList: + if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute=attr[0])).boolValue != attr[1]: + isFailed = True + + if isFailed == True: return False + + response = stub.findElement(ReqFindElement(textField='Check')) + if len(response.elements) <= 0: return False + + checkList = [ + ['VISIBLE', True], + ['FOCUSABLE', True], + ['FOCUSED', False], + ['ENABLED', True], + ['CLICKABLE', True], + ['SCROLLABLE', False], + ['CHECKABLE', False], + ['CHECKED', False], + ['SELECTED', False], + ['SELECTABLE', True], + ['SHOWING', True], + ] + isFailed = False + for el in response.elements: + for attr in checkList: + if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute=attr[0])).boolValue != attr[1]: + isFailed = True + + return isFailed == False + +def clickTest(stub): + response = stub.findElement(ReqFindElement(textField='Accessibility')) + if len(response.elements) <= 0: return False + + for el in response.elements: + stub.click(ReqClick(elementId=el.elementId, type='ELEMENTID')) + + response = stub.findElement(ReqFindElement(textField='Screen Reader')) + if len(response.elements) <= 0: return False + + for el in response.elements: + stub.click(ReqClick(coordination=Point(x=320, y=130), type='COORD')) + + response = stub.findElement(ReqFindElement(textField='UI Descriptions')) + if len(response.elements) <= 0: return False + + return True + +def longClickTest(stub): + response = stub.sendKey(ReqKey(type='HOME', actionType='STROKE')) + stub.click(ReqClick(coordination=Point(x=160, y=160), type='COORD')) + # TODO : find out something changed + return False + +def flickTest(stub): + response = stub.findElement(ReqFindElement(textField='Bg', isShowing=True)) + if len(response.elements) <= 0: return False + targetObj = response.elements[0].elementId + + for tryCnt in range(10): + print('Flick to bottom to find "Spinner" item @ tries:', tryCnt) + stub.flick(ReqFlick(startPoint=Point(x=160, y=359), endPoint=Point(x=160, y=1), durationMs=110)) + response = stub.findElement(ReqFindElement(textField='Spinner')) + time.sleep(0.01) + print(response) + if len(response.elements) > 0: + for el in response.elements: + if stub.getAttribute(ReqGetAttribute(elementId=el.elementId, attribute='SHOWING')).boolValue: return True + + return False + +def touchTest(stub): + res = stub.touchDown(ReqTouchDown(coordination=Point(x=160,y=640))) + print(res) + seq = res.seqId + if seq < 0: return False + for yy in range(640, 30, -10): + stub.touchMove(ReqTouchMove(coordination=Point(x=160,y=yy), seqId=seq)) + stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=seq)) + + return True + + +def get_file_chunks(filename): + CHUNK_SIZE = 1024 * 1024 + with open(filename, 'rb') as f: + while True: + piece = f.read(CHUNK_SIZE) + if len(piece) == 0: + return + yield ReqInstallApp(package=piece) + + +def installAppTest(stub): + response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')) + if (response.isInstalled): return True + + tpkFile = './org.tizen.uicomponents.arm.tpk' + binaryChunk = get_file_chunks(tpkFile) + response = stub.installApp(binaryChunk) + + for waitCnt in range(10): + response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')) + print('tries:', waitCnt, 'isInstalled:', response.isInstalled) + time.sleep(1) + if response.isInstalled: return True + return False + +def removeAppTest(stub): + response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')) + if (response.isInstalled): response = stub.removeApp(ReqRemoveApp(packageName='org.example.uicomponents')) + for waitCnt in range(10): + response = stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')) + print('tries:', waitCnt, 'isInstalled:', response.isInstalled) + time.sleep(1) + if response.isInstalled != True: return True + return False + +def getAppInfoTest(stub): + return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning + +def launchAppTest(stub): + print('launch result', stub.launchApp(ReqLaunchApp(packageName='org.example.uicomponents'))) + + return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning + +def closeAppTest(stub): + print('close result',stub.closeApp(ReqCloseApp(packageName='org.example.uicomponents'))) + return stub.getAppInfo(ReqGetAppInfo(packageName='org.example.uicomponents')).isRunning != True + +def sendKeyTest(stub): + response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE')) + time.sleep(0.3) + response = stub.sendKey(ReqKey(type='WHEELUP', actionType='STROKE')) + time.sleep(0.3) + response = stub.sendKey(ReqKey(type='WHEELDOWN', actionType='STROKE')) + time.sleep(0.3) + response = stub.sendKey(ReqKey(type='POWER', actionType='STROKE')) + time.sleep(1) + response = stub.sendKey(ReqKey(type='POWER', actionType='STROKE')) + time.sleep(1) + response = stub.sendKey(ReqKey(type='BACK', actionType='STROKE')) + time.sleep(1) + response = stub.sendKey(ReqKey(type='MENU', actionType='STROKE')) + time.sleep(1) + return True + +def getDeviceTimeTest(stub): + response1 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK')) + response2 = stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK')) + print(response1, response2) + return response2.timestampUTC > response1.timestampUTC; + +def getLocationTest(stub): + response = stub.getLocation(ReqGetLocation()) + + if response.alt < 0: return False + if response.lat < 0: return False + return True + +def takeScreenshotTest(stub): + responses = stub.takeScreenshot(ReqTakeScreenshot()) + image = open("screenshot.png", "wb") + for response in responses: + image.write(response.image) + image.close() + return True; + +def defaultSetup(stub): + if stub.getAppInfo(ReqGetAppInfo(packageName='org.tizen.elm-demo-tizen-mobile')).isRunning: + stub.closeApp(ReqCloseApp(packageName='org.tizen.elm-demo-tizen-mobile')) + + stub.launchApp(ReqLaunchApp(packageName='org.tizen.elm-demo-tizen-mobile')) + +def defaultTearDown(stub): + stub.closeApp(ReqCloseApp(packageName='org.tizen.elm-demo-tizen-mobile')) + +def runTest(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown, alwaySucceed=False): + print("Testing started :", testFunc) + + setup(stub) + result = testFunc(stub) + tearDown(stub) + + print("Testing result :", result) + if alwaySucceed: return True + assert True == result + +def runTestWithoutSetupAndTearDown(stub, testFunc, setup=defaultSetup, tearDown=defaultTearDown): + def Empty(stub): + pass + + runTest(stub, testFunc, Empty, Empty) + + +def run(): + with grpc.insecure_channel('127.0.0.1:50051') as channel: + stub = BootstrapStub(channel) + + runTest(stub, getDeviceTimeTest) + runTest(stub, findElementTest) + runTest(stub, getValueTest) + runTest(stub, getSizeTest) + runTest(stub, getAttributeTest) + runTest(stub, clickTest) + runTest(stub, flickTest) + runTest(stub, touchTest) + runTest(stub, sendKeyTest) + runTest(stub, setValueClearTest) + runTest(stub, takeScreenshotTest) + runTest(stub, longClickTest, alwaySucceed=True) + runTest(stub, getLocationTest, alwaySucceed=True) + + runTestWithoutSetupAndTearDown(stub, installAppTest) + runTestWithoutSetupAndTearDown(stub, launchAppTest) + runTestWithoutSetupAndTearDown(stub, getAppInfoTest) + runTestWithoutSetupAndTearDown(stub, closeAppTest) + runTestWithoutSetupAndTearDown(stub, removeAppTest) + +if __name__ == '__main__': + logging.basicConfig() + run() diff --git a/protocol/examples/python/mobileDemoTestTM1/org.tizen.elm-demo-tizen-mobile-0.2-1.armv7l.rpm b/protocol/examples/python/mobileDemoTestTM1/org.tizen.elm-demo-tizen-mobile-0.2-1.armv7l.rpm new file mode 100644 index 0000000..ab036c1 Binary files /dev/null and b/protocol/examples/python/mobileDemoTestTM1/org.tizen.elm-demo-tizen-mobile-0.2-1.armv7l.rpm differ