def _prepare(): # 准备工作 # 清理QQ、微信账号,清理游戏数据确保每次启动的逻辑是一样的。然后,拉起游戏 env = os.environ.get("PLATFORM_IP") logger = manager.get_logger() lanuch_result = False if env: lanuch_result = _cloud_prepare() else: lanuch_result = _native_prepare() if lanuch_result: # 拉起成功,通常游戏会有一段过场动画,这时候并不一定会启动我们这边的sdk,我们需要不断的尝试连接SDK。如果,连接成功获取sdk版本号则游戏已经启动 logger.debug("Launch package {0} SUCCESS,try to connect U3DAutomation SDK".format(os.environ["PKGNAME"])) global engine engine = manager.get_engine() version = None for i in range(30): try: version = engine.get_sdk_version() if version: logger.debug(version) manager.save_sdk_version(version) return True except: time.sleep(2) return False
def _prepare(): #clear qq,wechat and game datax on device to make sure a stable test environment, and then launch the game. env = os.environ.get("PLATFORM_IP") logger = manager.get_logger() lanuch_result = False if env: lanuch_result = _cloud_prepare() else: lanuch_result = _native_prepare() if lanuch_result: #launch success. in general , a game may have a loading phase in which the sdk has not been launched. So we try to connect SDK in a loop. logger.debug("Launch package {0} SUCCESS,try to connect U3DAutomation SDK".format(os.environ["PKGNAME"])) global engine engine = manager.get_engine() version = None for i in range(30): try: version = engine.get_sdk_version() if version: logger.debug(version) manager.save_sdk_version(version) return True except: time.sleep(2) return False
def _prepare(): # 准备工作 # 清理QQ、微信账号,清理游戏数据确保每次启动的逻辑是一样的。然后,拉起游戏 env = os.environ.get("PLATFORM_IP") logger = manager.get_logger() lanuch_result = False if env: lanuch_result = _cloud_prepare() else: lanuch_result = _native_prepare() if lanuch_result: # 拉起成功,通常游戏会有一段过场动画,这时候并不一定会启动我们这边的sdk,我们需要不断的尝试连接SDK。如果,连接成功获取sdk版本号则游戏已经启动 logger.debug( "Launch package {0} SUCCESS,try to connect U3DAutomation SDK". format(os.environ["PKGNAME"])) global engine engine = manager.get_engine() version = None for i in range(30): try: version = engine.get_sdk_version() if version: logger.debug(version) manager.save_sdk_version(version) return True except: time.sleep(2) return False
def _run(): prepare = _prepare() logger = manager.get_logger() reporter = manager.get_reporter() if not prepare: reporter.screenshot() logger.error("Connect to sdk fail,please config your game contain sdk or not in the first scene") return try: import testcase.runner as runner runner.run() except WeTestRuntimeError as e: stack = traceback.format_exc() logger.exception(stack)
def _run(): prepare = _prepare() logger = manager.get_logger() reporter = manager.get_reporter() if not prepare: reporter.screenshot() logger.error("Connect to sdk fail,please config your game contain sdk or not in the first scene") return try: import testcase.runner as runner runner.run() except WeTestRuntimeError as e: stack = traceback.format_exc() logger.exception(stack)
def _cloud_prepare(): # 云端测试,只需要拉起游戏 reporter = manager.get_reporter() device = manager.get_device() logger = manager.get_logger() try: reporter.screenshot() res = device.launch_app() logger.debug(res) reporter.screenshot() time.sleep(10) return True except: stack = traceback.format_exc() logger.error(stack) logger.error("Launch app failure") return False
def _cloud_prepare(): # test in cloud, just launch the app reporter = manager.get_reporter() device = manager.get_device() logger = manager.get_logger() try: reporter.screenshot() res = device.launch_app() logger.debug(res) reporter.screenshot() time.sleep(10) return True except: stack = traceback.format_exc() logger.error(stack) logger.error("Launch app failure") return False
def _prepare(): # 准备工作 # 清理QQ、微信账号,清理游戏数据确保每次启动的逻辑是一样的。然后,拉起游戏 env = os.environ.get("PLATFORM_IP") logger = manager.get_logger() lanuch_result = False if env: lanuch_result = _cloud_prepare() else: lanuch_result = _native_prepare() if lanuch_result: # 拉起成功,通常游戏会有一段过场动画,这时候并不一定会启动我们这边的sdk,我们需要不断的尝试连接SDK。如果,连接成功获取sdk版本号则游戏已经启动 logger.debug( "Launch package {0} SUCCESS,try to connect U3DAutomation SDK". format(os.environ["PKGNAME"])) global engine engine = manager.get_engine() version = None for i in range(30): try: # 开场msdk提示 allow = device.ui_device(className="android.widget.Button") if allow and allow.exists: logger.debug("find popup windows click") allow.click.wait() device.excute_adb("shell input tap 20 20") time.sleep(5) version = engine.get_sdk_version() if version: logger.debug(version) manager.save_sdk_version(version) return True except: time.sleep(2) return False
Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://opensource.org/licenses/MIT Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ __author__ = 'minhuaxu [email protected]' import sys, os, time sys.path.append(os.path.abspath(os.path.join(os.getcwd(), ".."))) import wpyscripts.manager as manager engine = manager.get_engine() logger = manager.get_logger() device = manager.get_device() def test_get_display_size(): display_size = device.get_display_size() logger.debug(display_size) rotation = device.get_rotation() logger.debug("Rotation : {0}".format(rotation)) def test_get_top_package_activity(): top_activity = device.get_top_package_activity() logger.debug(top_activity)
os.environ["LOCAL_ENGINE_PORT"] = options.LOCAL_ENGINE_PORT if options.UIAUTOMATOR_PORT: os.environ["UIAUTOMATOR_PORT"] = options.UIAUTOMATOR_PORT if options.ANDROID_SERIAL: os.environ["ANDROID_SERIAL"] = options.ANDROID_SERIAL if options.OTHERNAME: os.environ["OTHERNAME"] = options.OTHERNAME if options.OTHERPWD: os.environ["OTHERPWD"] = options.OTHERPWD if options.WECHATNAME: os.environ["WECHATNAME"] = options.WECHATNAME if options.WECHATPWD: os.environ["WECHATPWD"] = options.WECHATPWD _prepare_environ() except getopt.error, msg: print("for help use --help") return 2 logger = manager.get_logger() try: _run() except: stack = traceback.format_exc() logger.exception(stack) finally: logger.debug("GAutomator End") if __name__ == "__main__": sys.exit(main())
def main(): """ when testing several phones on your local PC, you could run the py by cmd you only need to set one type of account. "othername and other pwd" will be used preferentially if multiple types are provided. --qqname:qqaccount --qqpwd:qq password --wechataccount:wechat account --wechatpwd:wechat password --othername:any other accounts --otherpwd: password of othername --engineport: the forward port mapping to the sdk port in device. the parameters for each device should be individually provided. --uiport:the forward port mapping to the uiautomator port in device. the parameters for each device should be individually provided. --serial: serial number of the target device. you could get it by "adb devices -l" :return: """ usage = "usage:%prog [options] --qqname= --qqpwd= --engineport= --uiport= --serial=" parser = optparse.OptionParser(usage) parser.add_option("-q", "--qqname", dest="QQNAME", help="QQ Account") parser.add_option("-p", "--qqpwd", dest="QQPWD", help="QQ Password") parser.add_option("-b", "--wechataccount", dest="WECHATNAME", help="wechat Account") parser.add_option("-c", "--wechatpwd", dest="WECHATPWD", help="wechat Password") parser.add_option("-e", "--engineport", dest="LOCAL_ENGINE_PORT", help="network port forward engine sdk") parser.add_option("-u", "--uiport", dest="UIAUTOMATOR_PORT", help="network port forward uiautomator server") parser.add_option("-s", "--serial", dest="ANDROID_SERIAL", help="adb devices android mobile serial") parser.add_option("-g", "--othername", dest="OTHERNAME", help="upload account") parser.add_option("-f", "--otherpwd", dest="OTHERPWD", help="upload password") (options, args) = parser.parse_args() try: if options.QQNAME: os.environ["QQNAME"] = options.QQNAME if options.QQPWD: os.environ["QQPWD"] = options.QQPWD if options.LOCAL_ENGINE_PORT: os.environ["LOCAL_ENGINE_PORT"] = options.LOCAL_ENGINE_PORT if options.UIAUTOMATOR_PORT: os.environ["UIAUTOMATOR_PORT"] = options.UIAUTOMATOR_PORT if options.ANDROID_SERIAL: os.environ["ANDROID_SERIAL"] = options.ANDROID_SERIAL if options.OTHERNAME: os.environ["OTHERNAME"] = options.OTHERNAME if options.OTHERPWD: os.environ["OTHERPWD"] = options.OTHERPWD if options.WECHATNAME: os.environ["WECHATNAME"] = options.WECHATNAME if options.WECHATPWD: os.environ["WECHATPWD"] = options.WECHATPWD _prepare_environ() except getopt.error as msg: print("for help use --help") return 2 logger = manager.get_logger() try: _run() except: stack = traceback.format_exc() logger.exception(stack) finally: logger.debug("GAutomator End")