//Double Click a record in dynamic grid based on data-field and row number /*Parameter Usage * gridPosition : gridPosition of the dynamic grid in the page * field : data-field attribute of the column to select * row : row value can be 'first' or 'last' or actual number like '1','2' etc. * tag : tag on which the action should be performed **/ public bool doubleClickRecordInDynamicGridBasedOnRowNumber(int gridPosition, string field, String row, String tag) { IWebElement pageElement = null; IReadOnlyCollection <IWebElement> tdListCollection = null; List <IWebElement> tdList = null; bool selectedFlag = false; int rowCount = 0; try { //Find the Page Element pageElement = findWebDriverElement.waitForElementById(null, null, "Portal"); tdListCollection = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@data-key,'==')]//tr[@data-field='" + field + "']")); if (tdListCollection.Count == 0) { tdListCollection = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@external-value,'==')]/td[@data-field='" + field + "']")); } if (tdListCollection.Count == 0) { tdListCollection = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@external-value,'=')]/td[@data-field='" + field + "']")); } tdList = new List <IWebElement>(tdListCollection); //Iterate over the input list for (int i = 0; i < tdList.Count; i++) { if (row.Equals("first") && i == 0) { new Actions(driver).DoubleClick(tdList[i].FindElement(By.TagName(tag))).Perform(); break; } if (row.Equals("last") && i == tdList.Count - 1) { new Actions(driver).DoubleClick(tdList[i].FindElement(By.TagName(tag))).Perform(); break; } else if (int.TryParse(row, out rowCount) && i == rowCount) { new Actions(driver).DoubleClick(tdList[i].FindElement(By.TagName(tag))).Perform(); break; } } // end of for each if (!selectedFlag) { SAFINCALog.Info("Record Not Found"); throw new NotFoundException("Record Not Found with row:" + row); } return(selectedFlag); } catch (Exception e) { selectedFlag = false; return(selectedFlag); throw e; } }
public bool isAllRecordsPresentSVLGrid(int gridPosition, string field, String[] data) { IWebElement pageElement = null; IReadOnlyCollection <IWebElement> elementTdList = null; bool isPresentFlag = false; String dataOfField = null; int count = 0; try { //Find the Page Element pageElement = findWebDriverElement.waitForElementById(null, null, "Portal"); elementTdList = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@data-key,'==')]/td[@data-field='" + field + "']")); if (elementTdList.Count == 0) { elementTdList = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@external-value,'==')]/td[@data-field='" + field + "']")); } //Iterate over the td list foreach (IWebElement td in elementTdList) { IWebElement span = td.FindElement(By.TagName("span")); dataOfField = span.GetAttribute("innerHTML"); if (!dataOfField.Equals("")) { if (Array.Exists(data, element => element == dataOfField)) { isPresentFlag = true; count++; } else { isPresentFlag = false; } } } // end of for each SAFINCALog.Info("Td count" + count); if (data.Length == count) { SAFINCALog.Info("Record count match"); } else { new NotFoundException("All records didn't match correctly"); } return(isPresentFlag); } catch (Exception e) { isPresentFlag = false; return(isPresentFlag); throw e; } }
//Switch Iframes public void iframeswitch(String iframeTextSrc) { IReadOnlyCollection <IWebElement> iframelist = driver.FindElements(By.TagName("iframe")); String value = null; SAFINCALog.Info("Count of IFrames: " + iframelist.Count()); //Iterate over the td list foreach (IWebElement iframe in iframelist) { value = iframe.GetAttribute("src"); SAFINCALog.Info("Src of IFrames: " + value); if (value != null && value != "") { if (value.Contains(iframeTextSrc)) { driver.SwitchTo().Frame(iframe); findWebDriverElement.Driver = driver; javaScriptCalls.Driver = driver; operateOnWebDriverElement.FindWebDriverElement = findWebDriverElement; operateOnWebDriverElement.JavaScriptCalls = javaScriptCalls; switchFlag = true; src = value; SAFINCALog.Info("Iframe Match for " + iframeTextSrc); break; } } } }
public void SeleniumQuit() { Console.WriteLine("Quitting Driver..........."); try { if (driver != null) { driver.Quit(); driver = null; } SAFINCALog.Info("Closing Web Driver..........."); ProcessMgn.killProcessByNames("IEDriverServer"); //Make sure the process is killed //Try to add the link to the Result file and screenshots if necessary this.TestContext.AddResultFile(WriteTestResultsExcel.testResultFilePath); if (WriteTestResultsExcel.errorTestResultFilePath != null) { this.TestContext.AddResultFile(WriteTestResultsExcel.errorTestResultFilePath); } } catch (Exception e) { Console.WriteLine(e.StackTrace); } }
public static void setTestClassStart(String testClassName, String dateTime) { try { SAFINCALog.Info("Executing Test Cases for Class Started for Class : " + testClassName); errorTestResultFilePath = null; //For Directory if (!Directory.Exists(resultFolderPath)) { resultFolderPath = resultFolderPath + "_" + dateTime; Directory.CreateDirectory(resultFolderPath); System.IO.File.Copy(@Environment.CurrentDirectory + "\\Test_Results_Template.xlsx", resultFolderPath + "\\Test_Results" + "_" + dateTime + ".xlsx"); } testResultFilePath = resultFolderPath + "\\Test_Results" + "_" + dateTime + ".xlsx"; testResultFile = new FileInfo(testResultFilePath); excelPackage = new ExcelPackage(testResultFile); testCaseWorkSheet = excelPackage.Workbook.Worksheets.First(); testStepWorkSheet = excelPackage.Workbook.Worksheets.Last(); } catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); } }
public static void setTestClassFinish(String testClassName) { try { SAFINCALog.Info("Executing Test Cases Finished for Class : " + testClassName); excelPackage.SaveAs(testResultFile); excelPackage.Dispose(); // excelPackage.Load(holdingStream); SAFINCALog.Info("Saving Test Results for Class : " + testClassName + " in path -> " + testResultFilePath); } catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); } finally { //tc_RowIndex = 7; ts_RowIndex = 7; testCaseIDCounter = 1; testStepIDCounter = 1; } }
//Verify Table row Div data public bool verifyTableRowDivData(String className, String text) { IWebElement webelement = findWebDriverElement.waitForElementByClassName(null, null, className); Boolean flag = false; IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody")); try { foreach (IWebElement elementTable in elementDivList) { IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr")); foreach (IWebElement elementTr in elementTrList) { IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td")); foreach (IWebElement elementTd in elementTdList) { if (elementTd.Text == text) { SAFINCALog.Info("Status is " + text + " and as expected"); //break; return(flag); } } // if (flag) { break; } } // if (flag) { break; } } return(flag); } catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); } return(flag); }
//Verify the table row data on the main panel public bool verifyTableRowData(String className, String text) { IWebElement webelement = findWebDriverElement.waitForElementByClassName(null, null, className); Boolean flag = false; IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody")); //Dictionary<String, String> attributeList = new Dictionary<string, string>(); try { foreach (IWebElement elementTable in elementDivList) { IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr")); foreach (IWebElement elementTr in elementTrList) { IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td")); foreach (IWebElement elementTd in elementTdList) { if (elementTd.GetAttribute("innerHTML").Contains(text)) { SAFINCALog.Info("Verified and passed"); flag = true; return(flag); } } // if (flag) { break; } } // if (flag) { break; } } return(flag); } catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); } return(flag); }
/// <summary> /// Used Only wiht JQuery based web runningApplication /// </summary> public void WaitForAjaxCallToFinish() { SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName()); try { AjaxCallToFinish(); } catch { SAFINCALog.Info(CommonUtilities.GetClassAndMethodName(), "CALLING THE JAVA SCRIPT THE FIST TIME FAILED. TRYING THE ONE MORE TIME"); AjaxCallToFinish(); } }
/// <summary> /// Take a print screen and save the image as .png file. /// </summary> /// <param name="imageFullPathAndName"></param> public static void CreateAndSaveScreenShot(string imageFullPathAndName) { SAFINCALog.Debug(GetClassAndMethodName()); Screen screen = Screen.PrimaryScreen; Bitmap bmp = new Bitmap(screen.Bounds.Width, screen.Bounds.Height); Graphics graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(0, 0, 0, 0, new Size(screen.Bounds.Width, screen.Bounds.Height)); bmp.Save(imageFullPathAndName, ImageFormat.Png); string imageFullPathAndNameWithoutC = imageFullPathAndName.Replace("C:", "").Replace("C:", ""); string imageFullPathAndNameIncludeFile = "file://///" + System.Environment.MachineName + imageFullPathAndNameWithoutC; SAFINCALog.Info("The screenshot is saved: " + imageFullPathAndNameIncludeFile); }
//Method to search if a record is present in the dynamic grid or not public bool isRecordPresent_InputField_DynamicGrid(int gridPosition, string field, String data) { IWebElement pageElement = null; IReadOnlyCollection <IWebElement> TdInputList = null; bool isPresentFlag = false; try { //Find the Page Element pageElement = findWebDriverElement.waitForElementById(null, null, "Portal"); TdInputList = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@data-key,'==')]//input[@data-field='" + field + "']")); if (TdInputList.Count == 0) { TdInputList = pageElement.FindElements(By.XPath("(//div[contains(@class,'DynamicGrid')])[" + gridPosition + "]//tr[contains(@external-value,'==')]//input[@data-field='" + field + "']")); } //Iterate over the input list foreach (IWebElement input in TdInputList) { if (input.GetAttribute("value") != null && input.GetAttribute("value").Equals(data)) { isPresentFlag = true; break; } else { } } // end of for each if (!isPresentFlag) { SAFINCALog.Info("Record Not Found"); throw new NotFoundException(); } return(isPresentFlag); } catch (Exception e) { isPresentFlag = false; return(isPresentFlag); throw e; } }
//Verify the table row div data(column as index) using xpath on the main panel public bool verifyTableDivDataUsingXpath(String xpath, int index, String verifyText) { IWebElement webelement = findWebDriverElement.WaitForElementByXPath(null, null, xpath); Boolean flag = false; IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody")); Dictionary <String, String> attributeList = new Dictionary <string, string>(); try { foreach (IWebElement elementTable in elementDivList) { IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr")); foreach (IWebElement elementTr in elementTrList) { IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td")); int counter = 0; foreach (IWebElement elementTd in elementTdList) { if (counter == index) { if (elementTd.Text == verifyText) { SAFINCALog.Info("Results are not expected"); flag = true; return(flag); //break; } } counter++; } //if (flag) { break; } } //if (flag) { break; } } return(flag); } catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); } return(flag); }
//Verify the table row data using Class with condition to verify on the main panel public bool verifyTableRowDataUsingClassWithCondition(String className, String verifyText, String clickText) { IWebElement webelement = findWebDriverElement.waitForElementByClassName(null, null, className); Boolean flag = false; IReadOnlyCollection <IWebElement> elementDivList = webelement.FindElements(By.TagName("tbody")); try { foreach (IWebElement elementTable in elementDivList) { IReadOnlyCollection <IWebElement> elementTrList = elementTable.FindElements(By.TagName("tr")); foreach (IWebElement elementTr in elementTrList) { if (elementTr.GetAttribute("innerHTML").Contains(verifyText)) { IReadOnlyCollection <IWebElement> elementTdList = elementTr.FindElements(By.TagName("td")); foreach (IWebElement elementTd in elementTdList) { if (elementTd.GetAttribute("innerHTML").Contains(clickText)) { SAFINCALog.Info("Status is " + clickText + " which is as expected"); flag = true; return(flag); //break; } } } //if (flag) { break; } } // if (flag) { break; } } return(flag); } catch (Exception e) { SAFINCALog.TestCaseErrorMessage(e); } return(flag); }
public static void setTestStepFinish(String status, Exception e) { try { // Test Step Error & ScreenShot Style testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Style.WrapText = true; testStepWorkSheet.Cells[ts_RowIndex, ts_testStepScreenShot_ColIndex].Style.WrapText = true; if (status.Equals("Pass")) { //Set Test Step Result to Pass testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Value = status; testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Green); //set Test Step Error to NA testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Value = "NA"; //set Test Step Screenshot location to NA testStepWorkSheet.Cells[ts_RowIndex, ts_testStepScreenShot_ColIndex].Value = "NA"; if (tc_Hierachy_Counter > 0) { subTestFailure = false; } } else { // Check for sub test case failure if (!subTestFailure) { //Set Test Step Result to Fail testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Value = status; //Set the color of the status testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red); //Write Error Message in Excel testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Value = e.Message; //set the width of the error column testStepWorkSheet.Column(ts_testStepError_ColIndex).Width = 50; testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Style.WrapText = true; testStepWorkSheet.Row(ts_RowIndex).Height = 50; //testStepWorkSheet.Column(ts_testStepError_ColIndex).AutoFit(); CommonUtilities.CreateAndSaveScreenShot(resultFolderPath + "\\" + currentTestname + ".png"); Thread.Sleep(3 * 1000); var uri = new Uri(resultFolderPath + "\\" + currentTestname + ".png"); errorTestResultFilePath = resultFolderPath + "\\" + currentTestname + ".png"; var cell = testStepWorkSheet.Cells[ts_RowIndex, ts_testStepScreenShot_ColIndex]; //cell.Hyperlink = new Uri(Environment.CurrentDirectory + "\\" + currentTestname + ".png"); // cell.Hyperlink = new Uri(Environment.CurrentDirectory + "\\" + currentTestname + ".png"); if (!(namedStyle != null)) { namedStyle = testStepWorkSheet.Workbook.Styles.CreateNamedStyle("HyperLink"); namedStyle.Style.Font.UnderLine = true; namedStyle.Style.Font.Color.SetColor(Color.Blue); } cell.Hyperlink = new ExcelHyperLink(uri.AbsoluteUri.ToString()); cell.StyleName = "HyperLink"; cell.Value = currentTestname + ".png"; if (tc_Hierachy_Counter > 0) { subTestFailure = true; } } } //Increment the Row Counter ts_RowIndex++; } catch (Exception ex) { SAFINCALog.Info("Error Writing data to excel " + ex); } }