public void SetUp() { leraApp = TestStack.White.Application.Launch("LeraForm.exe"); mainWindow = leraApp.GetWindow("myWin"); btn = mainWindow.Get <TestStack.White.UIItems.Button>(SearchCriteria.ByAutomationId("button1")); label = mainWindow.Get <TestStack.White.UIItems.Label>(SearchCriteria.ByAutomationId("label1")); }
static void Main(string[] args) { for (int i = 0; i < Convert.ToInt32(args[1]); i++) { StreamWriter file2 = new StreamWriter(@"e:\RunningTimeWhiteLogin.txt", true); Stopwatch stopwatch = Stopwatch.StartNew(); //creates and start the instance of Stopwatch var psi = new ProcessStartInfo(@"C:\\Users\\pth\\AppData\\Local\\Personify\\Omni\\Personify.exe"); TestStack.White.Application app = TestStack.White.Application.AttachOrLaunch(psi); int numWaits = 0; Window window; do { Console.WriteLine("\n Looking for Chat application..."); // Find window with title "Personify" window = app.GetWindow("Personify", TestStack.White.Factory.InitializeOption.NoCache); ++numWaits; Thread.Sleep(100); } while (window == null && numWaits < 50); Assert.IsNotNull(window); TestStack.White.UIItems.TextBox username = window.Get <TestStack.White.UIItems.TextBox>(SearchCriteria.ByAutomationId("Username")); TestStack.White.UIItems.TextBox password = window.Get <TestStack.White.UIItems.TextBox>(SearchCriteria.ByAutomationId("Password")); if (username == null || password == null) { Assert.Fail("!!Can not find any textbox"); } AutomationElement aeTemp = TreeWalker.ControlViewWalker.GetNextSibling(password.AutomationElement); // Input valid nxchattest1 user account to sign in. AutomationElement aeSignInButton = TreeWalker.ControlViewWalker.GetNextSibling(aeTemp); TestStack.White.UIItems.Button signIn = new TestStack.White.UIItems.Button(aeSignInButton, window.ActionListener); username.BulkText = ""; password.BulkText = ""; signIn.Click(); Thread.Sleep(1000); username.BulkText = "*****@*****.**"; password.BulkText = "123456"; signIn.Click(); Thread.Sleep(2000); // Waiting for Chat Deck Window display numWaits = 0; do { Console.WriteLine("\n Looking for Chat Deck..."); window = app.GetWindow("Home", TestStack.White.Factory.InitializeOption.NoCache); ++numWaits; Thread.Sleep(100); } while (window == null && numWaits < 50); //TestStack.White.UIItems.TextBox texttemp = window.Get<TestStack.White.UIItems.TextBox>(SearchCriteria.ByText("Create an immersive recording with your persona and content on screen.")); TestStack.White.UIItems.Label texttemp = window.Get <TestStack.White.UIItems.Label>(SearchCriteria.ByNativeProperty(AutomationElement.NameProperty, "Create an immersive recording with your persona and content on screen.")); AutomationElement aemenu = TreeWalker.ControlViewWalker.GetNextSibling(texttemp.AutomationElement); TestStack.White.UIItems.Button menubtn = new TestStack.White.UIItems.Button(aemenu, window.ActionListener); menubtn.Toggle(); TestStack.White.UIItems.MenuItems.Menu signout = window.Get <TestStack.White.UIItems.MenuItems.Menu>(SearchCriteria.ByText("Sign out")); signout.Click(); app.Kill(); stopwatch.Stop(); file2.WriteLine(stopwatch.ElapsedMilliseconds + " miliseconds"); file2.Close(); } }
private Boolean ConvertPDFToExcel(Dictionary <string, string> ProcessInfo) { /* * USE FULL LINKS FOR TestStack * https://github.com/TestStack/White * http://teststackwhite.readthedocs.io/en/latest/ * http://teststackwhite.readthedocs.io/en/latest/UIItems/#controltype-to-uiitem-mapping-for-primary-uiitems * http://www.dreamincode.net/forums/topic/322108-c%23-teststackwhite-for-beginners/ (Examples) * */ string windowslist = "Windows Count is :"; processList.Add(GetFormattedText(LogType.Info, "PDF To Excel Conversion Process Initialization")); Boolean completedStatus = false; String tempStr = ""; try { File.WriteAllText(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + StatusFile, "Temp=0,Status=Convert Process Initiated"); processList.Add(GetFormattedText(LogType.Info, "Convert Process Initiated")); pdfToExcelApp = TestStack.White.Application.Launch(AppDefaultDir + PDFConverterAppPath); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); processList.Add(GetFormattedText(LogType.Info, "Application Launched")); List <Window> allWindows = pdfToExcelApp.GetWindows(); windowslist = windowslist + allWindows.Count(); foreach (Window aWindow in allWindows) { windowslist = windowslist + "- Window Name is :" + aWindow.Title; } windowslist = windowslist + " Window Title is " + pdfToExcelApp.Process.MainWindowTitle; processList.Add(GetFormattedText(LogType.Info, windowslist)); window = pdfToExcelApp.GetWindow(SearchCriteria.ByText("PDFdu PDF To Excel (Registered) v1.3"), InitializeOption.NoCache); window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); //window.LogStructure(); // To Display all components list with AutomationId in Window. processList.Add(GetFormattedText(LogType.Info, "Window Detected")); File.WriteAllText(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + StatusFile, "Temp=0,Status=Window Detected"); // Merge multiple worksheets into a single worksheet TestStack.White.UIItems.CheckBox chkMergeMultiple = window.Get <TestStack.White.UIItems.CheckBox>("chkCombine"); window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); chkMergeMultiple.Checked = true; window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); // Show Output folder when done TestStack.White.UIItems.CheckBox chkOpen = window.Get <TestStack.White.UIItems.CheckBox>("chkOpen"); window.WaitWhileBusy(); chkOpen.Checked = false; window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); // Original Folder TestStack.White.UIItems.RadioButton rdoSaveOld = window.Get <TestStack.White.UIItems.RadioButton>("rdoSaveOld"); window.WaitWhileBusy(); rdoSaveOld.IsSelected = true; window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); TestStack.White.UIItems.RadioButton rdoXlsx = window.Get <TestStack.White.UIItems.RadioButton>("rdoXlsx"); window.WaitWhileBusy(); rdoXlsx.IsSelected = true; window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); // Custom File Name TestStack.White.UIItems.CheckBox chkCustomFileName = window.Get <TestStack.White.UIItems.CheckBox>("chkFileName"); window.WaitWhileBusy(); chkCustomFileName.Checked = false; window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); // Add file name prefix TestStack.White.UIItems.CheckBox chkBeforeName = window.Get <TestStack.White.UIItems.CheckBox>("chkBeforeName"); window.WaitWhileBusy(); chkBeforeName.Checked = false; window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); // Add file name suffix TestStack.White.UIItems.CheckBox chkAfterName = window.Get <TestStack.White.UIItems.CheckBox>("chkAfterName"); window.WaitWhileBusy(); chkAfterName.Checked = false; window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); AddFilesToConvert(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + ProcessInfo["CON"]); processList.Add(GetFormattedText(LogType.Info, "Consumption File Assigned")); window.WaitWhileBusy(); AddFilesToConvert(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + ProcessInfo["GEN"]); processList.Add(GetFormattedText(LogType.Info, "Generation File Assigned")); window.WaitWhileBusy(); AddFilesToConvert(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + ProcessInfo["TSC"]); processList.Add(GetFormattedText(LogType.Info, "Time Slot File Assigned")); window.WaitWhileBusy(); AddFilesToConvert(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + ProcessInfo["MCON"]); processList.Add(GetFormattedText(LogType.Info, "Meter Consumption File Assigned")); window.WaitWhileBusy(); AddFilesToConvert(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + ProcessInfo["OAB"]); processList.Add(GetFormattedText(LogType.Info, "Open Access Bill File Assigned")); window.WaitWhileBusy(); processList.Add(GetFormattedText(LogType.Info, "Convert Processing Initiated......")); // Now Start Convert PDF to Excel TestStack.White.UIItems.Button btnMakePDF = window.Get <TestStack.White.UIItems.Button>("btnMakePDF"); window.WaitWhileBusy(); btnMakePDF.Click(); window.WaitWhileBusy(); processList.Add(GetFormattedText(LogType.Info, "Convert Processing Started......")); // Display Progress Window TestStack.White.UIItems.Label lblDoing = window.Get <TestStack.White.UIItems.Label>(SearchCriteria.ByAutomationId("lblDoing")); window.WaitWhileBusy(); String currProgressText = ""; do { processList.Add(GetFormattedText(LogType.Info, "Progress Text : " + lblDoing.Text)); if (!currProgressText.Equals(lblDoing.Text)) { if (lblDoing.Text.Contains("1/5")) { tempStr = "CONS"; } else if (lblDoing.Text.Contains("2/5")) { tempStr = "GEN"; } else if (lblDoing.Text.Contains("3/5")) { tempStr = "TSC"; } else if (lblDoing.Text.Contains("4/5")) { tempStr = "MCON"; } else if (lblDoing.Text.Contains("5/5")) { tempStr = "OAB"; } File.WriteAllText(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + StatusFile, String.Format("State={0},Status={1}", tempStr, lblDoing.Text)); } SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); Thread.Sleep(500); } while (!lblDoing.Text.Contains("Please Wait ...")); window.WaitWhileBusy(); SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); completedStatus = true; File.WriteAllText(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + StatusFile, String.Format("State={0},Status={1}", "Completed", "Completed")); processList.Add(GetFormattedText(LogType.Info, "Convert Process Completed")); // Display Message Dialog after Process completed.. SetForegroundWindow(pdfToExcelApp.Process.MainWindowHandle); window.WaitWhileBusy(); TestStack.White.UIItems.Button btnCompleted = window.Get <TestStack.White.UIItems.Button>("2"); window.WaitWhileBusy(); btnCompleted.Click(); pdfToExcelApp.Kill(); processList.Add(GetFormattedText(LogType.Info, "Convert PDF To Closed")); return(true); } catch (Exception convertPDFToExcelExp) { var annotatedException = new Exception("ConvertPDFToExcel-" + windowslist, convertPDFToExcelExp); processList.Add(GetFormattedText(LogType.Error, "Unable to convert PDF To Excel due to " + convertPDFToExcelExp.ToString())); if (!completedStatus) // Some times exception raised after file processing completed.. like Unable to find Completed button { File.WriteAllText(AppDefaultDir + UploadFileDir + ProcessInfo["DIR"] + "\\" + StatusFile, String.Format("State={0},Status={1}", tempStr, "Failed")); } if (pdfToExcelApp != null) { pdfToExcelApp.Kill(); } return(false); } }