private void btnAudacity_Click(object sender, EventArgs e) { if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Audacity\\Audacity.exe")) { MessageBox.Show("Audacity is not installed..."); return; } try { System.Diagnostics.ProcessStartInfo audacityProcess = new System.Diagnostics.ProcessStartInfo(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Audacity\\Audacity.exe"); appAudacity = TestStack.White.Application.AttachOrLaunch(audacityProcess); audacityWindow = appAudacity.GetWindow("Audacity", TestStack.White.Factory.InitializeOption.NoCache); audacityToolDock = (TestStack.White.UIItems.Panel)audacityWindow.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("ToolDock"))[0]; audacityTransportToolbar = (TestStack.White.UIItems.Panel)audacityToolDock.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Audacity Transport ToolBar"))[0]; AudacityButton_Record = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Record"))[0]; AudacityButton_Pause = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Pause"))[0]; AudacityButton_Play = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Play"))[0]; AudacityButton_Stop = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Stop"))[0]; AudacityButton_SkipToStart = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Skip to Start"))[0]; AudacityButton_SkipToEnd = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Skip to End"))[0]; this.TopMost = true; this.TopMost = false; this.Activate(); } catch (Exception ex) { MessageBox.Show("Window Unavailable\n" + ex.Message); } }
//If it's allready open -> returns true. If it's closed it tries opens it. public static void openPianoRollContextMenu(IntPtr windowHandle, TestStack.White.UIItems.WindowItems.Window window) { TestStack.White.UIItems.Panel itemToClick = null; //TODO: use isPianoRollContextMenuOpen? //if (!isPianoRollContextMenuOpen(windowHandle, window)) //{ UIItemCollection coll = window.Items; foreach (UIItem item in coll) { if (item.Name.Contains("Piano roll")) { if (((TestStack.White.UIItems.Panel)item).Items.Count == 0) { itemToClick = (TestStack.White.UIItems.Panel)item; break; } } } //TODO: Focus alway returns false bool focus = SetForegroundWindow(windowHandle); if (focus) { var mouse = window.Mouse; Point p = itemToClick.Location; p.Offset(11, 12); mouse.Click(p); } else { //Do it as well, but log it Debug.Print("Failed to focus window"); var mouse = window.Mouse; Point p = itemToClick.Location; p.Offset(11, 12); mouse.Click(p); } //} }
private void btnAudacity_Click(object sender, EventArgs e) { if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Audacity\\Audacity.exe")) { MessageBox.Show("Audacity is not installed..."); return; } try { System.Diagnostics.ProcessStartInfo audacityProcess = new System.Diagnostics.ProcessStartInfo(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Audacity\\Audacity.exe"); appAudacity = TestStack.White.Application.AttachOrLaunch(audacityProcess); audacityWindow = appAudacity.GetWindow("Audacity", TestStack.White.Factory.InitializeOption.NoCache); audacityToolDock = (TestStack.White.UIItems.Panel)audacityWindow.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("ToolDock"))[0]; audacityTransportToolbar = (TestStack.White.UIItems.Panel)audacityToolDock.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Audacity Transport ToolBar"))[0]; AudacityButton_Record = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Record"))[0]; AudacityButton_Pause = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Pause"))[0]; AudacityButton_Play = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Play"))[0]; AudacityButton_Stop = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Stop"))[0]; AudacityButton_SkipToStart = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Skip to Start"))[0]; AudacityButton_SkipToEnd = (TestStack.White.UIItems.Button)audacityTransportToolbar.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.ByText("Skip to End"))[0]; this.TopMost = true; this.TopMost = false; this.Activate(); } catch (Exception ex) { MessageBox.Show("Window Unavailable\n"+ex.Message); } }
//************************************************************************************************************************************************************** public static void UIA_ClickOnPaneItem(AutomationElement uiaWindow, Window window, int index) { try { PropertyCondition paneCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane); AutomationElementCollection allPanes = uiaWindow.FindAll(TreeScope.Descendants, paneCondition); TestStack.White.UIItems.Panel p = new TestStack.White.UIItems.Panel(allPanes[index], window.ActionListener); p.Focus(); p.Click(); Thread.Sleep(int.Parse(Execution_Speed)); } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static void UIA_ClickOnPaneItem(AutomationElement uiaWindow, Window window, int index) { Logger.logMessage("Function call @ :" + DateTime.Now); try { PropertyCondition paneCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane); AutomationElementCollection allPanes = uiaWindow.FindAll(TreeScope.Descendants, paneCondition); TestStack.White.UIItems.Panel p = new TestStack.White.UIItems.Panel(allPanes[index], window.ActionListener); p.Focus(); p.Click(); Thread.Sleep(int.Parse(Execution_Speed)); Logger.logMessage("UIA_ClickOnPaneItem " + uiaWindow + "->" + window + "->" + index + " - Successful"); Logger.logMessage("------------------------------------------------------------------------------"); } catch (Exception e) { Logger.logMessage("UIA_ClickOnPaneItem " + uiaWindow + "->" + window + "->" + index + " - Failed"); Logger.logMessage(e.Message); Logger.logMessage("------------------------------------------------------------------------------"); String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }