How to use install_app method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

BuildmacOSInstallApp.command

Source:BuildmacOSInstallApp.command Github

copy

Full Screen

1#!/usr/bin/env python2from Scripts import *3import os, datetime, shutil, time, sys, argparse4# Using the techniques outlined by wolfmannight here: https://www.insanelymac.com/forum/topic/338810-create-legit-copy-of-macos-from-apple-catalog/5class buildMacOSInstallApp:6 def __init__(self):7 self.r = run.Run()8 self.u = utils.Utils("Build macOS Install App")9 self.target_files = [10 "BaseSystem.dmg",11 "BaseSystem.chunklist",12 "InstallESDDmg.pkg",13 "InstallInfo.plist",14 "AppleDiagnostics.dmg",15 "AppleDiagnostics.chunklist"16 ]17 # Verify we're on macOS - this doesn't work anywhere else18 if not sys.platform == "darwin":19 self.u.head("WARNING")20 print("")21 print("This script only runs on macOS!")22 print("")23 exit(1)24 def mount_dmg(self, dmg, no_browse = False):25 # Mounts the passed dmg and returns the mount point(s)26 args = ["/usr/bin/hdiutil", "attach", dmg, "-plist", "-noverify"]27 if no_browse:28 args.append("-nobrowse")29 out = self.r.run({"args":args})30 if out[2] != 0:31 # Failed!32 raise Exception("Mount Failed!", "{} failed to mount:\n\n{}".format(os.path.basename(dmg), out[1]))33 # Get the plist data returned, and locate the mount points34 try:35 plist_data = plist.loads(out[0])36 mounts = [x["mount-point"] for x in plist_data.get("system-entities", []) if "mount-point" in x]37 return mounts38 except:39 raise Exception("Mount Failed!", "No mount points returned from {}".format(os.path.basename(dmg)))40 def unmount_dmg(self, mount_point):41 # Unmounts the passed dmg or mount point - retries with force if failed42 # Can take either a single point or a list43 if not type(mount_point) is list:44 mount_point = [mount_point]45 unmounted = []46 for m in mount_point: 47 args = ["/usr/bin/hdiutil", "detach", m]48 out = self.r.run({"args":args})49 if out[2] != 0:50 # Polite failed, let's crush this b!51 args.append("-force")52 out = self.r.run({"args":args})53 if out[2] != 0:54 # Oh... failed again... onto the next...55 print(out[1])56 continue57 unmounted.append(m)58 return unmounted59 def main(self):60 while True:61 self.u.head()62 print("")63 print("Q. Quit")64 print("")65 fold = self.u.grab("Please drag and drop the output folder from gibMacOS here: ")66 print("")67 if fold.lower() == "q":68 self.u.custom_quit()69 f_path = self.u.check_path(fold)70 if not f_path:71 print("That path does not exist!\n")72 self.u.grab("Press [enter] to return...")73 continue74 # Let's check if it's a folder. If not, make the next directory up the target75 if not os.path.isdir(f_path):76 f_path = os.path.dirname(os.path.realpath(f_path))77 # Walk the contents of f_path and ensure we have all the needed files78 lower_contents = [y.lower() for y in os.listdir(f_path)]79 missing_list = [x for x in self.target_files if not x.lower() in lower_contents]80 if len(missing_list):81 self.u.head("Missing Required Files")82 print("")83 print("That folder is missing the following required files:")84 print(", ".join(missing_list))85 print("")86 self.u.grab("Press [enter] to return...")87 # Time to build the installer!88 cwd = os.getcwd()89 os.chdir(f_path)90 base_mounts = []91 try:92 self.u.head("Building Installer")93 print("")94 print("Taking ownership of downloaded files...")95 for x in self.target_files:96 print(" - {}...".format(x))97 self.r.run({"args":["chmod","a+x",x]})98 print("Mounting BaseSystem.dmg...")99 base_mounts = self.mount_dmg("BaseSystem.dmg")100 if not len(base_mounts):101 raise Exception("Mount Failed!", "No mount points were returned from BaseSystem.dmg")102 base_mount = base_mounts[0] # Let's assume the first103 print("Locating Installer app...")104 install_app = next((x for x in os.listdir(base_mount) if os.path.isdir(os.path.join(base_mount,x)) and x.lower().endswith(".app") and not x.startswith(".")),None)105 if not install_app:106 raise Exception("Installer app not located in {}".format(base_mount))107 print(" - Found {}".format(install_app))108 # Copy the .app over109 out = self.r.run({"args":["cp","-R",os.path.join(base_mount,install_app),os.path.join(f_path,install_app)]})110 if out[2] != 0:111 raise Exception("Copy Failed!", out[1])112 print("Unmounting BaseSystem.dmg...")113 for x in base_mounts:114 self.unmount_dmg(x)115 base_mounts = []116 shared_support = os.path.join(f_path,install_app,"Contents","SharedSupport")117 if not os.path.exists(shared_support):118 print("Creating SharedSupport directory...")119 os.makedirs(shared_support)120 print("Copying files to SharedSupport...")121 for x in self.target_files:122 y = "InstallESD.dmg" if x.lower() == "installesddmg.pkg" else x # InstallESDDmg.pkg gets renamed to InstallESD.dmg - all others stay the same123 print(" - {}{}".format(x, " --> {}".format(y) if y != x else ""))124 out = self.r.run({"args":["cp","-R",os.path.join(f_path,x),os.path.join(shared_support,y)]})125 if out[2] != 0:126 raise Exception("Copy Failed!", out[1])127 print("Patching InstallInfo.plist...")128 with open(os.path.join(shared_support,"InstallInfo.plist"),"rb") as f:129 p = plist.load(f)130 if "Payload Image Info" in p:131 pii = p["Payload Image Info"]132 if "URL" in pii: pii["URL"] = pii["URL"].replace("InstallESDDmg.pkg","InstallESD.dmg")133 if "id" in pii: pii["id"] = pii["id"].replace("com.apple.pkg.InstallESDDmg","com.apple.dmg.InstallESD")134 pii.pop("chunklistURL",None)135 pii.pop("chunklistid",None)136 with open(os.path.join(shared_support,"InstallInfo.plist"),"wb") as f:137 plist.dump(p,f)138 print("")139 print("Created: {}".format(install_app))140 print("Saved to: {}".format(os.path.join(f_path,install_app)))141 print("")142 self.u.grab("Press [enter] to return...")143 except Exception as e:144 print("An error occurred:")145 print(" - {}".format(e))146 print("")147 if len(base_mounts):148 for x in base_mounts:149 print(" - Unmounting {}...".format(x))150 self.unmount_dmg(x)151 print("")152 self.u.grab("Press [enter] to return...")153if __name__ == '__main__':154 b = buildMacOSInstallApp()...

