├── examples ├── ImperiusGeorge.apk ├── basicUsages │ ├── press.keys.au3 │ └── retrive.device.info.au3 ├── simpleTest │ └── simple.test.au3 ├── pageObjectTest │ ├── page.object.test.au3 │ ├── dashboardScreen.au3 │ └── inputsScreen.au3 └── microTest │ └── micro.test.au3 ├── bin └── imperiusserver.1.0.1.jar ├── .gitmodules ├── appveyor.yml ├── imperius.au3 ├── LICENSE.txt ├── README.md ├── lib ├── adb.constants.au3 ├── imperius.server.au3 ├── logger.au3 ├── adb.au3 ├── android.keys.constants.au3 └── uidevice.au3 └── test └── imperius.test.au3 /examples/ImperiusGeorge.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/htejera/ImperiusAutoIt/HEAD/examples/ImperiusGeorge.apk -------------------------------------------------------------------------------- /bin/imperiusserver.1.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/htejera/ImperiusAutoIt/HEAD/bin/imperiusserver.1.0.1.jar -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/vendor/micro"] 2 | path = lib/vendor/micro 3 | url = git://github.com/AutoItMicro/MicroUnitTestingFramework.git 4 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 0.1.beta.{build} 2 | 3 | branches: 4 | only: 5 | - master 6 | 7 | except: 8 | - gh-pages 9 | 10 | init: 11 | - cinst autoit.commandline 12 | 13 | build: off 14 | 15 | test_script: 16 | - git submodule update --init --recursive 17 | - cd test 18 | - autoit3 /ErrorStdOut /AutoIt3ExecuteScript imperius.test.au3 ci 19 | -------------------------------------------------------------------------------- /imperius.au3: -------------------------------------------------------------------------------- 1 | #Region includes 2 | #include-once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #EndRegion includes 15 | 16 | _AutoItObject_Startup() -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright © 2016 Henry Tejera henrytejera@gmail.com 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /examples/basicUsages/press.keys.au3: -------------------------------------------------------------------------------- 1 | #include <../../imperius.au3> 2 | 3 | ;Local $sDeviceId = "" If multiple emulator/device instances are running, you must specify a serial device id. 4 | Local $oImperius = ImperiusServer("127.0.0.1", 3007) 5 | Local $oLogger = $oImperius.getLogger() 6 | Local $oDevice = $oImperius.getDevice() 7 | $oImperius.start() ;Start the ImperiusGeorge server on the device. 8 | 9 | With $oDevice 10 | .pressBack() 11 | .pressHome() 12 | .pressTab() 13 | .pressAppMenu() 14 | .pressEnter() 15 | .sendKeyEvents($KEYCODE_CAMERA); You can find all key code definitions at android.keys.constants.au3 16 | EndWith 17 | 18 | $oImperius.stop() 19 | $oImperius = 0 -------------------------------------------------------------------------------- /examples/basicUsages/retrive.device.info.au3: -------------------------------------------------------------------------------- 1 | #include <../../imperius.au3> 2 | 3 | ;Local $sDeviceId = "" If multiple emulator/device instances are running, you must specify a serial device id. 4 | Local $oImperius = ImperiusServer("127.0.0.1", 3007) 5 | Local $oLogger = $oImperius.getLogger() 6 | Local $oDevice = $oImperius.getDevice() 7 | $oImperius.start() ;Start the ImperiusGeorge server on the device. 8 | 9 | $oLogger.info("Dump: " & $oDevice.getDump() ) 10 | $oLogger.info("Top Activity: " & $oDevice.getCurrentTopActivity()) 11 | $oLogger.info("Activity Name: " & $oDevice.getActivityName()) 12 | $oLogger.info("Device Name: " & $oDevice.getDeviceName()) 13 | $oLogger.info("Device Version: " & $oDevice.getDeviceVersion()) 14 | $oLogger.info("Device Manufacturer: " & $oDevice.getDeviceManufacturer()) 15 | $oLogger.info("Device Model: " & $oDevice.getDeviceModel()) 16 | $oLogger.info("Packages: " & $oDevice.getPackages()[0]) 17 | $oDevice.getScreenshot("screen.png") 18 | 19 | $oImperius.stop() 20 | $oImperius = 0 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![logo](https://cloud.githubusercontent.com/assets/3797402/20860319/f751422a-b953-11e6-94a5-0fb02dca0ce8.png) 2 | 3 | # Imperius AutoIt 4 | 5 | [![Build status](https://img.shields.io/appveyor/ci/ohtejera/imperiusautoit.svg?style=flat-square)](https://ci.appveyor.com/project/ohtejera/imperiusautoit) 6 | 7 | **Imperius AutoIt** is an [ImperiusGeorge](https://github.com/lookout/ImperiusGeorge) client for mobile test automation that support native Android apps. Tests are written using [AutoIt](https://www.autoitscript.com/site/) , that's it! 8 | 9 | 10 | To see what **Imperius AutoIt** can do for you, check out the documentation at https://ohtejera.github.io/ImperiusAutoIt/ 11 | 12 | 13 | ## License 14 | 15 | Copyright © 2016 Henry Tejera 16 | 17 | This work is free. It comes without any warranty, to 18 | the extent permitted by applicable law. You can redistribute it 19 | and/or modify it under the terms of the **Do What The Fuck You Want** 20 | To Public License, Version 2, as published by Sam Hocevar. See 21 | [WTFPL](http://www.wtfpl.net) for more details 22 | -------------------------------------------------------------------------------- /examples/simpleTest/simple.test.au3: -------------------------------------------------------------------------------- 1 | ;simple.test.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | ; 6 | ;Description: 7 | ; This is a very simple test. 8 | 9 | #include <../../imperius.au3> 10 | 11 | ;Application Under Test data. 12 | Local $sAUTPath = "../ImperiusGeorge.apk" 13 | Local $sPackage = "appinventor.ai_henrytejera.ImperiusGeorge" 14 | Local $sActivity = ".Screen1" 15 | 16 | ;Local $sDeviceId = "" If multiple emulator/device instances are running, you must specify a serial device id. 17 | Local $oImperius = ImperiusServer("127.0.0.1", 3007) 18 | Local $oLogger = $oImperius.getLogger() 19 | Local $oDevice = $oImperius.getDevice() 20 | $oImperius.start() ;Start the ImperiusGeorge server on the device. 21 | 22 | ;Install the application under test through the ADB client. 23 | $oImperius.getAdb().install($sAUTPath) 24 | $oDevice.startActivity($sPackage, $sActivity) 25 | $oLogger.info("Dump:" & $oDevice.getDump() ) 26 | $oDevice.waitForTextExist("AutoIt client") 27 | $oDevice.clickAndWait("Inputs Screen") 28 | $oDevice.enterText("0", "Imperius") 29 | $oDevice.enterText("1", "Password") 30 | $oDevice.click("Add") 31 | $oDevice.waitForTextExist("Ready") 32 | $oDevice.getScreenshot("InputScreen.png") 33 | $oDevice.pressBack() 34 | $oDevice.click("Back") 35 | $oDevice.clearPackage($sPackage) 36 | $oImperius.getAdb().uninstall($sPackage) 37 | 38 | $oImperius.stop() 39 | $oImperius = 0 -------------------------------------------------------------------------------- /lib/adb.constants.au3: -------------------------------------------------------------------------------- 1 | ;adb.constants.au3 2 | 3 | #include-once 4 | Global Const $INSTALL_SUCCEEDED = 1 5 | Global Const $INSTALL_FAILED_ALREADY_EXISTS = -1 6 | Global Const $INSTALL_FAILED_INVALID_APK = -2 7 | Global Const $INSTALL_FAILED_INVALID_URI = -3 8 | Global Const $INSTALL_FAILED_INSUFFICIENT_STORAGE = -4 9 | Global Const $INSTALL_FAILED_DUPLICATE_PACKAGE = -5 10 | Global Const $INSTALL_FAILED_NO_SHARED_USER = -6 11 | Global Const $INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7 12 | Global Const $INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8 13 | Global Const $INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9 14 | Global Const $INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10 15 | Global Const $INSTALL_FAILED_DEXOPT = -11 16 | Global Const $INSTALL_FAILED_OLDER_SDK = -12 17 | Global Const $INSTALL_FAILED_CONFLICTING_PROVIDER = -13 18 | Global Const $INSTALL_FAILED_NEWER_SDK = -14 19 | Global Const $INSTALL_FAILED_TEST_ONLY = -15 20 | Global Const $INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16 21 | Global Const $INSTALL_FAILED_MISSING_FEATURE = -17 22 | Global Const $INSTALL_FAILED_CONTAINER_ERROR = -18 23 | Global Const $INSTALL_FAILED_INVALID_INSTALL_LOCATION = -19 24 | Global Const $INSTALL_FAILED_MEDIA_UNAVAILABLE = -20 25 | Global Const $INSTALL_FAILED_VERIFICATION_TIMEOUT = -21 26 | Global Const $INSTALL_FAILED_VERIFICATION_FAILURE = -22 27 | Global Const $INSTALL_FAILED_PACKAGE_CHANGED = -23 28 | Global Const $INSTALL_FAILED_UID_CHANGED = -24 29 | Global Const $INSTALL_FAILED_VERSION_DOWNGRADE = -25 30 | Global Const $INSTALL_FAILED_INTERNAL_ERROR = -110 31 | Global Const $INSTALL_FAILED_USER_RESTRICTED = -111 -------------------------------------------------------------------------------- /examples/pageObjectTest/page.object.test.au3: -------------------------------------------------------------------------------- 1 | ;page.object.test.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | ; 6 | ;Description: 7 | ; Simple test that show the page object design best practice in order to minimize code duplication, make tests more readable, 8 | ; reduce the cost of modification, and improve maintainability. 9 | ;See: 10 | ; 11 | 12 | #include <../../imperius.au3> 13 | #include 14 | #include 15 | 16 | ;Application Under Test data. 17 | Local $sAUTPath = "../ImperiusGeorge.apk" 18 | Local $sPackage = "appinventor.ai_henrytejera.ImperiusGeorge" 19 | Local $sActivity = ".Screen1" 20 | 21 | ;Local $sDeviceId = "" If multiple emulator/device instances are running, you must specify a serial device id. 22 | Local $oImperius = ImperiusServer("127.0.0.1", 3007) 23 | Local $oLogger = $oImperius.getLogger() 24 | Local $oDevice = $oImperius.getDevice() 25 | $oImperius.start() ;Start the ImperiusGeorge server on the device. 26 | 27 | ;Install the application under test through the ADB client. 28 | $oImperius.getAdb().install($sAUTPath) 29 | $oDevice.startActivity($sPackage, $sActivity) 30 | 31 | Local $oDashboardScreen = DashboardScreen($oDevice) 32 | $oDashboardScreen.waitForScreen() 33 | Local $oInputsScreen = $oDashboardScreen.pressInputsScreen() 34 | 35 | With $oInputsScreen 36 | .writeName("Imperius") 37 | .writePassword("Password") 38 | .pressAdd() 39 | .waitForReady() 40 | .back() 41 | EndWith 42 | 43 | $oDevice.clearPackage($sPackage) 44 | $oImperius.getAdb().uninstall($sPackage) 45 | 46 | $oImperius.stop() 47 | $oImperius = 0 -------------------------------------------------------------------------------- /examples/pageObjectTest/dashboardScreen.au3: -------------------------------------------------------------------------------- 1 | ;dashboardScreen.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | ; 6 | ;Description: 7 | ; This object represents the Dashboard screen of the AUT (activity .Screen1) 8 | 9 | ;Function: DashboardScreen 10 | ; 11 | ;Parameters: 12 | ; $oDevice- Object. An UiDevice instance. 13 | ; 14 | ;Returns: 15 | ; Object. An DashboardScreen instance. 16 | Func DashboardScreen($oDevice) 17 | Local $oClassObject = _AutoItObject_Class() 18 | $oClassObject.Create() 19 | 20 | ;Methods 21 | With $oClassObject 22 | .AddMethod("pressInputsScreen", "_PressInputsScreen") 23 | .AddMethod("waitForScreen", "_WaitForScreen") 24 | EndWith 25 | 26 | ;Properties 27 | With $oClassObject 28 | .AddProperty("oDevice", $ELSCOPE_PRIVATE, $oDevice) 29 | .AddProperty("buttonInputs", $ELSCOPE_PRIVATE, "Inputs Screen") 30 | .AddProperty("textTitle", $ELSCOPE_PRIVATE, "ImperiusGeorge") 31 | EndWith 32 | 33 | Return $oClassObject.Object 34 | EndFunc ;==>DashboardScreen 35 | 36 | #Region Methods 37 | ;Function: _PressInputsScreen 38 | ;Presses the "Inputs Screen" button. 39 | ; 40 | ;Parameters: 41 | ; $oSelf - Object reference. 42 | ; 43 | ;Returns: 44 | ; Object. A InputsScreen instance. 45 | Func _PressInputsScreen($oSelf) 46 | $oSelf.oDevice.click($oSelf.buttonInputs) 47 | Return InputsScreen($oSelf.oDevice) 48 | EndFunc ;==>_PressInputsScreen 49 | 50 | ;Function: _WaitForScreen 51 | ;Wait for the title of this screen. 52 | ; 53 | ;Parameters: 54 | ; $oSelf - Object reference. 55 | Func _WaitForScreen($oSelf) 56 | $oSelf.oDevice.waitForTextExist($oSelf.textTitle) 57 | EndFunc ;==>_WaitForScreen 58 | #EndRegion Methods -------------------------------------------------------------------------------- /examples/microTest/micro.test.au3: -------------------------------------------------------------------------------- 1 | ;micro.test.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | ; 6 | ;Description: 7 | ; This is a very simple test that use Micro Unit Testing Framework. 8 | 9 | #include <../../imperius.au3> 10 | 11 | #Region AUTData 12 | Local $sAUTPath = "../ImperiusGeorge.apk" 13 | Local $sPackage = "appinventor.ai_henrytejera.ImperiusGeorge" 14 | Local $sActivity = ".Screen1" 15 | #EndRegion AUTData 16 | 17 | #Region BeforeAfter 18 | Func BeforeSuite($oServer, $sAppPath, $sPackage) 19 | Local $oAdb = $oServer.getAdb() 20 | With $oAdb 21 | .uninstall($sPackage) 22 | .install($sAppPath) 23 | EndWith 24 | EndFunc ;==>BeforeSuite 25 | #EndRegion BeforeAfter 26 | 27 | #Region Suite 28 | Local $oImperius = ImperiusServer("127.0.0.1", 3007) 29 | Local $oDevice = $oImperius.getDevice() 30 | $oImperius.start() 31 | BeforeSuite($oImperius, $sAUTPath, $sPackage) 32 | Local $oTestSuite = newTestSuite("Suite") 33 | $oTestSuite.addTest(TestInputScreen($oDevice)) 34 | $oTestSuite.finish() 35 | $oImperius.stop() 36 | $oImperius = 0 37 | #EndRegion Suite 38 | 39 | #Region Tests 40 | Func TestInputScreen($oDevice) 41 | Local $oTest = newTest("Test InputScreen") 42 | Local $sExpected = "Ready" 43 | With $oDevice 44 | .startActivity($sPackage, $sActivity) 45 | .waitForTextExist("AutoIt client") 46 | .clickAndWait("Inputs Screen") 47 | .enterText("0", "Imperius") 48 | .enterText("1", "Password") 49 | .click("Add") 50 | .getScreenshot("InputScreen.png") 51 | EndWith 52 | $oTest.assertTrue("Assert that the [" & $sExpected & "] text is present on the screen", $oDevice.waitForTextExist($sExpected)) 53 | Return $oTest 54 | EndFunc ;==>TestInputScreen 55 | #EndRegion Tests -------------------------------------------------------------------------------- /examples/pageObjectTest/inputsScreen.au3: -------------------------------------------------------------------------------- 1 | ;inputsScreen.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | ; 6 | ;Description: 7 | ; This object represents the InputsScreen screen of the AUT (activity .InputsScreen) 8 | 9 | ;Function: InputsScreen 10 | ; 11 | ;Parameters: 12 | ; $oDevice- Object. An UiDevice instance. 13 | ; 14 | ;Returns: 15 | ; Object. An InputsScreen instance. 16 | Func InputsScreen($oDevice) 17 | Local $oClassObject = _AutoItObject_Class() 18 | $oClassObject.Create() 19 | 20 | ;Methods 21 | With $oClassObject 22 | .AddMethod("writeName", "_WriteName") 23 | .AddMethod("writePassword", "_WritePassword") 24 | .AddMethod("pressAdd", "_PressAdd") 25 | .AddMethod("back", "_Back") 26 | .AddMethod("waitForReady", "_WaitForReady") 27 | EndWith 28 | 29 | ;Properties 30 | With $oClassObject 31 | .AddProperty("oDevice", $ELSCOPE_PRIVATE, $oDevice) 32 | .AddProperty("inputName", $ELSCOPE_PRIVATE, 0) 33 | .AddProperty("inputPassword", $ELSCOPE_PRIVATE, 1) 34 | .AddProperty("buttonAdd", $ELSCOPE_PRIVATE, "Add") 35 | .AddProperty("buttonBack", $ELSCOPE_PRIVATE, "Back") 36 | .AddProperty("textReady", $ELSCOPE_PRIVATE, "Ready") 37 | EndWith 38 | 39 | Return $oClassObject.Object 40 | EndFunc ;==>InputsScreen 41 | 42 | #Region Methods 43 | ;Function: _WriteName 44 | ;Enter the given text in the "Name" input. 45 | ; 46 | ;Parameters: 47 | ; $oSelf - Object reference. 48 | ; $sName - String. The name. 49 | Func _WriteName($oSelf, $sName) 50 | $oSelf.oDevice.enterText($oSelf.inputName, $sName) 51 | EndFunc ;==>_WriteName 52 | 53 | ;Function: _WritePassword 54 | ;Enter the given text in the "Password" input. 55 | ; 56 | ;Parameters: 57 | ; $oSelf - Object reference. 58 | ; $sPassword - String. The password. 59 | Func _WritePassword($oSelf, $sPassword) 60 | $oSelf.oDevice.enterText($oSelf.inputPassword, $sPassword) 61 | EndFunc ;==>_WritePassword 62 | 63 | ;Function: _PressAdd 64 | ;Presses the Add button. 65 | ; 66 | ;Parameters: 67 | ; $oSelf - Object reference. 68 | Func _PressAdd($oSelf) 69 | $oSelf.oDevice.click($oSelf.buttonAdd) 70 | EndFunc ;==>_PressAdd 71 | 72 | ;Function: _Back 73 | ;Presses the Back button. 74 | ; 75 | ;Parameters: 76 | ; $oSelf - Object reference. 77 | ; 78 | ;Returns: 79 | ; Object. A DashboardScreen instance. 80 | Func _Back($oSelf) 81 | $oSelf.oDevice.click($oSelf.buttonBack) 82 | Return DashboardScreen($oSelf.oDevice) 83 | EndFunc ;==>_Back 84 | 85 | ;Function: _WaitForReady 86 | ; 87 | ;Parameters: 88 | ; $oSelf - Object reference. 89 | Func _WaitForReady($oSelf) 90 | $oSelf.oDevice.waitForTextExist($oSelf.textReady) 91 | EndFunc ;==>_WaitForReady 92 | #EndRegion Methods -------------------------------------------------------------------------------- /test/imperius.test.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_Change2CUI=y 3 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 4 | #include <../imperius.au3> 5 | 6 | Global Enum $IP, $PORT, $DEVICEID, $SERVERPATH, $TIMEOUT 7 | Global $aParams[5] = ["127.0.0.1", 3007, "123456", "C:\folder", 15000] 8 | 9 | #Region Suite 10 | Local $oTestSuite = newTestSuite("Imperius") 11 | $oTestSuite.ci = True 12 | $oTestSuite.addTest(TestImperiusServerGetters()) 13 | $oTestSuite.addTest(TestUIDeviceGetters()) 14 | $oTestSuite.addTest(TestLoggerLevels()) 15 | $oTestSuite.addTest(TestLoggerFile()) 16 | $oTestSuite.finish() 17 | #EndRegion Suite 18 | 19 | #Region Tests 20 | Func TestImperiusServerGetters() 21 | Local $sMsg = "This [%s] getter should be equal to [%s]" 22 | Local $sURL = 'http://' & $aParams[$IP] & ':' & $aParams[$PORT] & '/' 23 | 24 | Local $oTest = newTest("ImperiusServerGetters") 25 | Local $oImperius = ImperiusServer($aParams[$IP], $aParams[$PORT], $aParams[$DEVICEID], $aParams[$SERVERPATH], $aParams[$TIMEOUT]) 26 | 27 | With $oTest 28 | .assertEquals(StringFormat($sMsg, "getIP", $aParams[$IP]), $oImperius.getIP(), $aParams[$IP]) 29 | .assertEquals(StringFormat($sMsg, "getPort", $aParams[$PORT]), $oImperius.getPort(), $aParams[$PORT]) 30 | .assertEquals(StringFormat($sMsg, "getServerPath", $aParams[$SERVERPATH]), $oImperius.getServerPath(), $aParams[$SERVERPATH] & "\" & $IMPERIUSSERVERJAR) 31 | .assertEquals(StringFormat($sMsg, "getTimeout", $aParams[$TIMEOUT]), $oImperius.getTimeout(), $aParams[$TIMEOUT]) 32 | .assertEquals(StringFormat($sMsg, "getUrl", $sURL), $sURL, $oImperius.getUrl()) 33 | .assertEquals(StringFormat($sMsg, "getDeviceID", $aParams[$DEVICEID]), $aParams[$DEVICEID], $oImperius.getDeviceID()) 34 | .assertTrue(StringFormat($sMsg, "getDevice", "UiDevice"), IsObj($oImperius.getDevice())) 35 | .assertTrue(StringFormat($sMsg, "getAdb", "ADB"), IsObj($oImperius.getAdb())) 36 | .assertTrue(StringFormat($sMsg, "getLogger", "Logger"), IsObj($oImperius.getLogger())) 37 | EndWith 38 | $oImperius = 0 39 | Return $oTest 40 | EndFunc ;==>TestImperiusServerGetters 41 | 42 | 43 | Func TestUIDeviceGetters() 44 | Local $sMsg = "This [%s] getter should be equal to [%s]" 45 | Local $oTest = newTest("UiDeviceGetters") 46 | Local $oImperius = ImperiusServer(Default, Default, $aParams[$DEVICEID], $aParams[$SERVERPATH]) 47 | Local $oDevice = $oImperius.getDevice() 48 | 49 | With $oTest 50 | .assertEquals(StringFormat($sMsg, "getDeviceID", $aParams[$DEVICEID]), $aParams[$DEVICEID], $oDevice.getDeviceID()) 51 | .assertTrue(StringFormat($sMsg, "getServer", "Imperius"), IsObj($oDevice.getServer())) 52 | EndWith 53 | $oImperius = 0 54 | $oDevice = 0 55 | Return $oTest 56 | EndFunc ;==>TestUIDeviceGetters 57 | 58 | Func TestLoggerLevels() 59 | Local $sMsg = "Actual level should be equal to [%s]" 60 | Local Const $LEVELSTRING[6] = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"] 61 | Local $sDefaultLevel = "INFO" 62 | Local $oTest = newTest("Logger") 63 | Local $oLogger = Logger() 64 | 65 | $oTest.assertEquals(StringFormat($sMsg, $sDefaultLevel), $sDefaultLevel, $oLogger.getLevel()) 66 | $oLogger.setLevel($LOG_TRACE) 67 | $oTest.assertEquals(StringFormat($sMsg, $LEVELSTRING[$LOG_TRACE]), $LEVELSTRING[$LOG_TRACE], $oLogger.getLevel()) 68 | $oLogger.setLevel($LOG_DEBUG) 69 | $oTest.assertEquals(StringFormat($sMsg, $LEVELSTRING[$LOG_DEBUG]), $LEVELSTRING[$LOG_DEBUG], $oLogger.getLevel()) 70 | $oLogger.setLevel($LOG_INFO) 71 | $oTest.assertEquals(StringFormat($sMsg, $sDefaultLevel), $sDefaultLevel, $oLogger.getLevel()) 72 | $oLogger.setLevel($LOG_WARN) 73 | $oTest.assertEquals(StringFormat($sMsg, $LEVELSTRING[$LOG_WARN]), $LEVELSTRING[$LOG_WARN], $oLogger.getLevel()) 74 | $oLogger.setLevel($LOG_ERROR) 75 | $oTest.assertEquals(StringFormat($sMsg, $LEVELSTRING[$LOG_ERROR]), $LEVELSTRING[$LOG_ERROR], $oLogger.getLevel()) 76 | $oLogger.setLevel($LOG_FATAL) 77 | $oTest.assertEquals(StringFormat($sMsg, $LEVELSTRING[$LOG_FATAL]), $LEVELSTRING[$LOG_FATAL], $oLogger.getLevel()) 78 | $oLogger = 0 79 | Return $oTest 80 | EndFunc ;==>TestLoggerLevels 81 | 82 | 83 | Func TestLoggerFile() 84 | Local $sMsg = "Actual level should be equal to [%s]" 85 | Local Const $LEVELSTRING[6] = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"] 86 | Local $sFileLog = "log.txt" 87 | Local $sDefaultLevel = "INFO" 88 | Local $oTest = newTest("LoggerFile") 89 | Local $oLogger = Logger($sFileLog) 90 | 91 | With $oLogger 92 | .setLevel($LOG_TRACE) 93 | .trace("TRACE") 94 | .setLevel($LOG_DEBUG) 95 | .debug("DEBUG") 96 | .setLevel($LOG_INFO) 97 | .info("INFO") 98 | .setLevel($LOG_WARN) 99 | .warn("WARN") 100 | .setLevel($LOG_ERROR) 101 | .error("ERROR") 102 | .setLevel($LOG_FATAL) 103 | .fatal("FATAL") 104 | EndWith 105 | 106 | $oTest.assertTrue("The file [" & $sFileLog & "] exists", FileExists($sFileLog)) 107 | $oTest.assertTrue("The file [" & $sFileLog & "] size should be > 0", FileGetSize($sFileLog) > 0) 108 | $oLogger = 0 109 | FileDelete($sFileLog) 110 | Return $oTest 111 | EndFunc ;==>TestLoggerFile 112 | #EndRegion Tests -------------------------------------------------------------------------------- /lib/imperius.server.au3: -------------------------------------------------------------------------------- 1 | ;imperius.server.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | 6 | Global Const $IMPERIUSSERVERJAR = "imperiusserver.1.0.1.jar" 7 | 8 | ;Function: ImperiusServer 9 | ;An ImperiusServer connection data. 10 | ; 11 | ;Parameters: 12 | ; $sIP - String. The Imperius server IP. Default is locahost. 13 | ; $iPort - Int. The Imperius server port. Default is 7120. 14 | ; $sDeviceId - String. The serial deviceID. Can be empty if only have one device. Deafuls is "". 15 | ; $sLocalServerPath - String. The full path to the imperiusserver.jar. Default uses the IMPERIUS environment variable. 16 | ; $iTimeout - Int. Timeout (miliseconds). Default is 30000. 17 | ; 18 | ;Returns: 19 | ; Object. An ImperiusServer instance. 20 | Func ImperiusServer($sIP = "localhost", $iPort = 7120, $sDeviceID = "", $sLocalServerPath = "", $iTimeout = 30000) 21 | Local $oClassObject = _AutoItObject_Class() 22 | $oClassObject.Create() 23 | Local $oDevice = "" 24 | Local $oLogger = Logger() 25 | $oLogger.setLevel($LOG_INFO) 26 | Local $oAdb = Adb($sDeviceID, $oLogger) 27 | 28 | If($sLocalServerPath == "") Then 29 | $sLocalServerPath = EnvGet("IMPERIUS") 30 | If ($sLocalServerPath == "") Then 31 | MsgBox(16, "Error", "Error: IMPERIUS environment variable is not set.") 32 | Exit 33 | EndIf 34 | EndIf 35 | $sLocalServerPath = $sLocalServerPath & "\" & $IMPERIUSSERVERJAR 36 | $oLogger.info("Imperius Server") 37 | $oLogger.info(StringFormat("IP: %s Port: %s DeviceID: %s Server: %s", $sIP,$iPort,$sDeviceID, $sLocalServerPath)) 38 | 39 | ;Methods 40 | With $oClassObject 41 | .AddMethod("getIP", "_GetIP") 42 | .AddMethod("getPort", "_GetPort") 43 | .AddMethod("getTimeout", "_GetTimeout") 44 | .AddMethod("getUrl", "_GetUrl") 45 | .AddMethod("getServerPath", "_GetServerPath") 46 | .AddMethod("getDeviceID", "__GetDeviceID") 47 | .AddMethod("getDevice", "_GetDevice") 48 | .AddMethod("getAdb", "_GetAdb") 49 | .AddMethod("getLogger", "_GetLogger") 50 | .AddMethod("start", "_StartServer") 51 | .AddMethod("stop", "_StopServer") 52 | EndWith 53 | 54 | ;Properties 55 | With $oClassObject 56 | .AddProperty("ip", $ELSCOPE_PRIVATE, $sIP) 57 | .AddProperty("port", $ELSCOPE_PRIVATE, $iPort) 58 | .AddProperty("timeout", $ELSCOPE_PRIVATE, $iTimeout) 59 | .AddProperty("path", $ELSCOPE_PRIVATE, $sLocalServerPath) 60 | .AddProperty("deviceID", $ELSCOPE_PRIVATE, $sDeviceID) 61 | .AddProperty("remotePath", $ELSCOPE_PRIVATE, "/data/local/tmp/" & $IMPERIUSSERVERJAR) 62 | .AddProperty("oDevice", $ELSCOPE_PRIVATE, $oDevice) 63 | .AddProperty("oAdb", $ELSCOPE_PRIVATE, $oAdb) 64 | .AddProperty("oLogger", $ELSCOPE_PRIVATE, $oLogger) 65 | EndWith 66 | 67 | Return $oClassObject.Object 68 | EndFunc ;==>ImperiusServer 69 | 70 | #Region Getters 71 | ;Function: _GetIP 72 | ;Gets the server IP. 73 | ; 74 | ;Parameters: 75 | ; $oSelf - Object reference. 76 | ; 77 | ;Returns: 78 | ; String. The server IP. 79 | Func _GetIP($oSelf) 80 | Return $oSelf.ip 81 | EndFunc ;==>_GetIP 82 | 83 | ;Function: _GetPort 84 | ;Gets the server Port. 85 | ; 86 | ;Parameters: 87 | ; $oSelf - Object reference. 88 | ; 89 | ;Returns: 90 | ; Int. The server port. 91 | Func _GetPort($oSelf) 92 | Return $oSelf.port 93 | EndFunc ;==>_GetPort 94 | 95 | ;Function: _GetTimeout 96 | ;Gets the server timeout. 97 | ; 98 | ;Parameters: 99 | ; $oSelf - Object reference. 100 | ; 101 | ;Returns: 102 | ; Int. The server timeout (miliseconds). 103 | Func _GetTimeout($oSelf) 104 | Return $oSelf.timeout 105 | EndFunc ;==>_GetTimeout 106 | 107 | ;Function: _GetURL 108 | ;Gets the URL. 109 | ; 110 | ;Parameters: 111 | ; $oSelf - Object reference. 112 | ; 113 | ;Returns: 114 | ; String. The server URL. 115 | Func _GetUrl($oSelf) 116 | Return 'http://' & $oSelf.ip & ':' & $oSelf.port & '/' 117 | EndFunc ;==>_GetUrl 118 | 119 | ;Function: _GetServerPath 120 | ;Gets the local full path to the server JAR file. 121 | ; 122 | ;Parameters: 123 | ; $oSelf - Object reference. 124 | ; 125 | ;Returns: 126 | ; String. The server local full path. 127 | Func _GetServerPath($oSelf) 128 | Return $oSelf.path 129 | EndFunc ;==>_GetServerPath 130 | 131 | ;Function: _GetDeviceID 132 | ;Gets the serial device. 133 | ; 134 | ;Parameters: 135 | ; $oSelf - Object reference. 136 | ; 137 | ;Returns: 138 | ; String. The serial device. 139 | Func __GetDeviceID($oSelf) 140 | Return $oSelf.deviceID 141 | EndFunc ;==>_GetDeviceID 142 | 143 | ;Function: _GetDevice 144 | ;Gets the UiDevice instance. 145 | ; 146 | ;Parameters: 147 | ; $oSelf - Object reference. 148 | ; 149 | ;Returns: 150 | ; Object. An UiDevice instance. 151 | Func _GetDevice($oSelf) 152 | If (IsString($oSelf.oDevice)) Then 153 | $oSelf.oDevice = UiDevice($oSelf, $oSelf.deviceID, $oSelf.oLogger) 154 | EndIf 155 | Return $oSelf.oDevice 156 | EndFunc ;==>_GetDevice 157 | 158 | ;Function: _GetAdb 159 | ;Gets the adb instance. 160 | ; 161 | ;Parameters: 162 | ; $oSelf - Object reference. 163 | ; 164 | ;Returns: 165 | ; Object. An Adb instance. 166 | Func _GetAdb($oSelf) 167 | Return $oSelf.oAdb 168 | EndFunc ;==>_GetAdb 169 | 170 | ;Function: _GetLogger 171 | ;Gets the Logger instance. 172 | ; 173 | ;Parameters: 174 | ; $oSelf - Object reference. 175 | ; 176 | ;Returns: 177 | ; Object. A Logger instance. 178 | Func _GetLogger($oSelf) 179 | Return $oSelf.oLogger 180 | EndFunc ;==>_GetLogger 181 | #EndRegion Getters 182 | 183 | #Region ServerManagement 184 | ;Function: _StartServer 185 | ;Start an Imperius server session on the device. 186 | ; 187 | ;Parameters: 188 | ; $oSelf - Object reference. 189 | Func _StartServer($oSelf) 190 | Local $iPort = $oSelf.port 191 | Local $sCommand = "uiautomator runtest " & $IMPERIUSSERVERJAR & " -c imperiusgeorge.TestServer -e port " & $iPort 192 | Local $oAdb = $oSelf.oAdb 193 | $oAdb.connect() 194 | 195 | If ($oAdb.fileExists($oSelf.remotePath) == False) Then 196 | $oAdb.push($oSelf.path, $oSelf.remotePath) 197 | EndIf 198 | 199 | With $oAdb 200 | .forward($iPort, $iPort) 201 | .shell($sCommand) 202 | EndWith 203 | EndFunc ;==>_StartServer 204 | 205 | ;Function: _StopServer 206 | ;Terminating a server session. 207 | ; 208 | ;Parameters: 209 | ; $oSelf - Object reference. 210 | Func _StopServer($oSelf) 211 | $oSelf.oDevice.stop() 212 | EndFunc ;==>_StopServer 213 | #EndRegion ServerManagement 214 | -------------------------------------------------------------------------------- /lib/logger.au3: -------------------------------------------------------------------------------- 1 | ;logger.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | ; 6 | ;Description: 7 | ; Logging. This object allows you to log messages with different log levels. 8 | ; Based on by jvanegmond. 9 | 10 | Global Enum $LOG_TRACE, $LOG_DEBUG, $LOG_INFO, $LOG_WARN, $LOG_ERROR, $LOG_FATAL 11 | 12 | ;Function: Logger 13 | ; 14 | ;Parameters: 15 | ; $sFileName - String. The full path to the log file. Writes log entries to a file. Defaul is empty (log to console). 16 | ; 17 | ;Returns: 18 | ; Object. A Looger instance. 19 | Func Logger($sFileName = "") 20 | Local $oClassObject = _AutoItObject_Class() 21 | $oClassObject.Create() 22 | Local $hLastLogHandle = -1 23 | Local $iLevel = $LOG_INFO 24 | Local $fLogFormat = _LogFormatDefault 25 | Local Const $LOG_LEVELSTRING[6] = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"] 26 | 27 | If ($sFileName <> "") Then 28 | $hLastLogHandle = FileOpen($sFileName, 1 + 8) 29 | EndIf 30 | 31 | ;Methods 32 | With $oClassObject 33 | .AddMethod("getLevel", "_GetLevel") 34 | .AddMethod("setLevel", "_LogLevel") 35 | .AddMethod("setFormat", "_LogFormat") 36 | .AddMethod("trace", "_LogTrace") 37 | .AddMethod("debug", "_LogDebug") 38 | .AddMethod("info", "_LogInfo") 39 | .AddMethod("warn", "_LogWarn") 40 | .AddMethod("error", "_LogError") 41 | .AddMethod("fatal", "_LogError") 42 | .AddDestructor("_LogClose") 43 | EndWith 44 | 45 | ;Properties 46 | With $oClassObject 47 | .AddProperty("logHandle", $ELSCOPE_PRIVATE, $hLastLogHandle) 48 | .AddProperty("fileName", $ELSCOPE_PRIVATE, $sFileName) 49 | .AddProperty("level", $ELSCOPE_PRIVATE, $iLevel) 50 | .AddProperty("format", $ELSCOPE_PRIVATE, $fLogFormat) 51 | .AddProperty("levelsString", $ELSCOPE_PRIVATE, $LOG_LEVELSTRING) 52 | EndWith 53 | 54 | Return $oClassObject.Object 55 | EndFunc ;==>Logger 56 | 57 | #Region Methods 58 | ;Function: _GetLevel 59 | ;Gets the actual log level. 60 | ; 61 | ;Parameters: 62 | ; $oSelf - Object reference. 63 | ; 64 | ;Returns: 65 | ; String. The actual level. 66 | Func _GetLevel($oSelf) 67 | Return $oSelf.levelsString[$oSelf.level] 68 | EndFunc ;==>_GetLevel 69 | 70 | ;Function: _LogLevel 71 | ;Sets the log level. Looger supports 6 logging levels: TRACE, DEBUG , INFO, WARNING , ERROR and FATAL. 72 | ;The default logging level is INFO. This means that only log entries with the logging level INFO and higher are output. 73 | ; 74 | ;Parameters: 75 | ; $iLevel - Int. The log level. $LOG_TRACE = 0, $LOG_DEBUG = 1 $LOG_INFO = 2, $LOG_WARN = 3, $LOG_ERROR = 4, $LOG_FATAL = 5. 76 | Func _LogLevel($oSelf, $iLevel) 77 | $oSelf.level = $iLevel 78 | EndFunc ;==>_LogLevel 79 | 80 | ;Function: _LogFormat 81 | ;Sets the log lormat . 82 | ; 83 | ;Parameters: 84 | ; $oSelf - Object reference. 85 | ; $fFormatFunc - Function. The function with the format. 86 | Func _LogFormat($oSelf, $fFormatFunc) 87 | $oSelf.format = $fFormatFunc 88 | EndFunc ;==>_LogFormat 89 | 90 | ;Function: _LogTrace 91 | ; 92 | ;Parameters: 93 | ; $oSelf - Object reference. 94 | ; $sMessage -String. The message to log. 95 | Func _LogTrace($oSelf, $sMessage) 96 | _LogMessage($oSelf, $LOG_TRACE, $sMessage) 97 | EndFunc ;==>_LogTrace 98 | 99 | ;Function: _LogDebug 100 | ; 101 | ;Parameters: 102 | ; $oSelf - Object reference. 103 | ; $sMessage -String. The message to log. 104 | Func _LogDebug($oSelf, $sMessage) 105 | _LogMessage($oSelf, $LOG_DEBUG, $sMessage) 106 | EndFunc ;==>_LogDebug 107 | 108 | ;Function: _LogInfo 109 | ; 110 | ;Parameters: 111 | ; $oSelf - Object reference. 112 | ; $sMessage -String. The message to log. 113 | Func _LogInfo($oSelf, $sMessage) 114 | _LogMessage($oSelf, $LOG_INFO, $sMessage) 115 | EndFunc ;==>_LogInfo 116 | 117 | ;Function: _LogWarn 118 | ; 119 | ;Parameters: 120 | ; $oSelf - Object reference. 121 | ; $sMessage -String. The message to log. 122 | Func _LogWarn($oSelf, $sMessage) 123 | _LogMessage($oSelf, $LOG_WARN, $sMessage) 124 | EndFunc ;==>_LogWarn 125 | 126 | ;Function: _LogError 127 | ; 128 | ;Parameters: 129 | ; $oSelf - Object reference. 130 | ; $sMessage -String. The message to log. 131 | Func _LogError($oSelf, $sMessage) 132 | _LogMessage($oSelf, $LOG_ERROR, $sMessage) 133 | EndFunc ;==>_LogError 134 | 135 | ;Function: _LogFatal 136 | ; 137 | ;Parameters: 138 | ; $oSelf - Object reference. 139 | ; $sMessage -String. The message to log. 140 | Func _LogFatal($oSelf, $sMessage) 141 | _LogMessage($oSelf, $LOG_FATAL, $sMessage) 142 | EndFunc ;==>_LogFatal 143 | 144 | ;Function: _LogMessage. 145 | ; 146 | ;Parameters: 147 | ; $oSelf - Object reference. 148 | ; $iLevel - Int. The log level. Default is INFO. 149 | ; $sMessage -String. The message to log. Default is "". 150 | Func _LogMessage($oSelf, $iLevel = $LOG_INFO, $sMessage = "") 151 | If ($iLevel < $oSelf.level) Then 152 | Return 153 | EndIf 154 | 155 | Local $sLevel = __LogLevelToString($oSelf, $iLevel) 156 | If @error Then 157 | ConsoleWriteError("Invalid log level given!") 158 | Return SetError(2, 0, -1) 159 | EndIf 160 | 161 | Local $fFormat = $oSelf.format 162 | $sMessage = $fFormat($sLevel, $sMessage) 163 | 164 | If $iLevel >= $LOG_ERROR Then 165 | ConsoleWriteError($sMessage & @CRLF) 166 | Else 167 | ConsoleWrite($sMessage & @CRLF) 168 | EndIf 169 | 170 | If ($oSelf .logHandle <> -1) Then 171 | FileWriteLine($oSelf .logHandle, $sMessage) 172 | EndIf 173 | EndFunc ;==>_LogMessage 174 | 175 | ;Function: _LogMessageUnformatted 176 | ; 177 | ;Parameters: 178 | ; $oSelf - Object reference. 179 | ; $sMessage -String. The message to log. 180 | Func _LogMessageUnformatted($oSelf, $sMessage) 181 | ConsoleWrite($sMessage & @CRLF) 182 | 183 | If ($oSelf .logHandle <> -1) Then 184 | FileWriteLine($oSelf .logHandle, $sMessage) 185 | EndIf 186 | EndFunc ;==>_LogMessageUnformatted 187 | 188 | ;Function: _LogLevelToString 189 | ; 190 | ;Parameters: 191 | ; $oSelf - Object reference. 192 | ; $iLevel - Int. The log level. 193 | ; 194 | ;Returns: 195 | ; String. The log level. 196 | Func __LogLevelToString($oSelf, $iLevel) 197 | If $iLevel < 0 Or $iLevel > UBound($oSelf.levelsString) - 1 Then 198 | Return SetError(1, 0, "") 199 | EndIf 200 | 201 | Return $oSelf.levelsString[$iLevel] 202 | EndFunc ;==>__LogLevelToString 203 | 204 | ;Function: _LogClose 205 | ; 206 | ;Parameters: 207 | ; $oSelf - Object reference. 208 | Func _LogClose($oSelf) 209 | If ($oSelf .logHandle <> -1) Then 210 | FileClose($oSelf.logHandle) 211 | EndIf 212 | $oSelf.logHandle = -1 213 | #forceref $oSelf 214 | EndFunc ;==>_LogClose 215 | 216 | ;Function: _LogFormatDefault 217 | ; 218 | ;Parameters: 219 | ; $iLevel - Int. The log level. 220 | ; $sMessage -String. The message to log. 221 | ; 222 | ;Returns: 223 | ; String. The message with the default format. 224 | Func _LogFormatDefault($sLevel, $sMessage) 225 | If (IsArray($sMessage)) Then 226 | $sMessage = _ArrayToString($sMessage) 227 | EndIf 228 | Return "[" & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " " & $sLevel & "] " & $sMessage 229 | EndFunc ;==>_LogFormatDefault 230 | #EndRegion Methods 231 | -------------------------------------------------------------------------------- /lib/adb.au3: -------------------------------------------------------------------------------- 1 | ;adb.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | ; 6 | ;Description: 7 | ;An ADB pseudo-client. Based on by Kyaw Swar Thwin. 8 | 9 | ;Function: Adb 10 | ; 11 | ;Parameters: 12 | ; $sDevice - String. The device serial id.Default is empty. 13 | ; $oLogger - Object. A Looger instance. Defualt is empty. 14 | ; 15 | ;Returns: 16 | ; Object. An Adb instance. 17 | Func Adb($sDeviceID = "", $oLogger = "") 18 | Local $oClassObject = _AutoItObject_Class() 19 | $oClassObject.Create() 20 | 21 | ;Methods 22 | With $oClassObject 23 | .AddMethod("connect", "_Adb_Connect") 24 | .AddMethod("isOnline", "_Adb_IsOnline") 25 | .AddMethod("isOffline", "_Adb_IsOffline") 26 | .AddMethod("fileExists", "_Adb_FileExists") 27 | .AddMethod("install", "_Adb_Install") 28 | .AddMethod("uninstall", "_Adb_Uninstall") 29 | .AddMethod("push", "_Adb_Push") 30 | .AddMethod("pull", "_Adb_Pull") 31 | .AddMethod("shell", "_Adb_Shell") 32 | .AddMethod("run", "_Adb_Run") 33 | .AddMethod("forward", "_Adb_Forward") 34 | .AddMethod("stopPackage", "_Adb_StopPackage") 35 | .AddMethod("getMemoryInfo", "_Adb_GetMemoryInfo") 36 | EndWith 37 | 38 | ;Properties 39 | With $oClassObject 40 | .AddProperty("deviceId", $ELSCOPE_PRIVATE, $sDeviceID) 41 | .AddProperty("oLogger", $ELSCOPE_PRIVATE, $oLogger) 42 | EndWith 43 | 44 | Return $oClassObject.Object 45 | EndFunc ;==>Adb 46 | 47 | #Region Methods 48 | ;Function: __Run 49 | ;A wrapper for Run function. Runs an external program. 50 | ; 51 | ;Parameters: 52 | ; $oSelf - Object reference. 53 | ; $sCommand - String. The command to execute. 54 | ; 55 | ;Returns: 56 | ; String. The command output. 57 | Func __Run($oSelf, $sCommand) 58 | Local $iPID, $sLine, $sOutput = "" 59 | $iPID = Run(@ComSpec & " /c " & $sCommand & " 2>&1", @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) 60 | While 1 61 | $sLine = StdoutRead($iPID) 62 | If (@error Or StringInStr($sLine, "Starting server on port") <> 0) Then 63 | ExitLoop 64 | EndIf 65 | $sOutput &= $sLine 66 | WEnd 67 | StdioClose($iPID) 68 | $sOutput = StringStripCR(StringTrimRight($sOutput, StringLen(@CRLF))) 69 | If (IsObj($oSelf.oLogger)) Then 70 | $oSelf.oLogger.info("[ADB] Run command:" & $sCommand & ". Result:" & $sOutput) 71 | EndIf 72 | Return $sOutput 73 | EndFunc ;==>__Run 74 | 75 | ;Function: _Adb_Connect 76 | ;Start the adb server process. 77 | ; 78 | ;Parameters: 79 | ; $oSelf - Object reference. 80 | ; 81 | ;Returns: 82 | ; 83 | Func _Adb_Connect($oSelf) 84 | __Run($oSelf, "adb start-server") 85 | EndFunc ;==>_Adb_Connect 86 | 87 | ;Function: _Adb_IsOffline 88 | ;Check if the adb server is offline. 89 | ; 90 | ;Parameters: 91 | ; $oSelf - Object reference. 92 | ; 93 | ;Returns: 94 | ; 95 | Func _Adb_IsOffline($oSelf) 96 | Return __Run($oSelf, "adb get-state") = "offline" 97 | EndFunc ;==>_Adb_IsOffline 98 | 99 | ;Function: _Adb_IsOnline 100 | ;Check if the adb server is online. 101 | ; 102 | ;Parameters: 103 | ; $oSelf - Object reference. 104 | ; 105 | ;Returns: 106 | ; 107 | Func _Adb_IsOnline($oSelf) 108 | Return __Run($oSelf, "adb get-state") = "device" 109 | EndFunc ;==>_Adb_IsOnline 110 | 111 | ;Function: _Adb_Install 112 | ;Pushes an Android application (specified as a full path to an .apk file) to an emulator/device. 113 | ; 114 | ;Parameters: 115 | ; $oSelf - Object reference. 116 | ; $sFilePath - String. The full path to the .apk file. 117 | ; $iMode - String. 1=Install on Internal Storage 2=Install application on sdcard. Default is 1. 118 | ; $bReinstall - Boolean. True = Install on Internal Storage. Default is False. 119 | ; 120 | ;Returns: 121 | ; Boolean Success: True Failure: False. 122 | Func _Adb_Install($oSelf, $sFilePath, $iMode = 1, $bReinstall = False) 123 | Local $aOutput 124 | If $iMode = Default Then $iMode = 1 125 | If $bReinstall = Default Then $bReinstall = False 126 | If $iMode = 2 Then ; Install on SD Card 127 | If $bReinstall Then 128 | $aOutput = StringSplit(_Adb_Run($oSelf, 'install -r -s "' & $sFilePath & '"'), @LF) 129 | Else 130 | $aOutput = StringSplit(_Adb_Run($oSelf, 'install -s "' & $sFilePath & '"'), @LF) 131 | EndIf 132 | Else ; Install on Internal Storage 133 | If $bReinstall Then 134 | $aOutput = StringSplit(_Adb_Run($oSelf, 'install -r "' & $sFilePath & '"'), @LF) 135 | Else 136 | $aOutput = StringSplit(_Adb_Run($oSelf, 'install "' & $sFilePath & '"'), @LF) 137 | EndIf 138 | EndIf 139 | If $aOutput[UBound($aOutput) - 1] <> "Success" Then 140 | $aOutput = _StringBetween($aOutput[UBound($aOutput) - 1], "[", "]") 141 | If Not @error Then 142 | Switch $aOutput[0] 143 | Case "INSTALL_FAILED_ALREADY_EXISTS" 144 | Return SetError(1, 0, $INSTALL_FAILED_ALREADY_EXISTS) 145 | Case "INSTALL_FAILED_INVALID_APK" 146 | Return SetError(1, 0, $INSTALL_FAILED_INVALID_APK) 147 | Case "INSTALL_FAILED_INVALID_URI" 148 | Return SetError(1, 0, $INSTALL_FAILED_INVALID_URI) 149 | Case "INSTALL_FAILED_INSUFFICIENT_STORAGE" 150 | Return SetError(1, 0, $INSTALL_FAILED_INSUFFICIENT_STORAGE) 151 | Case "INSTALL_FAILED_DUPLICATE_PACKAGE" 152 | Return SetError(1, 0, $INSTALL_FAILED_DUPLICATE_PACKAGE) 153 | Case "INSTALL_FAILED_NO_SHARED_USER" 154 | Return SetError(1, 0, $INSTALL_FAILED_NO_SHARED_USER) 155 | Case "INSTALL_FAILED_UPDATE_INCOMPATIBLE" 156 | Return SetError(1, 0, $INSTALL_FAILED_UPDATE_INCOMPATIBLE) 157 | Case "INSTALL_FAILED_SHARED_USER_INCOMPATIBLE" 158 | Return SetError(1, 0, $INSTALL_FAILED_SHARED_USER_INCOMPATIBLE) 159 | Case "INSTALL_FAILED_MISSING_SHARED_LIBRARY" 160 | Return SetError(1, 0, $INSTALL_FAILED_MISSING_SHARED_LIBRARY) 161 | Case "INSTALL_FAILED_REPLACE_COULDNT_DELETE" 162 | Return SetError(1, 0, $INSTALL_FAILED_REPLACE_COULDNT_DELETE) 163 | Case "INSTALL_FAILED_DEXOPT" 164 | Return SetError(1, 0, $INSTALL_FAILED_DEXOPT) 165 | Case "INSTALL_FAILED_OLDER_SDK" 166 | Return SetError(1, 0, $INSTALL_FAILED_OLDER_SDK) 167 | Case "INSTALL_FAILED_CONFLICTING_PROVIDER" 168 | Return SetError(1, 0, $INSTALL_FAILED_CONFLICTING_PROVIDER) 169 | Case "INSTALL_FAILED_NEWER_SDK" 170 | Return SetError(1, 0, $INSTALL_FAILED_NEWER_SDK) 171 | Case "INSTALL_FAILED_TEST_ONLY" 172 | Return SetError(1, 0, $INSTALL_FAILED_TEST_ONLY) 173 | Case "INSTALL_FAILED_CPU_ABI_INCOMPATIBLE" 174 | Return SetError(1, 0, $INSTALL_FAILED_CPU_ABI_INCOMPATIBLE) 175 | Case "INSTALL_FAILED_MISSING_FEATURE" 176 | Return SetError(1, 0, $INSTALL_FAILED_MISSING_FEATURE) 177 | Case "INSTALL_FAILED_CONTAINER_ERROR" 178 | Return SetError(1, 0, $INSTALL_FAILED_CONTAINER_ERROR) 179 | Case "INSTALL_FAILED_INVALID_INSTALL_LOCATION" 180 | Return SetError(1, 0, $INSTALL_FAILED_INVALID_INSTALL_LOCATION) 181 | Case "INSTALL_FAILED_MEDIA_UNAVAILABLE" 182 | Return SetError(1, 0, $INSTALL_FAILED_MEDIA_UNAVAILABLE) 183 | Case "INSTALL_FAILED_VERIFICATION_TIMEOUT" 184 | Return SetError(1, 0, $INSTALL_FAILED_VERIFICATION_TIMEOUT) 185 | Case "INSTALL_FAILED_VERIFICATION_FAILURE" 186 | Return SetError(1, 0, $INSTALL_FAILED_VERIFICATION_FAILURE) 187 | Case "INSTALL_FAILED_PACKAGE_CHANGED" 188 | Return SetError(1, 0, $INSTALL_FAILED_PACKAGE_CHANGED) 189 | Case "INSTALL_FAILED_UID_CHANGED" 190 | Return SetError(1, 0, $INSTALL_FAILED_UID_CHANGED) 191 | Case "INSTALL_FAILED_VERSION_DOWNGRADE" 192 | Return SetError(1, 0, $INSTALL_FAILED_VERSION_DOWNGRADE) 193 | Case "INSTALL_FAILED_INTERNAL_ERROR" 194 | Return SetError(1, 0, $INSTALL_FAILED_INTERNAL_ERROR) 195 | Case "INSTALL_FAILED_USER_RESTRICTED" 196 | Return SetError(1, 0, $INSTALL_FAILED_USER_RESTRICTED) 197 | EndSwitch 198 | Else 199 | Return SetError(1, 0, 0) 200 | EndIf 201 | EndIf 202 | Return $INSTALL_SUCCEEDED 203 | EndFunc ;==>_Adb_Install 204 | 205 | ;Function: _Adb_Uninstall 206 | ;Removes a package from the emulator/device. 207 | ; 208 | ;Parameters: 209 | ; $oSelf - Object reference. 210 | ; $sPackage -String. The package to remove. 211 | ; $bKeepDataCache - Boolean. Keep the data and cache directories around after package removal.Default is False. 212 | ; 213 | ;Returns: 214 | ; Int. Success: 1 Failure: . 215 | Func _Adb_Uninstall($oSelf, $sPackage, $bKeepDataCache = False) 216 | Local $sOutput 217 | If $bKeepDataCache = Default Then $bKeepDataCache = False 218 | If $bKeepDataCache Then 219 | $sOutput = _Adb_Run($oSelf, 'uninstall -k ' & $sPackage) 220 | Else 221 | $sOutput = _Adb_Run($oSelf, 'uninstall ' & $sPackage) 222 | EndIf 223 | If $sOutput <> "Success" Then Return SetError(1, 0, 0) 224 | Return 1 225 | EndFunc ;==>_Adb_Uninstall 226 | 227 | ;Function: _Adb_Push 228 | ;Upload a specified file from your computer to an emulator/device. 229 | ; 230 | ;Parameters: 231 | ; $oSelf - Object reference. 232 | ; $sLocalPath - String. The full local path to the file to upload. 233 | ; $sRemotePath - String. 234 | ; 235 | ;Returns: 236 | ; Int. Success: 1 Failure: . 237 | Func _Adb_Push($oSelf, $sLocalPath, $sRemotePath) 238 | Return _Adb_Run($oSelf, 'push "' & $sLocalPath & '" "' & $sRemotePath & '"') 239 | EndFunc ;==>_Adb_Push 240 | 241 | ;Function: _Adb_Pull 242 | ;Download a specified file from an emulator/device to your computer. 243 | ; 244 | ;Parameters: 245 | ; $oSelf - Object reference. 246 | ; $sRemotePath - String. 247 | ; $sLocalPath - String. 248 | ; 249 | ;Returns: 250 | ; Int. Success: 1 Failure: . 251 | Func _Adb_Pull($oSelf, $sRemotePath, $sLocalPath) 252 | Return _Adb_Run($oSelf, 'pull "' & $sRemotePath & '" "' & $sLocalPath & '"') 253 | EndFunc ;==>_Adb_Pull 254 | 255 | ;Function: _Adb_Forward 256 | ;Forward socket connections. 257 | ; 258 | ;Parameters: 259 | ; $oSelf - Object reference. 260 | ; $iLocal - Int. The local port. 261 | ; $iRemote - Int. The remote port. 262 | Func _Adb_Forward($oSelf, $iLocal, $iRemote) 263 | _Adb_Run($oSelf, 'forward tcp:' & $iLocal & ' tcp:' & $iRemote) 264 | EndFunc ;==>_Adb_Forward 265 | 266 | ;Function: _Adb_FileExist 267 | ;Checks if a file or directory exists. 268 | ; 269 | ;Parameters: 270 | ; $oSelf - Object reference. 271 | ; $sFilePath - String. The directory or file to check. 272 | ; 273 | ;Returns: 274 | ; Boolean. Success: True Failure: False. 275 | Func _Adb_FileExists($oSelf, $sFilePath) 276 | Local $sResponse = _Adb_Shell($oSelf, 'if [ -e \"' & $sFilePath & '\" ]; then echo \"Found\"; else echo \"Not Found\"; fi') = "Found" 277 | Return ($sResponse == "Found") ? True : False 278 | EndFunc ;==>_Adb_FileExists 279 | 280 | ;Function: _Adb_GetMemoryInfo 281 | ;Get currently memory consumption of an application. 282 | ; 283 | ;Parameters: 284 | ; $oSelf - Object reference. 285 | ; $sPackage - String. The package. 286 | ; 287 | ;Returns: 288 | ; Success: An array with these values: 289 | ; - element [0] contains the value of Proportional Set Size (PSS). 290 | ; - element [1] contains the value of Private Dirty RAM. 291 | ; - element [2] contains the value of Private Clean RAM. 292 | ; - element [3] contains the value of Swapped Dirty RAM. 293 | ; - element [4] contains the value of Heap Size RAM. 294 | ; - element [5] contains the value of Heap Alloc RAM. 295 | ; - element [6] contains the value of Heap Free RAM. 296 | ; Failure: sets the @error flag to non-zero. 297 | Func _Adb_GetMemoryInfo($oSelf, $sPackage) 298 | Local Enum $PPS, $PDR, $PCR, $SDR, $HSR, $HAR, $HFR 299 | Local $aResult[7] 300 | Local $sResponse = _Adb_Shell($oSelf, 'dumpsys meminfo ' & $sPackage) 301 | ;TODO: Please, someone remove this ugly memory parser and make a better regex based parser 302 | ;for this output. Thank you. 303 | Local $aTotal = _StringBetween($sResponse, "TOTAL ", "", Default, True) 304 | Local $iError = @error 305 | If $iError Then Return SetError($iError, 0) 306 | Local $aTemp = StringSplit(StringStripWS($aTotal[0], $STR_STRIPSPACES), " ") 307 | $aResult[$PPS] = $aTemp[1] 308 | $aResult[$PDR] = $aTemp[2] 309 | $aResult[$PCR] = $aTemp[3] 310 | $aResult[$SDR] = $aTemp[4] 311 | $aResult[$HSR] = $aTemp[5] 312 | $aResult[$HAR] = $aTemp[6] 313 | $aResult[$HFR] = StringRegExpReplace($aTemp[7], "\D", "") 314 | Return $aResult 315 | EndFunc ;==>_Adb_GetMemoryInfo 316 | 317 | ;Function: _Adb_StopPackage 318 | ;Force stop everything associated with the given package. 319 | ; 320 | ;Parameters: 321 | ; $oSelf - Object reference. 322 | ; $sPackage - String. The package. 323 | ; 324 | ;Returns: 325 | ; String. The command output. 326 | Func _Adb_StopPackage($oSelf, $sPackage) 327 | Return _Adb_Shell($oSelf, 'am force-stop ' & $sPackage) 328 | EndFunc ;==>_Adb_StopPackage 329 | 330 | ;Function: _Adb_Shell 331 | ;Exceute a shell command. 332 | ; 333 | ;Parameters: 334 | ; $oSelf - Object reference. 335 | ; $sCommand - String. The shell command to execute. 336 | ; 337 | ;Returns: 338 | ; Int. Success: 1 Failure: . 339 | Func _Adb_Shell($oSelf, $sCommand) 340 | Return _Adb_Run($oSelf, 'shell "' & $sCommand & '"') 341 | EndFunc ;==>_Adb_Shell 342 | 343 | ;Function: _Adb_Run 344 | ;Exceute an adb command. 345 | ; 346 | ;Parameters: 347 | ; $oSelf - Object reference. 348 | ; $sCommand - String. The command to execute. 349 | ; 350 | ;Returns: 351 | ; Int. Success: 1 Failure: . 352 | Func _Adb_Run($oSelf, $sCommand) 353 | Local $sSerial = ($oSelf.deviceId <> "") ? "-s " & $oSelf.deviceId : "" 354 | Return __Run($oSelf, 'adb ' & $sSerial & ' ' & $sCommand) 355 | EndFunc ;==>_Adb_Run 356 | #EndRegion Methods 357 | -------------------------------------------------------------------------------- /lib/android.keys.constants.au3: -------------------------------------------------------------------------------- 1 | ;android.keys.constants.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | 6 | #include-once 7 | ; Key code constant: Unknown key code. 8 | Global Const $KEYCODE_UNKNOWN = 0 9 | ; Key code constant: Soft Left key. Usually situated below the display on phones and used as a 10 | ; multi-function feature key for selecting a software defined function shown on the bottom left 11 | ; of the display. 12 | Global Const $KEYCODE_SOFT_LEFT = 1 13 | ; Key code constant: Soft Right key. Usually situated below the display on phones and used as a 14 | ; multi-function feature key for selecting a software defined function shown on the bottom right 15 | ; of the display. 16 | Global Const $KEYCODE_SOFT_RIGHT = 2 17 | ; Key code constant: Home key. This key is handled by the framework and is never delivered to 18 | ; applications. 19 | Global Const $KEYCODE_HOME = 3 20 | ; Key code constant: Back key. 21 | Global Const $KEYCODE_BACK = 4 22 | ; Key code constant: Call key. 23 | Global Const $KEYCODE_CALL = 5 24 | ; Key code constant: End Call key. 25 | Global Const $KEYCODE_ENDCALL = 6 26 | ; Key code constant: '0' key. 27 | Global Const $KEYCODE_0 = 7 28 | ; Key code constant: '1' key. 29 | Global Const $KEYCODE_1 = 8 30 | ; Key code constant: '2' key. 31 | Global Const $KEYCODE_2 = 9 32 | ; Key code constant: '3' key. 33 | Global Const $KEYCODE_3 = 10 34 | ; Key code constant: '4' key. 35 | Global Const $KEYCODE_4 = 11 36 | ; Key code constant: '5' key. 37 | Global Const $KEYCODE_5 = 12 38 | ; Key code constant: '6' key. 39 | Global Const $KEYCODE_6 = 13 40 | ; Key code constant: '7' key. 41 | Global Const $KEYCODE_7 = 14 42 | ; Key code constant: '8' key. 43 | Global Const $KEYCODE_8 = 15 44 | ; Key code constant: '9' key. 45 | Global Const $KEYCODE_9 = 16 46 | ; Key code constant: ';' key. 47 | Global Const $KEYCODE_STAR = 17 48 | ; Key code constant: '#' key. 49 | Global Const $KEYCODE_POUND = 18 50 | ; Key code constant: Directional Pad Up key. May also be synthesized from trackball motions. 51 | Global Const $KEYCODE_DPAD_UP = 19 52 | ; Key code constant: Directional Pad Down key. May also be synthesized from trackball motions. 53 | Global Const $KEYCODE_DPAD_DOWN = 20 54 | ; Key code constant: Directional Pad Left key. May also be synthesized from trackball motions. 55 | Global Const $KEYCODE_DPAD_LEFT = 21 56 | ; Key code constant: Directional Pad Right key. May also be synthesized from trackball motions. 57 | Global Const $KEYCODE_DPAD_RIGHT = 22 58 | ; Key code constant: Directional Pad Center key. May also be synthesized from trackball motions. 59 | Global Const $KEYCODE_DPAD_CENTER = 23 60 | ; Key code constant: Volume Up key. Adjusts the speaker volume up. 61 | Global Const $KEYCODE_VOLUME_UP = 24 62 | ; Key code constant: Volume Down key. Adjusts the speaker volume down. 63 | Global Const $KEYCODE_VOLUME_DOWN = 25 64 | ; Key code constant: Power key. 65 | Global Const $KEYCODE_POWER = 26 66 | ; Key code constant: Camera key. Used to launch a camera application or take pictures. 67 | Global Const $KEYCODE_CAMERA = 27 68 | ; Key code constant: Clear key. 69 | Global Const $KEYCODE_CLEAR = 28 70 | ; Key code constant: 'A' key. 71 | Global Const $KEYCODE_A = 29 72 | ; Key code constant: 'B' key. 73 | Global Const $KEYCODE_B = 30 74 | ; Key code constant: 'C' key. 75 | Global Const $KEYCODE_C = 31 76 | ; Key code constant: 'D' key. 77 | Global Const $KEYCODE_D = 32 78 | ; Key code constant: 'E' key. 79 | Global Const $KEYCODE_E = 33 80 | ; Key code constant: 'F' key. 81 | Global Const $KEYCODE_F = 34 82 | ; Key code constant: 'G' key. 83 | Global Const $KEYCODE_G = 35 84 | ; Key code constant: 'H' key. 85 | Global Const $KEYCODE_H = 36 86 | ; Key code constant: 'I' key. 87 | Global Const $KEYCODE_I = 37 88 | ; Key code constant: 'J' key. 89 | Global Const $KEYCODE_J = 38 90 | ; Key code constant: 'K' key. 91 | Global Const $KEYCODE_K = 39 92 | ; Key code constant: 'L' key. 93 | Global Const $KEYCODE_L = 40 94 | ; Key code constant: 'M' key. 95 | Global Const $KEYCODE_M = 41 96 | ; Key code constant: 'N' key. 97 | Global Const $KEYCODE_N = 42 98 | ; Key code constant: 'O' key. 99 | Global Const $KEYCODE_O = 43 100 | ; Key code constant: 'P' key. 101 | Global Const $KEYCODE_P = 44 102 | ; Key code constant: 'Q' key. 103 | Global Const $KEYCODE_Q = 45 104 | ; Key code constant: 'R' key. 105 | Global Const $KEYCODE_R = 46 106 | ; Key code constant: 'S' key. 107 | Global Const $KEYCODE_S = 47 108 | ; Key code constant: 'T' key. 109 | Global Const $KEYCODE_T = 48 110 | ; Key code constant: 'U' key. 111 | Global Const $KEYCODE_U = 49 112 | ; Key code constant: 'V' key. 113 | Global Const $KEYCODE_V = 50 114 | ; Key code constant: 'W' key. 115 | Global Const $KEYCODE_W = 51 116 | ; Key code constant: 'X' key. 117 | Global Const $KEYCODE_X = 52 118 | ; Key code constant: 'Y' key. 119 | Global Const $KEYCODE_Y = 53 120 | ; Key code constant: 'Z' key. 121 | Global Const $KEYCODE_Z = 54 122 | ; Key code constant: ',' key. 123 | Global Const $KEYCODE_COMMA = 55 124 | ; Key code constant: '.' key. 125 | Global Const $KEYCODE_PERIOD = 56 126 | ; Key code constant: Left Alt modifier key. 127 | Global Const $KEYCODE_ALT_LEFT = 57 128 | ; Key code constant: Right Alt modifier key. 129 | Global Const $KEYCODE_ALT_RIGHT = 58 130 | ; Key code constant: Left Shift modifier key. 131 | Global Const $KEYCODE_SHIFT_LEFT = 59 132 | ; Key code constant: Right Shift modifier key. 133 | Global Const $KEYCODE_SHIFT_RIGHT = 60 134 | ; Key code constant: Tab key. 135 | Global Const $KEYCODE_TAB = 61 136 | ; Key code constant: Space key. 137 | Global Const $KEYCODE_SPACE = 62 138 | ; Key code constant: Symbol modifier key. Used to enter alternate symbols. 139 | Global Const $KEYCODE_SYM = 63; 140 | ; Key code constant: Explorer special function key. Used to launch a browser application. 141 | Global Const $KEYCODE_EXPLORER = 64 142 | ; Key code constant: Envelope special function key. Used to launch a mail application. 143 | Global Const $KEYCODE_ENVELOPE = 65 144 | ; Key code constant: Enter key. 145 | Global Const $KEYCODE_ENTER = 66 146 | ; Key code constant: Backspace key. Deletes characters before the insertion point, unlike 147 | ; {@link #$KEYCODE_FORWARD_DEL}. 148 | Global Const $KEYCODE_DEL = 67 149 | ; Key code constant: '`' (backtick) key. 150 | Global Const $KEYCODE_GRAVE = 68 151 | ; Key code constant: '-'. 152 | Global Const $KEYCODE_MINUS = 69 153 | ; Key code constant: '=' key. 154 | Global Const $KEYCODE_EQUALS = 70 155 | ; Key code constant: '[' key. 156 | Global Const $KEYCODE_LEFT_BRACKET = 71 157 | ; Key code constant: ']' key. 158 | Global Const $KEYCODE_RIGHT_BRACKET = 72 159 | ; Key code constant: '\' key. 160 | Global Const $KEYCODE_BACKSLASH = 73 161 | ; Key code constant: ';' key. 162 | Global Const $KEYCODE_SEMICOLON = 74 163 | ; Key code constant: ''' (apostrophe) key. 164 | Global Const $KEYCODE_APOSTROPHE = 75 165 | ; Key code constant: '/' key. 166 | Global Const $KEYCODE_SLASH = 76 167 | ; Key code constant: '@' key. 168 | Global Const $KEYCODE_AT = 77 169 | ; Key code constant: Number modifier key. Used to enter numeric symbols. 170 | Global Const $KEYCODE_NUM = 78 171 | ; Key code constant: Headset Hook key. Used to hang up calls and stop media. 172 | Global Const $KEYCODE_HEADSETHOOK = 79 173 | ; Key code constant: Camera Focus key. Used to focus the camera. 174 | Global Const $KEYCODE_FOCUS = 80 ;Camera; focus 175 | ; Key code constant: '+' key. 176 | Global Const $KEYCODE_PLUS = 81 177 | ; Key code constant: Menu key. 178 | Global Const $KEYCODE_MENU = 82 179 | ; Key code constant: Notification key. 180 | Global Const $KEYCODE_NOTIFICATION = 83 181 | ; Key code constant: Search key. 182 | Global Const $KEYCODE_SEARCH = 84 183 | ; Key code constant: Play/Pause media key. 184 | Global Const $KEYCODE_MEDIA_PLAY_PAUSE = 85 185 | ; Key code constant: Stop media key. 186 | Global Const $KEYCODE_MEDIA_STOP = 86 187 | ; Key code constant: Play Next media key. 188 | Global Const $KEYCODE_MEDIA_NEXT = 87 189 | ; Key code constant: Play Previous media key. 190 | Global Const $KEYCODE_MEDIA_PREVIOUS = 88 191 | ; Key code constant: Rewind media key. 192 | Global Const $KEYCODE_MEDIA_REWIND = 89 193 | ; Key code constant: Fast Forward media key. 194 | Global Const $KEYCODE_MEDIA_FAST_FORWARD = 90 195 | ; Key code constant: Mute key. Mutes the microphone, unlike {@link #$KEYCODE_VOLUME_MUTE}. 196 | Global Const $KEYCODE_MUTE = 91 197 | ; Key code constant: Page Up key. 198 | Global Const $KEYCODE_PAGE_UP = 92 199 | ; Key code constant: Page Down key. 200 | Global Const $KEYCODE_PAGE_DOWN = 93 201 | ; Key code constant: Picture Symbols modifier key. Used to switch symbol sets (Emoji, Kao-moji). 202 | Global Const $KEYCODE_PICTSYMBOLS = 94; switch symbol-sets (Emoji, Kao - moji) 203 | ; Key code constant: Switch Charset modifier key. Used to switch character sets (Kanji, 204 | ; Katakana). 205 | Global Const $KEYCODE_SWITCH_CHARSET = 95; switch char-sets (Kanji, Katakana) 206 | ; Key code constant: A Button key. On a game controller, the A button should be either the button 207 | ; labeled A or the first button on the upper row of controller buttons. 208 | Global Const $KEYCODE_BUTTON_A = 96 209 | ; Key code constant: B Button key. On a game controller, the B button should be either the button 210 | ; labeled B or the second button on the upper row of controller buttons. 211 | Global Const $KEYCODE_BUTTON_B = 97 212 | ; Key code constant: C Button key. On a game controller, the C button should be either the button 213 | ; labeled C or the third button on the upper row of controller buttons. 214 | Global Const $KEYCODE_BUTTON_C = 98 215 | ; Key code constant: X Button key. On a game controller, the X button should be either the button 216 | ; labeled X or the first button on the lower row of controller buttons. 217 | Global Const $KEYCODE_BUTTON_X = 99 218 | ; Key code constant: Y Button key. On a game controller, the Y button should be either the button 219 | ; labeled Y or the second button on the lower row of controller buttons. 220 | Global Const $KEYCODE_BUTTON_Y = 100 221 | ; Key code constant: Z Button key. On a game controller, the Z button should be either the button 222 | ; labeled Z or the third button on the lower row of controller buttons. 223 | Global Const $KEYCODE_BUTTON_Z = 101 224 | ; Key code constant: L1 Button key. On a game controller, the L1 button should be either the 225 | ; button labeled L1 (or L) or the top left trigger button. 226 | Global Const $KEYCODE_BUTTON_L1 = 102 227 | ; Key code constant: R1 Button key. On a game controller, the R1 button should be either the 228 | ; button labeled R1 (or R) or the top right trigger button. 229 | Global Const $KEYCODE_BUTTON_R1 = 103 230 | ; Key code constant: L2 Button key. On a game controller, the L2 button should be either the 231 | ; button labeled L2 or the bottom left trigger button. 232 | Global Const $KEYCODE_BUTTON_L2 = 104 233 | ; Key code constant: R2 Button key. On a game controller, the R2 button should be either the 234 | ; button labeled R2 or the bottom right trigger button. 235 | Global Const $KEYCODE_BUTTON_R2 = 105 236 | ; Key code constant: Left Thumb Button key. On a game controller, the left thumb button indicates 237 | ; that the left (or only) joystick is pressed. 238 | Global Const $KEYCODE_BUTTON_THUMBL = 106 239 | ; Key code constant: Right Thumb Button key. On a game controller, the right thumb button 240 | ; indicates that the right joystick is pressed. 241 | Global Const $KEYCODE_BUTTON_THUMBR = 107 242 | ; Key code constant: Start Button key. On a game controller, the button labeled Start. 243 | Global Const $KEYCODE_BUTTON_START = 108 244 | ; Key code constant: Select Button key. On a game controller, the button labeled Select. 245 | Global Const $KEYCODE_BUTTON_SELECT = 109 246 | ; Key code constant: Mode Button key. On a game controller, the button labeled Mode. 247 | Global Const $KEYCODE_BUTTON_MODE = 110 248 | ; Key code constant: Escape key. 249 | Global Const $KEYCODE_ESCAPE = 111 250 | ; Key code constant: Forward Delete key. Deletes characters ahead of the insertion point. 251 | Global Const $KEYCODE_FORWARD_DEL = 112 252 | ; Key code constant: Left Control modifier key. 253 | Global Const $KEYCODE_CTRL_LEFT = 113 254 | ; Key code constant: Right Control modifier key. 255 | Global Const $KEYCODE_CTRL_RIGHT = 114 256 | ; Key code constant: Caps Lock key. 257 | Global Const $KEYCODE_CAPS_LOCK = 115 258 | ; Key code constant: Scroll Lock key. 259 | Global Const $KEYCODE_SCROLL_LOCK = 116 260 | ; Key code constant: Left Meta modifier key. 261 | Global Const $KEYCODE_META_LEFT = 117 262 | ; Key code constant: Right Meta modifier key. 263 | Global Const $KEYCODE_META_RIGHT = 118 264 | ; Key code constant: Function modifier key. 265 | Global Const $KEYCODE_FUNCTION = 119 266 | ; Key code constant: System Request / Print Screen key. 267 | Global Const $KEYCODE_SYSRQ = 120 268 | ; Key code constant: Break / Pause key. 269 | Global Const $KEYCODE_BREAK = 121 270 | ; Key code constant: Home Movement key. Used for scrolling or moving the cursor around to the 271 | ; start of a line or to the top of a list. 272 | Global Const $KEYCODE_MOVE_HOME = 122 273 | ; Key code constant: End Movement key. Used for scrolling or moving the cursor around to the end 274 | ; of a line or to the bottom of a list. 275 | Global Const $KEYCODE_MOVE_END = 123 276 | ; Key code constant: Insert key. Toggles insert / overwrite edit mode. 277 | Global Const $KEYCODE_INSERT = 124 278 | ; Key code constant: Forward key. Navigates forward in the history stack. 279 | Global Const $KEYCODE_FORWARD = 125 280 | ; Key code constant: Play media key. 281 | Global Const $KEYCODE_MEDIA_PLAY = 126 282 | ; Key code constant: Pause media key. 283 | Global Const $KEYCODE_MEDIA_PAUSE = 127 284 | ; Key code constant: Close media key. May be used to close a CD tray, for example. 285 | Global Const $KEYCODE_MEDIA_CLOSE = 128 286 | ; Key code constant: Eject media key. May be used to eject a CD tray, for example. 287 | Global Const $KEYCODE_MEDIA_EJECT = 129 288 | ; Key code constant: Record media key. 289 | Global Const $KEYCODE_MEDIA_RECORD = 130 290 | ; Key code constant: F1 key. 291 | Global Const $KEYCODE_F1 = 131 292 | ; Key code constant: F2 key. 293 | Global Const $KEYCODE_F2 = 132 294 | ; Key code constant: F3 key. 295 | Global Const $KEYCODE_F3 = 133 296 | ; Key code constant: F4 key. 297 | Global Const $KEYCODE_F4 = 134 298 | ; Key code constant: F5 key. 299 | Global Const $KEYCODE_F5 = 135 300 | ; Key code constant: F6 key. 301 | Global Const $KEYCODE_F6 = 136 302 | ; Key code constant: F7 key. 303 | Global Const $KEYCODE_F7 = 137 304 | ; Key code constant: F8 key. 305 | Global Const $KEYCODE_F8 = 138 306 | ; Key code constant: F9 key. 307 | Global Const $KEYCODE_F9 = 139 308 | ; Key code constant: F10 key. 309 | Global Const $KEYCODE_F10 = 140 310 | ; Key code constant: F11 key. 311 | Global Const $KEYCODE_F11 = 141 312 | ; Key code constant: F12 key. 313 | Global Const $KEYCODE_F12 = 142; 314 | ; Key code constant: Num Lock key. This is the Num Lock key; it is different from 315 | ; $KEYCODE_NUM. This key alters the behavior of other keys on the numeric keypad. 316 | Global Const $KEYCODE_NUM_LOCK = 143 317 | ; Key code constant: Numeric keypad '0' key. 318 | Global Const $KEYCODE_NUMPAD_0 = 144 319 | ; Key code constant: Numeric keypad '1' key. 320 | Global Const $KEYCODE_NUMPAD_1 = 145 321 | ; Key code constant: Numeric keypad '2' key. 322 | Global Const $KEYCODE_NUMPAD_2 = 146 323 | ; Key code constant: Numeric keypad '3' key. 324 | Global Const $KEYCODE_NUMPAD_3 = 147 325 | ; Key code constant: Numeric keypad '4' key. 326 | Global Const $KEYCODE_NUMPAD_4 = 148 327 | ; Key code constant: Numeric keypad '5' key. 328 | Global Const $KEYCODE_NUMPAD_5 = 149 329 | ; Key code constant: Numeric keypad '6' key. 330 | Global Const $KEYCODE_NUMPAD_6 = 150 331 | ; Key code constant: Numeric keypad '7' key. 332 | Global Const $KEYCODE_NUMPAD_7 = 151 333 | ; Key code constant: Numeric keypad '8' key. 334 | Global Const $KEYCODE_NUMPAD_8 = 152 335 | ; Key code constant: Numeric keypad '9' key. 336 | Global Const $KEYCODE_NUMPAD_9 = 153 337 | ; Key code constant: Numeric keypad '/' key (for division). 338 | Global Const $KEYCODE_NUMPAD_DIVIDE = 154 339 | ; Key code constant: Numeric keypad ';' key (for multiplication). 340 | Global Const $KEYCODE_NUMPAD_MULTIPLY = 155 341 | ; Key code constant: Numeric keypad '-' key (for subtraction). 342 | Global Const $KEYCODE_NUMPAD_SUBTRACT = 156 343 | ; Key code constant: Numeric keypad '+' key (for addition). 344 | Global Const $KEYCODE_NUMPAD_ADD = 157 345 | ; Key code constant: Numeric keypad '.' key (for decimals or digit grouping). 346 | Global Const $KEYCODE_NUMPAD_DOT = 158 347 | ; Key code constant: Numeric keypad ',' key (for decimals or digit grouping). 348 | Global Const $KEYCODE_NUMPAD_COMMA = 159 349 | ; Key code constant: Numeric keypad Enter key. 350 | Global Const $KEYCODE_NUMPAD_ENTER = 160 351 | ; Key code constant: Numeric keypad '=' key. 352 | Global Const $KEYCODE_NUMPAD_EQUALS = 161 353 | ; Key code constant: Numeric keypad '(' key. 354 | Global Const $KEYCODE_NUMPAD_LEFT_PAREN = 162 355 | ; Key code constant: Numeric keypad ')' key. 356 | Global Const $KEYCODE_NUMPAD_RIGHT_PAREN = 163 357 | ; Key code constant: Volume Mute key. Mutes the speaker, unlike {@link #$KEYCODE_MUTE}. This key 358 | ; should normally be implemented as a toggle such that the first press mutes the speaker and the 359 | ; second press restores the original volume. 360 | Global Const $KEYCODE_VOLUME_MUTE = 164 361 | ; Key code constant: Info key. Common on TV remotes to show additional information related to 362 | ; what is currently being viewed. 363 | Global Const $KEYCODE_INFO = 165 364 | ; Key code constant: Channel up key. On TV remotes, increments the television channel. 365 | Global Const $KEYCODE_CHANNEL_UP = 166 366 | ; Key code constant: Channel down key. On TV remotes, decrements the television channel. 367 | Global Const $KEYCODE_CHANNEL_DOWN = 167 368 | ; Key code constant: Zoom in key. 369 | Global Const $KEYCODE_ZOOM_IN = 168 370 | ; Key code constant: Zoom out key. 371 | Global Const $KEYCODE_ZOOM_OUT = 169 372 | ; Key code constant: TV key. On TV remotes, switches to viewing live TV. 373 | Global Const $KEYCODE_TV = 170 374 | ; Key code constant: Window key. On TV remotes, toggles picture-in-picture mode or other 375 | ; windowing functions. 376 | Global Const $KEYCODE_WINDOW = 171 377 | ; Key code constant: Guide key. On TV remotes, shows a programming guide. 378 | Global Const $KEYCODE_GUIDE = 172 379 | ; Key code constant: DVR key. On some TV remotes, switches to a DVR mode for recorded shows. 380 | Global Const $KEYCODE_DVR = 173; 381 | ; Key code constant: Bookmark key. On some TV remotes, bookmarks content or web pages. 382 | Global Const $KEYCODE_BOOKMARK = 174 383 | ; Key code constant: Toggle captions key. Switches the mode for closed-captioning text, for 384 | ; example during television shows. 385 | Global Const $KEYCODE_CAPTIONS = 175 386 | ; Key code constant: Settings key. Starts the system settings activity. 387 | Global Const $KEYCODE_SETTINGS = 176; 388 | ; Key code constant: TV power key. On TV remotes, toggles the power on a television screen. 389 | Global Const $KEYCODE_TV_POWER = 177 390 | ; Key code constant: TV input key. On TV remotes, switches the input on a television screen. 391 | Global Const $KEYCODE_TV_INPUT = 178 392 | ; Key code constant: Set-top-box power key. On TV remotes, toggles the power on an external 393 | ; Set-top-box. 394 | Global Const $KEYCODE_STB_POWER = 179 395 | ; Key code constant: Set-top-box input key. On TV remotes, switches the input mode on an external 396 | ; Set-top-box. 397 | Global Const $KEYCODE_STB_INPUT = 180 398 | ; Key code constant: A/V Receiver power key. On TV remotes, toggles the power on an external A/V 399 | ; Receiver. 400 | Global Const $KEYCODE_AVR_POWER = 181 401 | ; Key code constant: A/V Receiver input key. On TV remotes, switches the input mode on an 402 | ; external A/V Receiver. 403 | Global Const $KEYCODE_AVR_INPUT = 182 404 | ; Key code constant: Red "programmable" key. On TV remotes, acts as a contextual/programmable 405 | ; key. 406 | Global Const $KEYCODE_PROG_RED = 183 407 | ; Key code constant: Green "programmable" key. On TV remotes, actsas a contextual/programmable 408 | ; key. 409 | Global Const $KEYCODE_PROG_GREEN = 184 410 | ; Key code constant: Yellow "programmable" key. On TV remotes, acts as a contextual/programmable 411 | ; key. 412 | Global Const $KEYCODE_PROG_YELLOW = 185 413 | ; Key code constant: Blue "programmable" key. On TV remotes, acts as a contextual/programmable 414 | ; key. 415 | Global Const $KEYCODE_PROG_BLUE = 186 416 | ; Key code constant: App switch key. Should bring up the application switcher dialog. 417 | Global Const $KEYCODE_APP_SWITCH = 187 418 | ; Key code constant: Generic Game Pad Button #1. 419 | Global Const $KEYCODE_BUTTON_1 = 188 420 | ; Key code constant: Generic Game Pad Button #2. 421 | Global Const $KEYCODE_BUTTON_2 = 189 422 | ; Key code constant: Generic Game Pad Button #3. 423 | Global Const $KEYCODE_BUTTON_3 = 190 424 | ; Key code constant: Generic Game Pad Button #4. 425 | Global Const $KEYCODE_BUTTON_4 = 191 426 | ; Key code constant: Generic Game Pad Button #5. 427 | Global Const $KEYCODE_BUTTON_5 = 192 428 | ; Key code constant: Generic Game Pad Button #6. 429 | Global Const $KEYCODE_BUTTON_6 = 193 430 | ; Key code constant: Generic Game Pad Button #7. 431 | Global Const $KEYCODE_BUTTON_7 = 194 432 | ; Key code constant: Generic Game Pad Button #8. 433 | Global Const $KEYCODE_BUTTON_8 = 195 434 | ; Key code constant: Generic Game Pad Button #9. 435 | Global Const $KEYCODE_BUTTON_9 = 196; 436 | ; Key code constant: Generic Game Pad Button #10. 437 | Global Const $KEYCODE_BUTTON_10 = 197 438 | ; Key code constant: Generic Game Pad Button #11. 439 | Global Const $KEYCODE_BUTTON_11 = 198 440 | ; Key code constant: Generic Game Pad Button #12. 441 | Global Const $KEYCODE_BUTTON_12 = 199 442 | ; Key code constant: Generic Game Pad Button #13. 443 | Global Const $KEYCODE_BUTTON_13 = 200 444 | ; Key code constant: Generic Game Pad Button #14. 445 | Global Const $KEYCODE_BUTTON_14 = 201 446 | ; Key code constant: Generic Game Pad Button #15. 447 | Global Const $KEYCODE_BUTTON_15 = 202 448 | ; Key code constant: Generic Game Pad Button #16. 449 | Global Const $KEYCODE_BUTTON_16 = 203 450 | ; Key code constant: Language Switch key. Toggles the current input language such as switching 451 | ; between English and Japanese on a QWERTY keyboard. On some devices, the same function may be 452 | ; performed by pressing Shift+Spacebar. 453 | Global Const $KEYCODE_LANGUAGE_SWITCH = 204 454 | ; Key code constant: Manner Mode key. Toggles silent or vibrate mode on and off to make the 455 | ; device behave more politely in certain settings such as on a crowded train. On some devices, 456 | ; the key may only operate when long-pressed. 457 | Global Const $KEYCODE_MANNER_MODE = 205; 458 | ; Key code constant: 3D Mode key. Toggles the display between 2D and 3D mode. 459 | Global Const $KEYCODE_3D_MODE = 206 460 | ; Key code constant: Contacts special function key. Used to launch an address book application. 461 | Global Const $KEYCODE_CONTACTS = 207 462 | ; Key code constant: Calendar special function key. Used to launch a calendar application. 463 | Global Const $KEYCODE_CALENDAR = 208 464 | ; Key code constant: Music special function key. Used to launch a music player application. 465 | Global Const $KEYCODE_MUSIC = 209 466 | ; Key code constant: Calculator special function key. Used to launch a calculator application. 467 | Global Const $KEYCODE_CALCULATOR = 210 -------------------------------------------------------------------------------- /lib/uidevice.au3: -------------------------------------------------------------------------------- 1 | ;uidevice.au3 2 | ; 3 | ;Author: 4 | ; henrytejera@gmail.com 5 | ; 6 | ;Description: 7 | ; UiDevice provides access to state information about the device. 8 | ; You can also use this class to simulate user actions on the device, 9 | ; such as click over a widget or pressing the Home and Menu buttons. 10 | 11 | ;Function: UiDevice 12 | ; 13 | ;Parameters: 14 | ; $oServer - Objetc An ImperiusServer instance. 15 | ; $sDevice- String. The device serial id.Default is empty. 16 | ; $oLogger - Object. A Looger instance. Defualt is empty. 17 | ; 18 | ;Returns: 19 | ; Object. An UiDevice instance. 20 | Func UiDevice($oServer, $sDeviceId = "", $oLogger = "") 21 | Local $oClassObject = _AutoItObject_Class() 22 | $oClassObject.Create() 23 | 24 | ;Methods 25 | With $oClassObject 26 | .AddMethod("getDeviceID", "_GetDeviceID") 27 | .AddMethod("getServer", "_GetServer") 28 | .AddMethod("click", "_Click") 29 | .AddMethod("clickAndWait", "_ClickAndWait") 30 | .AddMethod("clickBiggestButton", "_ClickBiggestButton") 31 | .AddMethod("enterText", "_EnterText") 32 | .AddMethod("waitUntilPartialTextExist", "_WaitUntilPartialTextExist") 33 | .AddMethod("waitForTextExist", "_WaitForTextExist") 34 | .AddMethod("waitUntilViewWithExactTextExists", "_WaitUntilViewWithExactTextExists") 35 | .AddMethod("swipeRelative", "_SwipeRelative") 36 | .AddMethod("delay", "_Delay") 37 | .AddMethod("openNotificationBar", "_OpenNotificationBar") 38 | .AddMethod("getScreenshot", "_GetScreenshot") 39 | .AddMethod("getCurrentTopActivity", "_GetCurrentTopActivity") 40 | .AddMethod("getDump", "_GetDump") 41 | .AddMethod("getActivityName", "_GetActivityName") 42 | .AddMethod("getDeviceName", "_GetDeviceName") 43 | .AddMethod("getVersion", "_GetVersion") 44 | .AddMethod("getDeviceVersion", "_GetDeviceVersion") 45 | .AddMethod("getDeviceManufacturer", "_GetDeviceManufacturer") 46 | .AddMethod("getDeviceModel", "_GetDeviceModel") 47 | .AddMethod("getPackages", "_GetPackages") 48 | .AddMethod("launchBrowser", "_LaunchBrowser") 49 | .AddMethod("launchDeepLink", "_LaunchDeepLink") 50 | .AddMethod("startActivity", "_StartActivity") 51 | .AddMethod("clearPackage", "_ClearPackage") 52 | .AddMethod("stopPackage", "_StopPackage") 53 | .AddMethod("sendKeyEvent", "_SendKeyEvent") 54 | .AddMethod("pressPower", "_PressPower") 55 | .AddMethod("pressBack", "_PressBack") 56 | .AddMethod("pressHome", "_PressHome") 57 | .AddMethod("pressMenu", "_PressMenu") 58 | .AddMethod("pressTab", "_PressTab") 59 | .AddMethod("pressEnter", "_PressEnter") 60 | .AddMethod("pressAppMenu", "_PressAppMenu") 61 | .AddMethod("tap", "_Tap") 62 | .AddMethod("longPress", "_LongPress") 63 | .AddMethod("setBatteryLevel", "_SetBatteryLevel") 64 | .AddMethod("setBatteryStatus", "_SetBatteryStatus") 65 | .AddMethod("batteryReset", "_BatteryReset") 66 | .AddMethod("writeServerLog", "_WriteServerLog") 67 | .AddMethod("getServerLog", "_GetServerLog") 68 | .AddMethod("clearServerLog", "_ClearServerLog") 69 | .AddMethod("shell", "_Shell") 70 | .AddMethod("stop", "_Stop") 71 | EndWith 72 | 73 | ;Properties 74 | With $oClassObject 75 | .AddProperty("deviceID", $ELSCOPE_PRIVATE, $sDeviceId) 76 | .AddProperty("lastMethod", $ELSCOPE_PRIVATE, "") 77 | .AddProperty("oServer", $ELSCOPE_PRIVATE, $oServer) 78 | .AddProperty("oLogger", $ELSCOPE_PRIVATE, $oLogger) 79 | EndWith 80 | 81 | Return $oClassObject.Object 82 | EndFunc ;==>UiDevice 83 | 84 | #Region Getters 85 | ;Function: _GetDeviceID 86 | ;Gets the serial device. 87 | ; 88 | ;Parameters: 89 | ; $oSelf - Object reference. 90 | ; 91 | ;Returns: 92 | ; String. The serial device. 93 | Func _GetDeviceID($oSelf) 94 | Return $oSelf.deviceID 95 | EndFunc ;==>_GetDeviceID 96 | 97 | ;Function: _GetServer 98 | ;Gets the ImperiusServer instance. 99 | ; 100 | ;Parameters: 101 | ; $oSelf - Object reference. 102 | ; 103 | ;Returns: 104 | ; String. The ImperiusServer instance. 105 | Func _GetServer($oSelf) 106 | Return $oSelf.oServer 107 | EndFunc ;==>_GetServer 108 | #EndRegion Getters 109 | 110 | #Region UIActionsMethods 111 | ;Function: _Click 112 | ;Perform a click over an element with the given text. 113 | ; 114 | ;Parameters: 115 | ; $oSelf - Object reference. 116 | ; $sText - String. The element text. 117 | ; 118 | ;Returns: 119 | ; Boolean Success: True Failure: False and set the value of the @error. 120 | Func _Click($oSelf, $sText) 121 | Local $sMethod = "clickIfExactExists" 122 | Local $sParam = '["' & $sText & '"]' 123 | Local $sResponse = _ExecuteUIHelp($oSelf, $sMethod, $sParam) 124 | Local $bResult = _ResponseOK($oSelf, $sResponse) 125 | Return SetError(@error, @extended, $bResult) 126 | EndFunc ;==>_Click 127 | 128 | ;Function: _ClickAndWait 129 | ;Click and wait for new window if this text item exists. 130 | ; 131 | ;Parameters: 132 | ; $oSelf - Object reference. 133 | ; $sText - String. The element text. 134 | ; 135 | ;Returns: 136 | ; Boolean Success: True Failure: False and set the value of the @error. 137 | Func _ClickAndWait($oSelf, $sText) 138 | Local $sMethod = "clickAndWaitForNewWindow" 139 | Local $sParam = '["' & $sText & '"]' 140 | Local $sResponse = _ExecuteUIHelp($oSelf, $sMethod, $sParam) 141 | Local $bResult = _ResponseOK($oSelf, $sResponse) 142 | Return SetError(@error, @extended, $bResult) 143 | EndFunc ;==>_ClickAndWait 144 | 145 | ;Function: _ClickBiggestButton 146 | ;Click the biggest button on the screen. 147 | ; 148 | ;Parameters: 149 | ; $oSelf - Object reference. 150 | ; 151 | ;Returns: 152 | ; Boolean Success: True Failure: False and set the value of the @error. 153 | Func _ClickBiggestButton($oSelf) 154 | Local $sMethod = "clickBiggestButton" 155 | Local $sResponse = _ExecuteUIHelp($oSelf, $sMethod) 156 | Return _ResponseOK($oSelf, $sResponse) 157 | EndFunc ;==>_ClickBiggestButton 158 | 159 | ;Function: _EnterTex 160 | ;Enter a given text into an input field. 161 | ; 162 | ;Parameters: 163 | ; $oSelf - Object reference. 164 | ; $iIndex - Int. The input index. 165 | ; $sText - String. The text to enter. 166 | Func _EnterText($oSelf, $iIndex, $sText) 167 | Local $sMethod = "enterText" 168 | Local $sParam = '[' & $iIndex & ', "' & $sText & '"]' 169 | _ExecuteUIHelp($oSelf, $sMethod, $sParam) 170 | EndFunc ;==>_EnterText 171 | 172 | ;Function: _WaitUntilPartialTextExist 173 | ;Waits for a component to become visible with the partial given text. 174 | ; 175 | ;Parameters: 176 | ; $oSelf - Object reference. 177 | ; $sText - String. The element text. 178 | ; $iTimeout - Int. Milliseconds to wait before giving up and failing the command. 179 | ; 180 | ;Returns: 181 | ; Boolean Success: True Failure: False and set the value of the @error. 182 | Func _WaitUntilPartialTextExist($oSelf, $sText, $iTimeout) 183 | Local $sMethod = "waitUntilViewWithPartialTextExists" 184 | Local $sParam = '["' & $sText & '", ' & $iTimeout & ']' 185 | Local $sResponse = _ExecuteUIHelp($oSelf, $sMethod, $sParam) 186 | Local $bResult = _ResponseOK($oSelf, $sResponse) 187 | Return SetError(@error, @extended, $bResult) 188 | EndFunc ;==>_WaitUntilPartialTextExist 189 | 190 | ;Function: _WaitForTextExist 191 | ;Waits for a component to become visible with the exact given text. 192 | ;Uses the default timeout in the server connection instance. 193 | ; 194 | ;Parameters: 195 | ; $oSelf - Object reference. 196 | ; $sText - String. The element text. 197 | ; 198 | ;Returns: 199 | ; Boolean Success: True Failure: False. 200 | Func _WaitForTextExist($oSelf, $sText) 201 | Return _WaitUntilExactTextExists($oSelf, $sText, $oSelf.getServer().getTimeout()) 202 | EndFunc ;==>_WaitForTextExist 203 | 204 | ;Function: _WaitUntilExactTextExists 205 | ;Waits for a component to become visible with the exact given text. 206 | ; 207 | ;Parameters: 208 | ; $oSelf - Object reference. 209 | ; $sText - String. The element text. 210 | ; $iTimeout - Int. Milliseconds to wait before giving up and failing the command. 211 | ; 212 | ;Returns: 213 | ; Boolean Success: True Failure: False and set the value of the @error. 214 | Func _WaitUntilExactTextExists($oSelf, $sText, $iTimeout) 215 | Local $sMethod = "waitUntilExactTextExists" 216 | Local $sParam = '[["' & $sText & '"], ' & $iTimeout & ']' 217 | Local $sResponse = _ExecuteUIHelp($oSelf, $sMethod, $sParam) 218 | Local $bResult = _ResponseOK($oSelf, $sResponse) 219 | Return SetError(@error, @extended, $bResult) 220 | EndFunc ;==>_WaitUntilExactTextExists 221 | 222 | ;Function: _WaitUntilViewWithExactTextExists 223 | ;Waits for a component view to become visible with the exact given text. 224 | ; 225 | ;Parameters: 226 | ; $oSelf - Object reference. 227 | ; $sText - String. The element text. 228 | ; $iTimeout - Int. Milliseconds to wait before giving up and failing the command. 229 | ; 230 | ;Returns: 231 | ; Boolean Success: True Failure: False and set the value of the @error. 232 | Func _WaitUntilViewWithExactTextExists($oSelf, $sText, $iTimeout) 233 | Local $sMethod = "waitUntilViewWithExactTextExists" 234 | Local $sParam = '["' & $sText & '", ' & $iTimeout & ']' 235 | Local $sResponse = _ExecuteUIHelp($oSelf, $sMethod, $sParam) 236 | Local $bResult = _ResponseOK($oSelf, $sResponse) 237 | Return SetError(@error, @extended, $bResult) 238 | EndFunc ;==>_WaitUntilViewWithExactTextExists 239 | 240 | ;Function: _SwipeRelative 241 | ;Swipes relative to the device screen size (0,0 top left, 1,1 bottom right). 242 | ; 243 | ;Parameters: 244 | ; $oSelf - Object reference. 245 | ; $iX - Int. x coordinate. 246 | ; $iY - Int. y coordinate. 247 | ; $iXend - Int. x end coordinate. 248 | ; $iYend - Int. y end coordinate. 249 | ; 250 | ;Returns: 251 | ; Boolean Success: True Failure: False and set the value of the @error. 252 | Func _SwipeRelative($oSelf, $iX, $iY, $iXend, $iYend) 253 | Local $sMethod = "swipeRelative" 254 | Local $sParam = '[' & $iX & ',' & $iY & ',' & $iXend & ',' & $iYend & ']' 255 | Local $sResponse = _ExecuteUIHelp($oSelf, $sMethod, $sParam) 256 | Local $bResult = _ResponseOK($oSelf, $sResponse) 257 | Return SetError(@error, @extended, $bResult) 258 | EndFunc ;==>_SwipeRelative 259 | 260 | ;Function: _Deleay 261 | ; Suspend execution for a specified period. 262 | ; 263 | ;Parameters: 264 | ; $oSelf - Object reference. 265 | ; $iTimeout - Int. The sleep time (millisecond). 266 | Func _Delay($oSelf, $iTimeout) 267 | Local $sMethod = "delay" 268 | Local $sParam = '[' & $iTimeout & ']' 269 | _ExecuteUIHelp($oSelf, $sMethod, $sParam) 270 | EndFunc ;==>_Delay 271 | 272 | ;Function: _OpenNotificationBar 273 | ;Opens the Notification Bar. 274 | ; 275 | ;Parameters: 276 | ; $oSelf - Object reference. 277 | Func _OpenNotificationBar($oSelf) 278 | Local $sMethod = "openNotificationBar" 279 | _ExecuteUIHelp($oSelf, $sMethod) 280 | EndFunc ;==>_OpenNotificationBar 281 | 282 | ;Function: _GetScreenshot 283 | ;Take a screenshot and save to a PNG file. 284 | ; 285 | ;Parameters: 286 | ; $oSelf - Object reference. 287 | ; $sLocalFile - String. The path to the destination (local) file (without the extension file).Defaul is @ScriptDir & "\screen.png". 288 | ; 289 | ;Returns: 290 | ; Boolean Success: True Failure: False and set the value of the @error. 291 | Func _GetScreenshot($oSelf, $sLocalFile = @ScriptDir & "\screen.png") 292 | Local $sMethod = "getScreenshot" 293 | Local $sRemoteScreenshot = _ExecuteUIHelp($oSelf, $sMethod) 294 | Local $bResult = _ResponseOK($oSelf, $sRemoteScreenshot) 295 | 296 | If ($bResult == False) Then 297 | Return SetError(@error, @extended, $bResult) 298 | EndIf 299 | 300 | $sRemoteScreenshot = StringReplace($sRemoteScreenshot, "\", "") 301 | $sRemoteScreenshot = StringReplace($sRemoteScreenshot, '"', '') 302 | $oSelf.getServer().getAdb().pull($sRemoteScreenshot, $sLocalFile) 303 | _Shell($oSelf, 'rm ' & $sRemoteScreenshot) 304 | Return True 305 | EndFunc ;==>_GetScreenshot 306 | 307 | ;Function: _GetCurrentTopActivity 308 | ;Gets the current top activity. 309 | ; 310 | ;Parameters: 311 | ; $oSelf - Object reference. 312 | ; 313 | ;Returns: 314 | ; String. The current top activity. 315 | Func _GetCurrentTopActivity($oSelf) 316 | Local $sMethod = "getCurrentTopActivity" 317 | Local $sResult = _ExecuteUIHelp($oSelf, $sMethod) 318 | Return StringReplace($sResult, '"', '') 319 | EndFunc ;==>_GetCurrentTopActivity 320 | 321 | ;Function: _GetActivityName 322 | ;Gets the current top activity. 323 | ; 324 | ;Parameters: 325 | ; $oSelf - Object reference. 326 | ; 327 | ;Returns: 328 | ; String. The current activity. 329 | Func _GetActivityName($oSelf) 330 | Local $sMethod = "getActivityName" 331 | Local $sResult = _ExecuteUIHelp($oSelf, $sMethod) 332 | Return StringReplace($sResult, '"', '') 333 | EndFunc ;==>_GetActivityName 334 | 335 | ;Function: _GetDeviceName 336 | ;Gets the device name. 337 | ; 338 | ;Parameters: 339 | ; $oSelf - Object reference. 340 | ; 341 | ;Returns: 342 | ; String. The device name. 343 | Func _GetDeviceName($oSelf) 344 | Local $sMethod = "getDeviceName" 345 | Return _ExecuteUIHelp($oSelf, $sMethod) 346 | EndFunc ;==>_GetDeviceName 347 | 348 | ;Function: _ClearPackage 349 | ;Clear application data. 350 | ; 351 | ;Parameters: 352 | ; $oSelf - Object reference. 353 | ; $sPackage - String.The package. 354 | ; 355 | ;Returns: 356 | ; Boolean Success: True Failure: False and set the value of the @error. 357 | Func _ClearPackage($oSelf, $sPackage) 358 | Local $sCommand = "pm clear " & $sPackage 359 | Local $sResponse = _Shell($oSelf, $sCommand) 360 | Return (StringInStr($sResponse, "Success") <> 0) ? True : SetError(2, 0, False) 361 | EndFunc ;==>_ClearPackage 362 | 363 | ;Function: _GetPackage 364 | ;Gets all installed packages. 365 | ; 366 | ;Parameters: 367 | ; $oSelf - Object reference. 368 | ; $sPackage - String. The package. 369 | ; 370 | ;Returns: 371 | ; Array. All installed packages. 372 | Func _GetPackages($oSelf) 373 | Local $sCommand = "pm list packages -f" 374 | Local $sResponse = _Shell($oSelf, $sCommand) 375 | Return __ParserPackages($sResponse) 376 | EndFunc ;==>_GetPackages 377 | 378 | ;Function: _SendKeyEvent 379 | ;Sends a KeyEvent. 380 | ; 381 | ;Parameters: 382 | ; $oSelf - Object reference. 383 | ; $iKeycode - Int. An event code. 384 | Func _SendKeyEvent($oSelf, $iKeycode) 385 | Local $sCommand = "input keyevent " & $iKeycode 386 | _Shell($oSelf, $sCommand) 387 | EndFunc ;==>_SendKeyEvent 388 | 389 | ;Function: _PressPower 390 | ;Sends the power button event to turn the device on or off. 391 | ; 392 | ;Parameters: 393 | ; $oSelf - Object reference. 394 | Func _PressPower($oSelf) 395 | _SendKeyEvent($oSelf, $KEYCODE_POWER) 396 | EndFunc ;==>_PressPower 397 | 398 | ;Function: _PressBack 399 | ;Presses the Back button. 400 | ; 401 | ;Parameters: 402 | ; $oSelf - Object reference. 403 | Func _PressBack($oSelf) 404 | _SendKeyEvent($oSelf, $KEYCODE_BACK) 405 | EndFunc ;==>_PressBack 406 | 407 | ;Function: _PressMenu 408 | ;Presses the Menu button. 409 | ; 410 | ;Parameters: 411 | ; $oSelf - Object reference. 412 | Func _PressMenu($oSelf) 413 | _SendKeyEvent($oSelf, $KEYCODE_SOFT_LEFT) 414 | EndFunc ;==>_PressMenu 415 | 416 | ;Function: _PressHome 417 | ;Presses the Home button. 418 | ; 419 | ;Parameters: 420 | ; $oSelf - Object reference. 421 | Func _PressHome($oSelf) 422 | _SendKeyEvent($oSelf, $KEYCODE_HOME) 423 | EndFunc ;==>_PressHome 424 | 425 | ;Function: _PressTab 426 | ;Presses the Tab button. 427 | ; 428 | ;Parameters: 429 | ; $oSelf - Object reference. 430 | Func _PressTab($oSelf) 431 | _SendKeyEvent($oSelf, $KEYCODE_TAB) 432 | EndFunc ;==>_PressTab 433 | 434 | ;Function: _PressEnter 435 | ;Presses the Enter button. 436 | ; 437 | ;Parameters: 438 | ; $oSelf - Object reference. 439 | Func _PressEnter($oSelf) 440 | _SendKeyEvent($oSelf, $KEYCODE_ENTER) 441 | EndFunc ;==>_PressEnter 442 | 443 | ;Function: _PressAppMenu 444 | ;Presses the App Menu button. 445 | ; 446 | ;Parameters: 447 | ; $oSelf - Object reference. 448 | Func _PressAppMenu($oSelf) 449 | _SendKeyEvent($oSelf, $KEYCODE_MENU) 450 | EndFunc ;==>_PressAppMenu 451 | 452 | ;Function: _Tap 453 | ; 454 | ;Parameters: 455 | ; $oSelf - Object reference. 456 | ; $iX -Int. x-coordinate of the tap. 457 | ; $iY -Int. y-coordinate of the tap. 458 | Func _Tap($oSelf, $iX, $iY) 459 | _Shell($oSelf, "input tap " & $iX & " " & $iY) 460 | EndFunc ;==>_Tap 461 | 462 | ;Function: _LongPress 463 | ; 464 | ;Parameters: 465 | ; $oSelf - Object reference. 466 | ; $iX - Int. x-coordinate. 467 | ; $iY - Int. y-coordinate. 468 | Func _LongPress($oSelf, $iX, $iY) 469 | Local $iDuration = 250 ;(ms) 470 | _Shell($oSelf, "input swipe " & $iX & " " & $iY & " " & $iX & " " & $iY & " " & $iDuration) 471 | EndFunc ;==>_LongPress 472 | 473 | ;Function: _Shell 474 | ;Execute a shell command on the device. 475 | ; 476 | ;Parameters: 477 | ; $oSelf - Object reference. 478 | ; $sCommand String The command to execute on the device. 479 | ; 480 | ;Returns: 481 | ; String .The command output. 482 | Func _Shell($oSelf, $sCommand) 483 | Local $sMethod = "shell" 484 | Local $sParam = '["' & $sCommand & '"]' 485 | Return _ExecuteUIHelp($oSelf, $sMethod, $sParam) 486 | EndFunc ;==>_Shell 487 | 488 | ;Function: _ResponseOK 489 | ;Checks if the server response has an error. 490 | ; 491 | ;Parameters: 492 | ; $oSelf - Object reference. 493 | ; $sRespose - String. The Imperius server response. 494 | ; 495 | ;Returns: 496 | ; Boolean. 497 | Func _ResponseOK($oSelf, $sResponse) 498 | Local $aErrors[4] 499 | $aErrors[0] = "Error" 500 | $aErrors[1] = "AssertionError" 501 | $aErrors[2] = "NoSuchMethodError" 502 | $aErrors[3] = "UiObjectNotFoundException" 503 | 504 | For $i = 0 To UBound($aErrors) - 1 505 | If (StringInStr($sResponse, $aErrors[$i])) Then 506 | If (IsObj($oSelf.oLogger)) Then 507 | $oSelf.oLogger.error("[UiDevice] Response: " & $sResponse & " Error:" & $aErrors[$i]) 508 | EndIf 509 | Return SetError(2, 0, False) 510 | EndIf 511 | Next 512 | Return True 513 | EndFunc ;==>_ResponseOK 514 | #EndRegion UIActionsMethods 515 | 516 | #Region GetPropMethods 517 | ;Function: _GetDeviceVersion 518 | ;Gets the device version. 519 | ; 520 | ;Parameters: 521 | ; $oSelf - Object reference. 522 | ; 523 | ;Returns: 524 | ; String. The android version (format: build.version.release). 525 | Func _GetDeviceVersion($oSelf) 526 | Local $sCommand = "getprop ro.build.version.release" 527 | Return StringReplace(_Shell($oSelf, $sCommand), "\n", "") 528 | EndFunc ;==>_GetDeviceVersion 529 | 530 | ;Function: _GetDeviceManufacturer 531 | ;Gets the device manufacturer. 532 | ; 533 | ;Parameters: 534 | ; $oSelf - Object reference. 535 | ; 536 | ;Returns: 537 | ; String. The device manufacturer. 538 | Func _GetDeviceManufacturer($oSelf) 539 | Local $sCommand = "getprop ro.product.manufacturer" 540 | Return StringReplace(_Shell($oSelf, $sCommand), "\n", "") 541 | EndFunc ;==>_GetDeviceManufacturer 542 | 543 | ;Function: _GetDeviceModel 544 | ;Gets the device model. 545 | ; 546 | ;Parameters: 547 | ; $oSelf - Object reference. 548 | ; 549 | ;Returns: 550 | ; String. The device model. 551 | Func _GetDeviceModel($oSelf) 552 | Local $sCommand = "getprop ro.product.model" 553 | Return StringReplace(_Shell($oSelf, $sCommand), "\n", "") 554 | EndFunc ;==>_GetDeviceModel 555 | #EndRegion GetPropMethods 556 | 557 | #Region LogMethods 558 | ;Function: _WriteServerLog 559 | ;Writes in the the server log. 560 | ; 561 | ;Parameters: 562 | ; $oSelf - Object reference. 563 | ; $oText - String. The text to write. 564 | Func _WriteServerLog($oSelf, $sText) 565 | Local $sMethod = "log" 566 | Local $sParam = '["' & $sText & '"]' 567 | _ExecuteUIHelp($oSelf, $sMethod, $sParam) 568 | EndFunc ;==>_WriteServerLog 569 | 570 | ;Function: _GetServerLog 571 | ;Gets the server execution logs. 572 | ; 573 | ;Parameters: 574 | ; $oSelf - Object reference. 575 | ; 576 | ;Returns: 577 | ; String. The server execution logs. 578 | Func _GetServerLog($oSelf) 579 | Local $sMethod = "exportLogs" 580 | Return _ExecuteUIHelp($oSelf, $sMethod) 581 | EndFunc ;==>_GetServerLog 582 | 583 | ;Function: _ClearServerLog 584 | ;Clears the server execution logs. 585 | ; 586 | ;Parameters: 587 | ; $oSelf - Object reference. 588 | Func _ClearServerLog($oSelf) 589 | Local $sMethod = "clearLogs" 590 | _ExecuteUIHelp($oSelf, $sMethod) 591 | EndFunc ;==>_ClearServerLog 592 | #EndRegion LogMethods 593 | 594 | #Region BatteryMethods 595 | ;Function: _SetBatteryLevel 596 | ;Change the battery level. 597 | ; 598 | ;Parameters: 599 | ; $oSelf - Object reference. 600 | ; $iLevel - Int.Level of the battery. 0 to 100. 601 | Func _SetBatteryLevel($oSelf, $iLevel) 602 | _Shell($oSelf, "dumpsys battery set level " & $iLevel) 603 | EndFunc ;==>_SetBatteryLevel 604 | 605 | ;Function: _SetBatteryStatus 606 | ;Change the battery status. 607 | ; 608 | ;Parameters: 609 | ; $oSelf - Object reference. 610 | ; $iLevel - Int.Status of the battery. Should be on of these: 611 | ; - 1 = Unknown. 612 | ; - 2 = Charging. 613 | ; - 3 = Descharging. 614 | ; - 4 = Not charging. 615 | ; - 5 = Full. 616 | Func _SetBatteryStatus($oSelf, $iStatus) 617 | _Shell($oSelf, "dumpsys battery set status " & $iStatus) 618 | EndFunc ;==>_SetBatteryStatus 619 | 620 | ;Function: _BatteryReset 621 | ;The first time you invoke one of SetBattery functions, the device stops getting information 622 | ;from real hardware. Hence, do not forget to finish your gambling executing this function in order to 623 | ;get our device back to earth. 624 | ; 625 | ;Parameters: 626 | ; $oSelf - Object reference. 627 | ; $iLevel - Int.Level of the battery. 0 to 100. 628 | Func _BatteryReset($oSelf) 629 | _Shell($oSelf, "dumpsys battery reset") 630 | EndFunc ;==>_BatteryReset 631 | #EndRegion BatteryMethods 632 | 633 | #Region ActivityManagerMethods 634 | ;Function: _LaunchBrowser 635 | ;Launch the default browser at an URL. 636 | ; 637 | ;Parameters: 638 | ; $oSelf - Object reference. 639 | ; $sUrl - String. The URL to open. 640 | ; 641 | ;Returns: 642 | ; Boolean Success: True Failure: False and set the value of the @error. 643 | Func _LaunchBrowser($oSelf, $sUrl) 644 | Local $sCommand = "am start -a android.intent.action.VIEW -d " & $sUrl 645 | Local $sResponse = _Shell($oSelf, $sCommand) 646 | Return (StringInStr($sResponse, "Starting:") <> 0) ? True : SetError(2, 0, False) 647 | EndFunc ;==>_LaunchBrowser 648 | 649 | ;Function: _LaunchDeepLink 650 | ;You can use this mehtod to test that the intent filter URIs you specified for 651 | ;deep linking resolve to the correct app activity. 652 | ;See 653 | ; 654 | ;Parameters: 655 | ; $oSelf - Object reference. 656 | ; $sUrl - String. The URL to open. 657 | ; $sPackage - String. The app package. 658 | ; 659 | ;Returns: 660 | ; String. Success: The open activity. Failure: empty 661 | Func _LaunchDeepLink($oSelf, $sUrl, $sPackage) 662 | Local $sCommand = "am start -W -a android.intent.action.VIEW -d " & $sUrl & " " & $sPackage 663 | Local $sResponse = StringReplace(_Shell($oSelf, $sCommand), "\n", "") 664 | Local $aActivity = StringRegExp($sResponse, "Activity:(?s)(.*?)ThisTime", 1) 665 | If @error Then Return "" 666 | Return $aActivity[0] 667 | EndFunc ;==>_LaunchDeepLink 668 | 669 | ;Function: _StartActivity 670 | ;Start an activity. 671 | ; 672 | ;Parameters: 673 | ; $oSelf - Object reference. 674 | ; $sPackage - String. The package. 675 | ; $sActivity - String. The activity. 676 | Func _StartActivity($oSelf, $sPackage, $sActivity) 677 | Local $sCommand = "am start " & $sPackage & "/" & $sActivity 678 | _Shell($oSelf, $sCommand) 679 | EndFunc ;==>_StartActivity 680 | 681 | ;Function: _StopPackage 682 | ;Force stop everything associated with the given package. 683 | ; 684 | ;Parameters: 685 | ; $oSelf - Object reference. 686 | ; $sPackage - String. The package. 687 | Func _StopPackage($oSelf, $sPackage) 688 | Local $sCommand = "am force-stop " & $sPackage 689 | _Shell($oSelf, $sCommand) 690 | EndFunc ;==>_StopPackage 691 | #EndRegion ActivityManagerMethods 692 | 693 | #Region UtilMethods 694 | ;Function: _GetVersion 695 | ;Gets the Imperius server version. 696 | ; 697 | ;Parameters: 698 | ; $oSelf - Object reference. 699 | ; 700 | ;Returns: 701 | ; String. The Imperius server version. 702 | Func _GetVersion($oSelf) 703 | Local $sMethod = "version" 704 | Return _ExecuteUtil($oSelf, $sMethod) 705 | EndFunc ;==>_GetVersion 706 | 707 | ;Function: _GetDump 708 | ;Gets a dump of views. 709 | ; 710 | ;Parameters: 711 | ; $oSelf - Object reference. 712 | ; 713 | ;Returns: 714 | ; String. A dump of views. 715 | Func _GetDump($oSelf) 716 | Local $sMethod = "dump" 717 | Return _ExecuteUtil($oSelf, $sMethod) 718 | EndFunc ;==>_GetDump 719 | 720 | ;Function: _Stop 721 | ;Terminating a server session. 722 | ; 723 | ;Parameters: 724 | ; $oSelf - Object reference. 725 | Func _Stop($oSelf) 726 | Local $sMethod = "terminate" 727 | _ExecuteUtil($oSelf, $sMethod) 728 | EndFunc ;==>_Stop 729 | #EndRegion UtilMethods 730 | 731 | #Region ParsersMethods 732 | ;TODO: Add regex. 733 | 734 | ;Function: __ParserPackages 735 | ;Parse the _GetPackages return. 736 | ; 737 | ;Parameters: 738 | ; $sPackages - String. The _GetPackages return. 739 | ; 740 | ;Returns: 741 | ; Array. An array with the packages. 742 | Func __ParserPackages($sPackages) 743 | $sPackages = StringReplace(StringReplace($sPackages, "\/", "/"), "package", "") 744 | $sPackages = StringReplace($sPackages, "\n", "") 745 | $sPackages = StringTrimLeft($sPackages, 1) 746 | Return StringSplit($sPackages, ":") 747 | EndFunc ;==>__ParserPackages 748 | #EndRegion ParsersMethods 749 | 750 | #Region ExecutorsMethods 751 | ;Function: _ExecuteUIHelp 752 | ;Execute an UIHelp method. 753 | ; 754 | ;Parameters: 755 | ; $oSelf - Object reference. 756 | ; $sMethod - String. The method name.Default is empty. 757 | ; $sParam - String . Method parameters. Default is "[]". 758 | ; 759 | ;Returns: 760 | ; String. The Imperius server response. 761 | Func _ExecuteUIHelp($oSelf, $sMethod = "", $sParam = '[]') 762 | $oSelf.lastMethod = $sMethod 763 | Local $sUrl = $oSelf.getServer().getUrl() & 'execute' 764 | $sUrl = $sUrl & "?on=imperiusgeorge.UIHelp&method=" & $sMethod & "&args=" & $sParam 765 | Return _ExecuteGet($oSelf, $sUrl) 766 | EndFunc ;==>_ExecuteUIHelp 767 | 768 | ;Function: _ExecuteUtil 769 | ;Execute an util method. 770 | ; 771 | ;Parameters: 772 | ; $oSelf - Object reference. 773 | ; $sMethod - String. The method name. 774 | ; 775 | ;Returns: 776 | ; String. The Imperius server response. 777 | Func _ExecuteUtil($oSelf, $sMethod) 778 | $oSelf.lastMethod = $sMethod 779 | Local $sUrl = $oSelf.getServer().getUrl() & $sMethod 780 | Return _ExecuteGet($oSelf, $sUrl) 781 | EndFunc ;==>_ExecuteUtil 782 | 783 | ;Function: _ExecuteGet 784 | ;Send a HTTP GET request to a URL. 785 | ; 786 | ;Parameters: 787 | ; $oSelf - Object reference. 788 | ; $sMethod - String. The URL to query, including the get parameters. 789 | ; 790 | ;Returns: 791 | ; String. The Imperius server response. 792 | Func _ExecuteGet($oSelf, $sUrl) 793 | Local $oErrorHandler = ObjEvent("AutoIt.Error", "_Err") 794 | Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") 795 | Local $sReceived = "" 796 | $oHTTP.Open("GET", $sUrl, False) 797 | $oHTTP.Send() 798 | 799 | $sReceived = $oHTTP.ResponseText 800 | Local $oStatusCode = $oHTTP.Status 801 | 802 | If $oStatusCode <> 200 Then 803 | ;We need this last method check because a bug on the Server#Terminate method. 804 | ;See: https://github.com/lookout/ImperiusGeorge/blob/master/src/imperiusgeorge/backend/Server.java#L46 805 | If ($oSelf.lastMethod <> "terminate") Then 806 | If (IsObj($oSelf.oLogger)) Then 807 | $oSelf.oLogger.error("[UiDevice] URL: " & $sUrl & " Status Code:" & $oStatusCode) 808 | EndIf 809 | EndIf 810 | Else 811 | If (IsObj($oSelf.oLogger)) Then 812 | $oSelf.oLogger.info("[UiDevice] URL: " & $sUrl & " Response: " & $sReceived) 813 | EndIf 814 | EndIf 815 | Return $sReceived 816 | EndFunc ;==>_ExecuteGet 817 | 818 | Func _Err($oSelf, $oError) 819 | If (IsObj($oSelf.oLogger)) Then 820 | $oSelf.oLogger.error("[UiDevice] Line: " & $oError.scriptline & " Description :" & $oError.description) 821 | EndIf 822 | EndFunc ;==>_Err 823 | #EndRegion ExecutorsMethods 824 | 825 | 826 | --------------------------------------------------------------------------------