Example #1
0
 public bool SelectFirstSearchRecord()
 {
     try
     {
         System.Threading.Thread.Sleep(3000);
         TestStack.White.UIItems.ListBoxItems.ListItem listView = searchwindow.Get <TestStack.White.UIItems.ListBoxItems.ListItem>(SearchCriteria.ByText("Theranos.PSC.UI.PatientViewModel"));
         listView.Select();
         Thread.Sleep(3000);
         standard.Next();
         return(true);
     }
     catch (Exception)
     {
         Console.WriteLine("Not able to Find any record");
         return(true);
     }
 }
 private static void TryEnable(string driverName, MMDevice mMDevice)
 {
     try
     {
         var hwnd = 0;
         hwnd = FindWindow(null, "Sound");
         Process soundProc;
         if (hwnd == 0)
         {
             soundProc = Process.Start("control.exe", "mmsys.cpl,,1");
         }
         else
         {
             CloseWindow((IntPtr)hwnd);
             while (hwnd == 0)
             {
                 Debug.WriteLine($"Waiting to Close ...");
                 Task.Delay(1000);
                 hwnd = FindWindow(null, "Sound");
             }
             soundProc = Process.Start("control.exe", "mmsys.cpl,,1");
         }
         hwnd = 0;
         hwnd = FindWindow(null, "Sound");
         while (hwnd == 0)
         {
             Debug.WriteLine($"Waiting ...");
             Task.Delay(1000);
             hwnd = FindWindow(null, "Sound");
         }
         if (hwnd == 0)
         {
             MessageBox.Show($"Couldnt find Sound Window.");
             return;
         }
         var id = GetWindowThreadProcessId((IntPtr)hwnd, out uint i);
         TestStack.White.Application application = TestStack.White.Application.Attach((int)i);
         Debug.WriteLine($"{application.Name}");
         TestStack.White.UIItems.WindowItems.Window window = application.GetWindow("Sound");
         var exists = window.Exists(TestStack.White.UIItems.Finders.SearchCriteria.ByText(driverName));
         if (exists)
         {
             TestStack.White.UIItems.ListBoxItems.ListItem listItem = window.Get <TestStack.White.UIItems.ListBoxItems.ListItem>(TestStack.White.UIItems.Finders.SearchCriteria.ByText(driverName));
             listItem.Focus();
             window.Keyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.UP);
             window.Keyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.DOWN);
             window.Keyboard.HoldKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT);
             window.Keyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.F10);
             window.Keyboard.LeaveKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT);
             window.Keyboard.Enter("E");
         }
         else
         {
             window.Keyboard.HoldKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT);
             window.Keyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.F10);
             window.Keyboard.LeaveKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT);
             window.Keyboard.Enter("S");
             window.Keyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.RETURN);
             TestStack.White.UIItems.ListBoxItems.ListItem listItem = window.Get <TestStack.White.UIItems.ListBoxItems.ListItem>(TestStack.White.UIItems.Finders.SearchCriteria.ByText(driverName));
             listItem.Focus();
             window.Keyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.UP);
             window.Keyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.DOWN);
             window.Keyboard.HoldKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT);
             window.Keyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.F10);
             window.Keyboard.LeaveKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT);
             window.Keyboard.Enter("E");
         }
         if (mMDevice != null)
         {
             if (mMDevice.State == DeviceState.Active)
             {
                 Debug.WriteLine($"{ mMDevice.FriendlyName}");
                 CloseWindow((IntPtr)hwnd);
             }
             else
             {
                 MessageBox.Show("Please Enable the device ");
             }
         }
     }
     catch (Exception)
     {
     }
 }