//This method Type the value which passed to this method public static bool SelectRadioButton(TestStack.White.UIItems.WindowItems.Window window, string elementid) { try { Radio radio = window.Get <Radio>(SearchCriteria.ByAutomationId(elementid)); radio.Click(); return(true); } catch (Exception) { try { Radio radio = window.Get <Radio>(SearchCriteria.ByText(elementid)); radio.Click(); return(true); } catch (Exception) { try { Radio radio = window.Get <Radio>(SearchCriteria.ByClassName(elementid)); radio.Click(); return(true); } catch (Exception) { Console.WriteLine("Not able to find the element"); return(false); } } } }
protected void btnOpenWndw_Click(object sender, EventArgs e) { try { KillRDPSession(); TimeBoundAccessRequest tbar = Session["TBAR"] as TimeBoundAccessRequest; CoreAppXmlConfiguration.Instance.BusyTimeout = 20000; Application app = TestStack.White.Application.Launch(@"E:\Software\TeamViewer_Setup.exe"); TestStack.White.UIItems.WindowItems.Window tvWindow = GetTeamViewerWindow(app); TestStack.White.UIItems.RadioButton runOnceCheckBox = tvWindow?.Items.FirstOrDefault(w => w.Name.ToUpper().Contains("ONE TIME")) as TestStack.White.UIItems.RadioButton; runOnceCheckBox.Select(); TestStack.White.UIItems.Button button = tvWindow?.Items.FirstOrDefault(w => w.Name.ToUpper().Contains("ACCEPT")) as TestStack.White.UIItems.Button; button.Click(); tvWindow = GetTeamViewerWindow(app); //give tv some seconds to intialize Thread.Sleep(new TimeSpan(0, 0, 10)); //Takes a screenshot of the entire desktop, and saves it to disk tvWindow.Focus(TestStack.White.UIItems.WindowItems.DisplayState.Maximized); Bitmap bitmap = Desktop.CaptureScreenshot(); string ImageName = DateTime.Now.Ticks.ToString() + ".jpg"; String saveImagePath = Server.MapPath("Images/") + ImageName; bitmap.Save(saveImagePath); tvImageDesktop.ImageUrl = "Images/" + ImageName; Session["APP"] = app; imgDiv.Visible = true; processingDiv.Visible = false; btnOpenWndw.Text = "RE-START THIS SESSION"; Task.Factory.StartNew(() => { DateTime maxDate = tbar.StartTime.AddMinutes(tbar.DurationInMinutes); DateTime currentDate = DateTime.Now; int minutesLeft = ((int)maxDate.Subtract(currentDate).TotalMinutes) + 1;//add an extra minute for network latency Thread.Sleep(new TimeSpan(0, minutesLeft + AnyAdditionalMinutes, 0)); KillRDPSession(); //string msg = "SESSION HAS EXPIRED"; //Master.ErrorMessage = msg; return; }); } catch (Exception ex) { //Show Error Message string msg = "ERROR:" + ex.Message; Master.ErrorMessage = msg; return; } }
// Perry Hunter 06/10/2013 /// <summary>Selects the requested FGen waveform shape button</summary> /// <summary>PREREQUISITE: Function Generator mode UI context, Channel tab selected</summary> /// <param name="type"></param> public static void SelectFGenSignalTypeButton(string type) { string _buttonID = GetRadioButtonID(type); // RadioButton _button = AWGUI.currentUIControlPanel.Get<RadioButton>(SearchCriteria.ByAutomationId(_buttonID)); //Kavitha RadioButton _button = AWGUI.currentMainWindow.Get <RadioButton>(SearchCriteria.ByAutomationId(_buttonID)); Assert.IsNotNull(_button); Assert.IsTrue(_button.Enabled); _button.Click(); }
public static void FGenWaveformShapeButtonShouldBe(string controlName, string expectedState) { string radioButtonId = GetRadioButtonID(controlName); bool expectedValue = true; if (expectedState == "should not") { expectedValue = false; } // RadioButton _button = AWGUI.currentUIControlPanel.Get<RadioButton>(SearchCriteria.ByAutomationId(radioButtonId)); //Kavitha RadioButton _button = AWGUI.currentMainWindow.Get <RadioButton>(SearchCriteria.ByAutomationId(radioButtonId)); Assert.IsNotNull(_button); Assert.AreEqual(expectedValue, _button.IsSelected); }
// Perry Hunter 06/10/2013 /// <summary>Selects the specified radiobutton in the AWG Main Window</summary> /// <param name="radioButtonName">The AutomationID of the radio button to select</param> public static void SelectMainRadioButton(string radioButtonName) { //Commenting out the reference to the AWG for use in writing debug statements when in the UI. This does not make sense. //AWG _awg = AwgSetupSteps.GetAWG("1"); //_awg.DiagComment("Selecting the " + radioButtonName + " RadioButton in " + _awg.ModelString + " window"); //The currentApplication and currentMainWindow are already defined from the setup steps... //Find the requested radiobutton by it's AutomationID (in WPF, this is name property) RadioButton _radiobutton = AWGUI.currentMainWindow.Get <RadioButton>(SearchCriteria.ByAutomationId(radioButtonName)); //Check the IsEnabled property Assert.IsTrue(_radiobutton.Enabled.Equals(true), radioButtonName + " was not enabled, could not select when requested"); //Click it _radiobutton.Click(); //Check it's "IsSelected" property - should now be true Assert.IsTrue(_radiobutton.IsSelected.Equals(true), radioButtonName + " was not selected after clicking"); }
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); } }