Full Screen

Full Screen

test_install_ability.py

Source:test_install_ability.py Github

copy

Full Screen

1import json2import unittest3from aos.ability.install_ability_device.install_app import InstallUpdateAbility4class TestCaseInstallAbility(unittest.TestCase):5 def setUp(self):6 #gia lap data tu brain:7 self.data = json.loads(json.loads ("{\"source\": \"eac7efdf-00ce-4404-af69-26c9da50cb39\", \"type\": \"install_ability_device\", \"protocol\": \"firebase\", \"data\": \"{\\\"app\\\": \\\"product_control_test\\\", \\\"version\\\": \\\"2.0.0\\\", \\\"link\\\": \\\"http://s3.amazonaws.com/s3-robotbase/product_control_test.zip\\\", \\\"is_service\\\": 0, \\\"action\\\": \\\"add\\\", \\\"md5_hash\\\": \\\"42e144f5829753ff55d953367297a2d2\\\", \\\"application_file\\\": \\\"main.py\\\"}\", \"time\": \"1489720855370000000\"}")['data'])8 def test_is_valid_data_false(self):9 del self.data['app']10 self.install_app = InstallUpdateAbility(self.data)11 self.assertFalse(self.install_app.is_valid_data)12 def test_is_valid_data_true(self):13 self.install_app = InstallUpdateAbility(self.data)14 self.assertTrue(self.install_app.is_valid_data)15 def test_is_valid_data_add_false_without_md5(self):16 del self.data['md5_hash']17 self.install_app = InstallUpdateAbility(self.data)18 self.assertFalse(self.install_app.is_valid_ability())19 def test_is_valid_data_add_false_without_link(self):20 del self.data['link']21 self.install_app = InstallUpdateAbility(self.data)22 self.assertFalse(self.install_app.is_valid_ability())23 def test_is_valid_data_add_true(self):24 self.install_app = InstallUpdateAbility(self.data)25 self.assertTrue(self.install_app.is_valid_ability())26 def test_download_success(self):27 self.install_app = InstallUpdateAbility(self.data)28 self.assertTrue(self.install_app.is_valid_ability())29 self.assertTrue(self.install_app.download())30 def test_download_and_unzip_success_with_md5_true(self):31 self.install_app = InstallUpdateAbility(self.data)32 self.assertTrue(self.install_app.is_valid_ability())33 self.assertTrue(self.install_app.download())34 self.assertTrue(self.install_app.unzip())35 def test_download_and_unzip_NOT_success_with_md5_false(self):36 self.data['md5_hash'] = 'random_md5_hash...'37 self.install_app = InstallUpdateAbility(self.data)38 self.assertTrue(self.install_app.is_valid_ability())39 self.assertTrue(self.install_app.download())40 self.assertTrue(self.install_app.unzip())41 def test_update_config_true(self):42 self.install_app = InstallUpdateAbility(self.data)43 self.assertTrue(self.install_app.is_valid_ability())44 self.assertTrue(self.install_app.download())45 self.assertTrue(self.install_app.unzip())46 self.assertTrue(self.install_app.update_config())47 from aos.system.configs.channel import BASE_APP48 app_path_config = BASE_APP + self.install_app.app_name + "/config.json"49 import os50 self.assertTrue(os.path.isfile(app_path_config))51 from aos.system.libs.util import Util52 version = Util.read_file(app_path_config)['version']53 print "compare version: ", version, self.install_app.version54 self.assertTrue(version == self.install_app.version)55 def test_full_install_true(self):56 self.install_app = InstallUpdateAbility(self.data)57 self.assertTrue(self.install_app.run())58 def test_is_valid_ability_FALSE_with_not_new_version(self):59 # testcase nay remove nhe.60 self.assertTrue(True)61 # version:62 # self.data['version'] = '2.2.0'63 # self.install_app = InstallUpdateAbility(self.data)64 # self.assertTrue(self.install_app.run())65 #66 # self.assertTrue(self.install_app.version == self.data['version'])67 #68 # self.data['version'] = '2.2.0'69 # self.install_app = InstallUpdateAbility(self.data)70 #71 # self.assertFalse(self.install_app.is_valid_ability())72 #73 # self.data['version'] = '1.0.0'74 # self.install_app = InstallUpdateAbility(self.data)75 #76 # self.assertFalse(self.install_app.is_valid_ability())77 def test_remove_app_success(self):78 import os79 self.install_app = InstallUpdateAbility(self.data)80 self.assertTrue(self.install_app.run())81 self.data['action'] = "remove"82 self.install_app = InstallUpdateAbility(self.data)83 self.assertTrue(self.install_app.run())84 self.assertTrue(not os.path.isdir(self.install_app.app_base_dir))85 def tearDown(self):86 try:87 import os88 if os.path.isdir(self.install_app.app_base_dir):89 import shutil90 shutil.rmtree(self.install_app.app_base_dir)91 except:92 pass93if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful