- 做appium自动化的时候,如果测试多台设备,需要多个虚拟机的时候,就需要创建多个模拟器;
- 夜神模拟器,提供了脚本的命令来创建NoxConsole
- NoxConsole目录在/bin
- 汇总使用中的问题
- 启动夜神模拟器:安装加入环境变量
- 删除和增加模拟器需要在安装目录的bin目录下执行;否则会报错;
-
首先切换到这个目录,再执行增加和删除工作;
-
使用NoxConsole.exe,不要用NoxConsole;
-
执行完成后,一定要切回原来的路径,要不然很多函数的结果有问题;如aapt
-
def change_dir(app): ''' 切换应用程序的目录 :param app: :return: ''' try: cmd = 'where ' + str(app) res = send_cmd(cmd=cmd) dir = "\".join(res.split("\")[:-1]) res = os.chdir(dir) path = os.getcwd() log.info("当前路径为:%s" %path) except Exception as err: raise Exception("change dir path fail: %s" % str(err)) def create_phone(num): ''' 创建夜神模拟器 :return: ''' cmd = 'NoxConsole quitall' res = (os.popen(cmd)).read() time.sleep(1) pro_path = os.path.dirname(__file__) for i in range(int(num)): if i == 0: nox_name = '127.0.0.1:62001' else: nox_name = '127.0.0.1:' + str(i - 1 + 62025) # 因为创建新的虚拟机需要在NoxConsole的根目录下进行,所以先切换到该目录去 change_dir("NoxConsole") cmd = 'NoxConsole.exe add -name:' + nox_name + ' -systemtype:5' res = (os.popen(cmd)).read() cmd = 'NoxConsole.exe modify -name:' + nox_name + ' --resolution:1080,1920,270' res = (os.popen(cmd)).read() time.sleep(1) cmd = 'NoxConsole.exe rename -name:' + nox_name + ' -title:' + nox_name res = (os.popen(cmd)).read() cmd = 'NoxConsole.exe launch -name:' + nox_name res = (os.popen(cmd)).read() time.sleep(3) log.info('Virtual phone is launching, plaease wait 60s...') os.chdir(pro_path) time.sleep(Wait.launch_virtual_time)
- 夜神模拟器命名规范:第二个是62025,以后的加一
- 127.0.0.1:62001
- 127.0.0.1:62025
- 127.0.0.1:62026
- 重命名:
- NoxConsole rename -name:夜神模拟器 -title:127.0.0.1:62001
- NoxConsole launch -name:127.0.0.1:62001