예제 #1
0
        public bool IsAppInstalled() //TODO - should take Device in constructor and check it for specific device
        {
            string       command = "adb shell cmd package list packages";
            StreamReader sr      = CommandLineExecutor.ExecuteCommandGetOutput(command);

            string tempLine = "";

            while (sr.Peek() != -1)
            {
                tempLine = sr.ReadLine();
                if (tempLine.Contains(Settings.chosenApp))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        public bool LaunchApp(Device device)
        {
            string arguments       = device.serial + " " + Settings.chosenApp;
            string launchAppResult = CommandLineExecutor.ExecuteScriptGetOutput(ADBScriptedFunctionsSettings.GetFunctionsFilePath(
                                                                                    ADBScriptedFunctionsSettings.EScriptedFunction.getResolution),
                                                                                arguments,
                                                                                ADBScriptedFunctionsSettings.GetFilePathForOutput(ADBScriptedFunctionsSettings.EScriptedFunction.appLaunch, device)
                                                                                ).ToLower();

            if (launchAppResult.Contains("error") || launchAppResult.Contains("exception"))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #3
0
        public Device GetDevicesResolution(Device device)
        {
            string command = "adb -s " + device.serial + " shell wm size";

            string          arguments = device.serial + " " + ADBScriptedFunctionsSettings.GetFilePathForOutput(ADBScriptedFunctionsSettings.EScriptedFunction.getResolution, device);
            string          output    = CommandLineExecutor.ExecuteScriptGetOutput(ADBScriptedFunctionsSettings.GetFunctionsFilePath(ADBScriptedFunctionsSettings.EScriptedFunction.getResolution), arguments, ADBScriptedFunctionsSettings.GetFilePathForOutput(ADBScriptedFunctionsSettings.EScriptedFunction.getResolution, device));
            MatchCollection Matches   = Regex.Matches(output, @"(\d+)");

            if (Matches.Count == 2)      // Correct case - two values was found (Height and Width)
            {
                device.resolutionY = Int32.Parse(Matches[0].Value);
                device.resolutionX = Int32.Parse(Matches[1].Value);
                return(device);
            }
            else                        // Incorrect case - output is different than expected
            {
                throw new ArgumentException("Could not get resolution for device " + device.serial + ". ADB output is: " + output);
            }
        }
예제 #4
0
        public List <Device> GetConnectedDevices()
        {
            List <Device> ConnectedDevices = new List <Device>();
            StreamReader  sr       = CommandLineExecutor.ExecuteCommandGetOutput("adb devices");
            string        tempLine = "";

            while (sr.Peek() != -1)
            {
                tempLine = sr.ReadLine();
                //if there is a device connected with correct status
                if (tempLine.Contains("device") && !tempLine.Contains("devices"))
                {
                    Device device = new Device();
                    device.status = Device.Status.Ready;
                    device.serial = tempLine.Remove(tempLine.Length - 7);
                    ConnectedDevices.Add(device);
                }
                // if there is a device but with incorrect status
                else if (tempLine.Contains("offline"))
                {
                    Device device = new Device();
                    device.status = Device.Status.Offline;
                    device.serial = tempLine.Remove(tempLine.Length - 8);
                    ConnectedDevices.Add(device);
                }
                else if (tempLine.Contains("unauthorized"))
                {
                    Device device = new Device();
                    device.status = Device.Status.Unauthorized;
                    device.serial = tempLine.Remove(tempLine.Length - 13);
                    ConnectedDevices.Add(device);
                }
            }

            return(ConnectedDevices);
        }
예제 #5
0
        //Begin logcat starts two processes collecting two logcats. Both of them need to be maintained.
        //One of them is "detailedLogcat" which is collecting all info related to this PID and it will be helpful for debugging
        //The second one is "briefLogcat" which is used by this program to determine conditions and actions of TestSteps.
        //The logic is:
        // 1. Check if files exist - if yes, delete them (they may be the result of the previous run)
        // 2. Clear device's logcat
        // 3. Run new process for both logcats
        // 4. Set the path to which logcats will be copied and read
        // 5. Return logcat
        //There is a reason .bat is used here. Cmd.exe crashes and stops logging after a few minutes for unknown reasons.
        public Logcat BeginLogcat(string packagename)
        {
            //first, clean up the old files
            Helpers.DeleteFileIfExists(Settings.briefLogcatFilePath);
            Helpers.DeleteFileIfExists(Settings.detailedLogcatFilePath);

            //second, create new ones
            Logcat logcat = new Logcat();

            logcat.logs = new List <string>();
            Directory.CreateDirectory(Settings.logcatContainerDirectory);

            //clear device's logs
            CommandLineExecutor.ExecuteCommand("adb logcat -c");

            //run .bats that will start logcat
            CommandLineExecutor.ExecuteScript(ADBScriptedFunctionsSettings.GetFunctionsFilePath(ADBScriptedFunctionsSettings.EScriptedFunction.startBriefLogcat), String.Empty, String.Empty);
            CommandLineExecutor.ExecuteScript(ADBScriptedFunctionsSettings.GetFunctionsFilePath(ADBScriptedFunctionsSettings.EScriptedFunction.startDetailedLogcat), String.Empty, String.Empty);

            logcat.detailedLogcatPath = Settings.GetPathForCopy(Settings.briefLogcatFilePath);
            logcat.briefLogcatPath    = Settings.GetPathForCopy(Settings.detailedLogcatFilePath);

            return(logcat);
        }
예제 #6
0
        public void ExecuteScript(string scriptName)
        {
            string scriptPath = Settings.appsDefinitionsContainerPath + scriptName;

            CommandLineExecutor.ExecuteScript(scriptName, string.Empty, Settings.appsDefinitionsContainerPath);
        }
예제 #7
0
        public void ExecuteInShell(string shellCommand)
        {
            string command = "adb shell " + shellCommand;

            CommandLineExecutor.ExecuteCommand(command);
        }
예제 #8
0
        public void InputTap(int x, int y)
        {
            string command = "adb shell input tap " + x + " " + y;

            CommandLineExecutor.ExecuteCommand(command);
        }
예제 #9
0
 public void InputBack()
 {
     CommandLineExecutor.ExecuteCommand("adb shell input keyevent 4");
 }