コード例 #1
0
        public void CloseMasterPlus(int timeout = 10)
        {
            var buttonClose = GetMasterPlusMainWindow().GetElementFromChild(MPObj.CloseMasterPlusButton);

            buttonClose.DoClickPoint(1);
            UtilWait.ForTrue(() => !UtilProcess.IsProcessExistedByName(this.SwProcessName), timeout);
        }
コード例 #2
0
        public void LaunchAndCheckCrash(long testTimes)
        {
            var crashTimes = 0;

            UtilCmd.Clear();
            for (var i = 1; i < testTimes; i++)
            {
                var titleTotal = $"Reopen Times: {i} - Crash Times: {crashTimes}";
                var logLines   = UtilFile.ReadFileByLine(LogPathLaunch);
                logLines.ForEach(UtilCmd.WriteLine);
                //logLines.ForEach(line => UtilCmd.WriteLine(line));
                var launchLogTime  = GetRestartLogTime();
                var screenshotPath = Path.Combine(ScreenshotsPath, crashTimes.ToString());
                UtilProcess.StartProcess(SwLnkPath);
                Timeout = 1;
                UtilCmd.WriteTitle($"{titleTotal} - Searching MP+ UI.");
                var startTime     = DateTime.Now;
                var dialogWarning = UtilWait.ForAnyResultCatch(() =>
                {
                    UtilCmd.WriteTitle($"{titleTotal} - Searching Warning dialog of the MP+ in 60s. Time elapsed: {(DateTime.Now - startTime).Seconds}s.");
                    SwMainWindow = new AT().GetElement(MPObj.MainWindow, Timeout);  // The MP+ will change after a while.
                    return(SwMainWindow.GetElement(MPObj.DialogWarning, Timeout));
                }, 60, 2);
                if (SwMainWindow == null)
                {
                    UtilCapturer.Capture(i.ToString());
                    UtilFile.WriteFile(LogPathLaunch, $"{launchLogTime}: Reopen Times: {i} - Could not open MasterPlus.");
                    crashTimes++;
                }
                UtilTime.WaitTime(1);
                UtilProcess.KillProcessByName(SwProcessName);
                UtilTime.WaitTime(1);
            }
        }
コード例 #3
0
ファイル: KeysSpyOp.cs プロジェクト: HuangLuffy/ezTesting
 public void Load()
 {
     if (app == null)
     {
         UtilProcess.KillProcessByName(System.IO.Path.GetFileName(_appPath));
         UtilTime.WaitTime(1);
         var p = UtilProcess.StartProcessReturn(_appPath);
         UtilWait.ForTrue(() => p.MainWindowHandle != IntPtr.Zero, 3);
         app = new AT().GetElementFromHwnd(p.MainWindowHandle);
     }
 }
コード例 #4
0
 public AT GetMasterPlusMainWindowForLaunching(int timeout = 0)
 {
     return(UtilWait.ForNonNull(() =>
     {
         if (UtilProcess.IsProcessExistedByName("RENEW"))
         {
             UtilProcess.KillProcessByName("RENEW");
         }
         var mainWindow = GetMasterPlusMainWindow();
         mainWindow.GetElement(MPObj.DeviceList);
         return mainWindow;
     }, timeout, 2));
 }
コード例 #5
0
        public void RestartSystemAndCheckDeviceRecognitionFlow(XmlOps xmlOps)
        {
            UtilFolder.CreateDirectory(Path.Combine(ScreenshotsPath, "Restart"));
            var restartLogTime = GetRestartLogTime();
            var screenshotPath = Path.Combine(RestartScreenshotPath, restartLogTime);
            var logLines       = UtilFile.ReadFileByLine(LogPathRestart);

            logLines.ForEach(line => UtilCmd.WriteLine(line));
            var titleLaunchTimes = xmlOps.GetRestartTimes();
            var titleTotal       = $"Restart Times: {titleLaunchTimes} - Error Times: {logLines.Count}";
            var t = UtilWait.WaitTimeElapseThread($"{titleTotal} - Waiting 35s.", 35);

            t.Start();
            t.Join();
            if (!File.Exists(SwLnkPath))
            {
                UtilCmd.WriteTitle($"{titleTotal} - Could not find {SwLnkPath}.");
                UtilCmd.PressAnyContinue();
            }
            UtilProcess.StartProcess(SwLnkPath);
            Timeout = 1;
            UtilCmd.WriteTitle($"{titleTotal} - Searching MP+ UI.");
            var startTime     = DateTime.Now;
            var dialogWarning = UtilWait.ForAnyResultCatch(() =>
            {
                UtilCmd.WriteTitle($"{titleTotal} - Searching Warning dialog of the MP+ in 60s. Time elapsed: {(DateTime.Now - startTime).Seconds}s.");
                SwMainWindow = new AT().GetElement(MPObj.MainWindow, Timeout);  // The MP+ will change after a while.
                return(SwMainWindow.GetElement(MPObj.DialogWarning, Timeout));
            }, 60, 3);

            if (SwMainWindow == null)
            {
                //UtilCmd.WriteTitle($"Restart Times: {titleLaunchTimes} - Could not open MasterPlus.");
                UtilCapturer.Capture(screenshotPath);
                UtilFile.WriteFile(LogPathRestart, $"{restartLogTime}: Restart Times: {titleLaunchTimes} - Could not open MasterPlus.");
            }
            else if (dialogWarning != null)
            {
                UtilCapturer.Capture(screenshotPath);
                //UtilCmd.WriteTitle($"Restart Times: {titleLaunchTimes} - The device was not displayed");
                UtilFile.WriteFile(LogPathRestart, $"{restartLogTime}: Restart Times: {titleLaunchTimes} - The device was not displayed.");
            }
            xmlOps.SetRestartTimes(Convert.ToInt16(titleLaunchTimes) + 1);
            UtilTime.WaitTime(1);
            UtilProcess.KillProcessByName(this.SwProcessName);
            //UtilProcess.ExecuteCmd();// sometimes it does not work somehow.
            UtilOS.Reboot();
        }
