public static void Initialization() { // Start browser PropertiesCollection.driver = new FirefoxDriver(); ClearBrowserCache(); // Pass application URL PropertiesCollection.driver.Url = AppConfigurationSettings.ApplicationPath; // Maximize browser PropertiesCollection.driver.Manage().Window.Maximize(); TestResultUtility.InitializeTestResultString("Test Suite"); }
/// <summary> /// UpDateTestResult in Html File /// </summary> public static void UpDateTestResult() { try { TestResultUtility.EndTestResultString(); TestResultUtility.WriteToHtmlFile(TestResultUtility.testResultHtmlString.ToString(), AppConfigurationSettings.ResultPath + "LoginTestResult-" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".html"); } catch (Exception ex) { Log.ErrorLog("UpDateTestResult----" + ex.Message); } }
public static bool ExecutionMethod(string testCaseID, string functionName, string expectedResult, string URL) { try { if (!string.IsNullOrEmpty(URL)) { PropertiesCollection.driver.Navigate().GoToUrl(AppConfigurationSettings.ApplicationPath + URL); Thread.Sleep(8000); } List <Datacollection> controlDetailsDataColllection = PopulateInCollection(AppConfigurationSettings.ControlDetails, testCaseID); for (int details = 1; details <= controlDetailsDataColllection.Count; details++) { string controllerType = ReadData(controlDetailsDataColllection, details, "ControllerType"); string controlName = ReadData(controlDetailsDataColllection, details, "ControllerName"); string propertyType = ReadData(controlDetailsDataColllection, details, "PropertyType"); string waitTime = ReadData(controlDetailsDataColllection, details, "WaitTime"); string controllerValue = ReadData(controlDetailsDataColllection, details, "ControllerValue"); string scroll = ReadData(controlDetailsDataColllection, details, "Scroll"); string alert = ReadData(controlDetailsDataColllection, details, "Alert"); string checklist = ReadData(controlDetailsDataColllection, details, "Checklist"); string screenshot = ReadData(controlDetailsDataColllection, details, "Screenshot"); if (!string.IsNullOrEmpty(controllerType)) { if (controllerType == ControllerType.Frame.ToString()) { //Then come out of the iFrame PropertiesCollection.driver.SwitchTo().DefaultContent(); //find the outer frame, and use switch to frame method IWebElement containerFrame = SeleniumMethods.FraneElement(controlName, propertyType); if (containerFrame != null) { PropertiesCollection.driver.SwitchTo().Frame(containerFrame); } } if (controllerType == ControllerType.InsideFrame.ToString()) { //find the outer frame, and use switch to frame method IWebElement containerFrame = SeleniumMethods.FraneElement(controlName, propertyType); if (containerFrame != null) { PropertiesCollection.driver.SwitchTo().Frame(containerFrame); } } if (controllerType == ControllerType.Text.ToString()) { SeleniumMethods.EnterText(controlName, controllerValue, propertyType); } if (checklist.ToLower() == "yes") { if (!SeleniumMethods.VerifyDropdownValue(controlName, controllerValue)) { SaveScreenshot(PropertiesCollection.driver.Title, functionName, testCaseID); TestResultUtility.AddTestFailToTestResultString("Project", controllerValue + "-Checklist Name-Available", controllerValue + " -Checklist Name Not Available", "Fail"); return(false); } } if (controllerType == ControllerType.Dropdown.ToString()) { SeleniumMethods.SelectDropDown(controlName, controllerValue, propertyType); } if (controllerType == ControllerType.SelectiveDropdown.ToString()) { SeleniumMethods.Click(controlName, propertyType); Thread.Sleep(1000); SeleniumMethods.SelectiveDropDownClick(controllerValue); Thread.Sleep(2000); } if (scroll.ToLower() == "yes") { ((IJavaScriptExecutor)PropertiesCollection.driver).ExecuteScript("scroll(0,700)"); } if (controllerType == ControllerType.Button.ToString()) { // Take a screenshot and save SaveScreenshot(PropertiesCollection.driver.Title, functionName, testCaseID); Thread.Sleep(1000); SeleniumMethods.Click(controlName, propertyType); } if (controllerType == ControllerType.Map.ToString()) { SeleniumMethods.ProductMapping(controllerValue); } if (waitTime != "") { Thread.Sleep(Convert.ToInt32(waitTime)); } if (screenshot.ToLower() == "yes") { SaveScreenshot(PropertiesCollection.driver.Title, functionName, testCaseID); } if (alert.ToLower() == "yes") { IAlert alertmsg = PropertiesCollection.driver.SwitchTo().Alert(); if (alertmsg != null) { alertmsg.Accept(); } Thread.Sleep(1000); } } } try { Assert.AreEqual(PropertiesCollection.driver.Title, expectedResult); TestResultUtility.AddTestPassToTestResultString(functionName, expectedResult, PropertiesCollection.driver.Title, "Pass"); SaveScreenshot(expectedResult, functionName, testCaseID); return(true); } catch { Log.ErrorLog("ExecutionMethod_Test_Error"); TestResultUtility.AddTestFailToTestResultString(functionName, expectedResult, PropertiesCollection.driver.Title, "Fail"); SaveScreenshot("ExecutionMethod_Test_Error", functionName, testCaseID); return(false); } } catch (Exception ex) { Log.ErrorLog(functionName + "-ExecutionMethod Error" + ex.Message); return(false); } }