コード例 #6
0
ファイル: AT.cs プロジェクト: HuangLuffy/ezTesting
        public void WaitForVanishedBySearch(ATElementStruct aTElementStruct, int timeout = -1, string treeScope = TreeScope.Descendants)
        {
            try
            {
                UtilWait.ForTrue(() => (GetElement(treeScope, aTElementStruct.Name, aTElementStruct.AutomationId, aTElementStruct.ClassName, aTElementStruct.FrameworkId, aTElementStruct.ControlType, aTElementStruct.FullDescriton, aTElementStruct.AccessKey, aTElementStruct.Index, -1, false, true) == null), timeout);
                //UtilWait.ForTrue(() =>
                //{
                //    return (GetElement(TreeScope, ATElementStruct.Name, ATElementStruct.AutomationId, ATElementStruct.ClassName, ATElementStruct.FrameworkId, ATElementStruct.ControlType, ATElementStruct.Index, -1, false, true) == null);

                //}, Timeout);
            }
            catch (Exception ex)
            {
                throw new Exception($"This element still exists. {ex.Message}");
            }
        }
コード例 #7
0
        public void SelectTab(ATElementStruct whichTab)
        {
            var currentTabbar = GetMasterPlusMainWindow().GetElement(new ATElementStruct()
            {
                ControlType = ATElement.ControlType.Tab
            });
            //var tabs = currentTab.GetElementsAllChild();
            //tabs.GetATCollection()[GetTabIndexByTabCount(tabs.GetATCollection().Length)].DoClickPoint(1);
            var targetTab = currentTabbar.GetElementFromChild(whichTab);

            if (targetTab.GetElementInfo().ToggleState().Equals("Off"))
            {
                targetTab.DoClickPoint(1);
                UtilWait.ForTrue(() => targetTab.GetElementInfo().ToggleState().Equals("On"), 3, 1);
            }
        }
コード例 #8
0
        private void ConnectRemoteOsAvailable(string remoteOsIp)
        {
            var currentTitle  = UtilCmd.GetTitle();
            var waitAnimation = UtilWait.WaitTimeElapseThread("Connecting...");

            try
            {
                _remoteOs = new RemoteOS(remoteOsIp);
                waitAnimation.Start();
                _remoteOs.IsRemoteOsAvailable();
                waitAnimation.Abort();
                UtilCmd.PressAnyContinue("The communication between the Local OS and the Remote OS established successfully. Press any key to continue.");
            }
            catch (Exception)
            {
                waitAnimation.Abort();
                UtilCmd.WriteTitle(currentTitle);
                throw;
            }
        }
コード例 #9
0
ファイル: AT.cs プロジェクト: HuangLuffy/ezTesting
 public AT GetElement(string treeScope = null, string name = null, string automationId = null, string className = null, string frameworkId = null, string controlType = null, string fullDescription = null, string accessKey = null, int?index = null, int timeout = -1, bool checkEnabled = false, bool returnNullWhenException = false)
 {
     try
     {
         AutomationElement = AutomationElement ?? AutomationElement.RootElement;
         var treeScopeVar = GetTreeScope(treeScope);
         var condition    = GetCondition(name, automationId, className, frameworkId, controlType, fullDescription, accessKey);
         var atObj        = timeout <= 0 ? GetElementByHandler(AutomationElement, treeScopeVar, condition, name, automationId, className, index) : UtilWait.ForAnyResult(() => GetElementByHandler(AutomationElement, treeScopeVar, condition, name, automationId, className, index), timeout);
         if (checkEnabled != true)
         {
             return(atObj);
         }
         if (!atObj.GetElementInfo().IsEnabled())
         {
             throw new Exception("This element is not enabled.");
         }
         return(atObj);
     }
     catch (Exception ex)
     {
         if (returnNullWhenException)
         {
             return(null);
         }
         throw new Exception("Failed to get: " + $"{(treeScope == null ? "" : $"TreeScope is {treeScope}. ")}{(name == null ? "" : $"Name is {name}. ")}{(automationId == null ? "" : $"AutomationId is {automationId}. ")}{(className == null ? "" : $"ClassName is {className}. ")}{(controlType == null ? "" : $"ControlType is {controlType}. ")}{(fullDescription == null ? "" : $"FullDescription is {fullDescription}. ")}{(accessKey == null ? "" : $"accessKey is {accessKey}. ")} " + ex.Message);
     }