// like a message internal StreamsApiResultModel.LikeMessageRequestModel LikePost(string actionName, string authorization, string messageID) { StreamsApiResultModel.LikeMessageRequestModel result = new StreamsApiResultModel.LikeMessageRequestModel(); try { JsonParser jp = new JsonParser(); string url = string.Format("http://{0}/api/streams", jp.ReadJson("TestingEnvironment")); authorization = HttpUtility.UrlEncode(authorization); string headers = string.Format("{0}", authorization); string postData = string.Format("actionName={0}", actionName + messageID); result = HttpRequestExtensions.TryPostJson <StreamsApiResultModel.LikeMessageRequestModel>(url, headers, postData, 1000); if (result == null) { Logger.Error("Failed to like message on " + messageID); } } catch (Exception ex) { Logger.Error(ex.Message + "Failed to like message on " + messageID); result = null; } return(result); }
// get feed from user wall internal List <StreamsApiResultModel.GetStreamRequestModel> GetStream(string username, string actionName, string messageID) { List <StreamsApiResultModel.GetStreamRequestModel> result = new List <StreamsApiResultModel.GetStreamRequestModel>(); try { JsonParser jp = new JsonParser(); string url = string.Format("http://{0}/api/streams", jp.ReadJson("TestingEnvironment")); //authorization = HttpUtility.UrlEncode(authorization); //string headers = string.Format("{0}", authorization); url = url + string.Format("/?actionName={0}", actionName + username); result = HttpRequestExtensions.TryGetJson <List <StreamsApiResultModel.GetStreamRequestModel> >(url, 1000); if (result == null) { Logger.Error("Failed to Get message on userwall"); } } catch (Exception ex) { Logger.Error("Failed to get message on user wall"); } return(result); }
// post a new message internal StreamsApiResultModel.PostMessageResultModel PostMessageRequest(string actionName, string autorization, string ownerUser, string messageBody) { StreamsApiResultModel.PostMessageResultModel result = new StreamsApiResultModel.PostMessageResultModel(); try { JsonParser jsonParser = new JsonParser(); string url = string.Format("http://{0}/api/streams", jsonParser.ReadJson("TestingEnvironment")); autorization = HttpUtility.UrlEncode(autorization); string headers = string.Format("{0}", autorization); string postData = string.Format("actionName={0}&ownerUser={1}&messageBody={2}", actionName, ownerUser, messageBody); result = HttpRequestExtensions.TryPostJson <StreamsApiResultModel.PostMessageResultModel>(url, headers, postData, 1000); } catch (Exception exception) { Logger.Error(exception.Message + "Failed to post message on " + ownerUser); result = null; } return(result); }
/// <summary> /// Unitest will cal this one /// </summary> /// <param name="batchId"></param> /// <returns></returns> public bool ExecuteOneBatch(string batchId) { try { var jp = new JsonParser(); string remote = jp.ReadJson("RemoteNode"); int timeoutAllScenarios = Convert.ToInt32(jp.ReadJson("TimeoutAllScenarios")) * 1000; var sel = new Selenium(); if (batchId == string.Empty) { MessageBox.Show("Select Batch first", "Applenium"); return(false); } var sql = new Sql(); _batchId = Convert.ToInt32(batchId); DataTable dtScenario = sql.GetDataTable(Constants.StrBatchScenariosToSelenium, _batchId.ToString(CultureInfo.InvariantCulture)); //SetAllScenariusStatusToRunorNot(dtScenario, Constants.Pending); var adapterBatches = new BatchesTableAdapter(); var adapterBatchLogic = new BatchLogicTableAdapter(); var adapterBrowser = new BrowsersTableAdapter(); string batchname = adapterBatches.GetBatchName(_batchId); var adapterScenario = new ScenarioTableAdapter(); _projectId = Convert.ToInt32(adapterBatches.GetProjectID(Convert.ToInt32(_batchId))); LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, Constants.LogBatchStatus + "=Started", Constants.Done, "0", _projectId, 0); Singleton myInstance = Singleton.Instance; myInstance.BatchResult = true; var threadFinishEvents = new List <EventWaitHandle>(); foreach (DataRow row in dtScenario.Rows) { if (myInstance.StopExecution) { myInstance.BatchResult = false; break; } var threadFinish = new EventWaitHandle(false, EventResetMode.ManualReset); string browserId = row["BrowserID"].ToString(); string batchLogicId = row["BatchLogicID"].ToString(); int executionStatus = Convert.ToInt32(row["ExecutionStatusID"].ToString()); if (executionStatus == 1) //run only selected scenarios { threadFinishEvents.Add(threadFinish); string browserName = adapterBrowser.GetBrowserName(Convert.ToInt32(browserId)); ThreadStart ts = delegate { //wait till hub return available browser RemoteWebDriver driver = null; int elapsed = 0; while ((driver == null) && (elapsed < timeoutAllScenarios)) { //generate random number 30-60 Random r = new Random(); int rInt = r.Next(30000, 60000); //for ints Thread.Sleep(rInt); driver = sel.SetWebDriverBrowser(null, browserId, false); elapsed += rInt; } string scenarioId = row["ScenarioID"].ToString(); // adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId),Constants.Running, Convert.ToInt32(batchLogicId)); string scenarioname = adapterScenario.GetScenarioName(Convert.ToInt32(scenarioId)); if (guiInstance != null && isBatchRun == true) { guiInstance.UpdateProgressLabel(scenarioname); } LogResult(_runExecutionId, Convert.ToInt32(_batchId), Convert.ToInt32(scenarioId), 0, 0, scenarioname + " ScenarioBrowser=" + browserName, Constants.Done, "0", _projectId, _projectPageId); // Do long work here bool scanearioresult = ExecuteOneScenario(scenarioId, driver); Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (EventHandler) delegate { if (scanearioresult == false) { myInstance.BatchResult = false; //adapterBatchLogic.Update(_batchId,Convert.ToInt32(scenarioId),Convert.ToInt32(browserId),Constants.Failed,Convert.ToInt32(batchLogicId)); } driver.Quit(); threadFinish.Set(); }, null, null); }; ts.BeginInvoke(delegate(IAsyncResult aysncResult) { ts.EndInvoke(aysncResult); }, null); if (remote == "no") { WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); } } } WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); string description; int status; if (myInstance.BatchResult) { description = string.Format("{0}={1}", Constants.LogBatchName, "Passed"); status = Constants.Passed; //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Passed",Constants.Passed, "0", _projectId, 0); } else { //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Failed",Constants.Failed, "0", _projectId, 0); description = string.Format("{0}={1}", Constants.LogBatchStatus, "Failed"); status = Constants.Failed; } LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, description, status, "0", _projectId, 0); //SetAllScenariusStatusToRunorNot(dtScenario, Constants.NotRunnig); return(myInstance.BatchResult); } catch (Exception exception) { Logger.Error(exception.Message, exception); return(false); } }
internal bool ExecuteOneTest(string testId, string inputDataRow, RemoteWebDriver driver, ref Dictionary <string, int> testStatus) { try { if (testId == string.Empty) { MessageBox.Show("Select test first", "Applenium"); return(false); } if (testStatus.ContainsKey("TotalTests")) { testStatus["TotalTests"] = testStatus["TotalTests"] + 1; } else { testStatus.Add("TotalTests", 1); } var sql = new Sql(); DataTable dt = sql.GetDataTable(Constants.StrTestStepsToSelenium, testId); bool testresult = true; bool recursivetestresult = true; var adapterGuiproject = new GuiProjectPageTableAdapter(); var adapterTest = new TestTableAdapter(); var adapteGuiPageSection = new GuiPageSectionTableAdapter(); string testname = adapterTest.GetTestName(Convert.ToInt32(testId)); if (guiInstance != null && isBatchRun == false) { guiInstance.UpdateProgressLabel(testname); } LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0, "TestStatus=Started with DataRow=" + inputDataRow, Constants.Done, "0", _projectId, _projectPageId); var jp = new JsonParser(); string skipTestOnStepFail = jp.ReadJson("SkipTestOnStepFail"); Singleton myInstance = Singleton.Instance; // Will always be the same instance... if (inputDataRow != null) { if (inputDataRow.IndexOf("-", 0, StringComparison.Ordinal) >= 0) { string[] rows = inputDataRow.Split('-'); for (int i = Convert.ToInt32(rows[0].ToString(CultureInfo.InvariantCulture)); i <= Convert.ToInt32(rows[1].ToString(CultureInfo.InvariantCulture)); i++) { testresult = ExecuteOneTest(testId, i.ToString(CultureInfo.InvariantCulture), driver, ref testStatus); if (testresult == false) { recursivetestresult = false; } } return(recursivetestresult); } if (inputDataRow.IndexOf(",", 0, StringComparison.Ordinal) >= 0) { string[] rows = inputDataRow.Split(','); foreach (string key in rows) { testresult = ExecuteOneTest(testId, key, driver, ref testStatus); if (testresult == false) { recursivetestresult = false; } } return(recursivetestresult); } foreach (DataRow testrow in dt.Rows) { testrow["InputDataRow"] = inputDataRow; } } foreach (DataRow row in dt.Rows) { if (myInstance.StopExecution) { testresult = false; break; } bool stepresult = ExecuteStep(row, driver); if (stepresult == false) { testresult = false; if (skipTestOnStepFail == "yes") { LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0, " Previous Step is Failed => TestStatus=Skiped moving to next test", Constants.Error, "0", _projectId, _projectPageId); break; } } } adapterTest.GetTestName(Convert.ToInt32(testId)); int projectPageSectionId = Convert.ToInt32(adapterTest.GetProjectPageID(Convert.ToInt32(Convert.ToInt32(testId)))); _projectPageId = Convert.ToInt32(adapteGuiPageSection.GetGuiPageID(projectPageSectionId)); _projectId = Convert.ToInt32(adapterGuiproject.GetProjectID(_projectPageId)); string description; int status; if (testresult) { description = string.Format("{0}={1}", Constants.LogTestStatus, "Passed"); status = Constants.Passed; if (testStatus.ContainsKey("PassedTests")) { testStatus["PassedTests"] = testStatus["PassedTests"] + 1; } else { testStatus.Add("PassedTests", 1); } //LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0,testname + " Test Passed with data row : " + inputDataRow, Constants.Passed, "0",_projectId,_projectPageId); } else { //LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0,testname + " Test Failed with data row : " + inputDataRow, Constants.Failed, "0",_projectId,_projectPageId); description = string.Format("{0}={1}", Constants.LogTestStatus, "Failed"); status = Constants.Failed; if (testStatus.ContainsKey("FailedTests")) { testStatus["FailedTests"] = testStatus["FailedTests"] + 1; } else { testStatus.Add("FailedTests", 1); } } LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0, description + " with DataRow=" + inputDataRow, status, "0", _projectId, _projectPageId); return(testresult); } catch (Exception exception) { Logger.Error(exception.Message, exception); return(false); } }
/// <summary> /// set driver with browser /// </summary> /// <param name="driver"></param> /// <param name="browserId"></param> /// <param name="islocal"></param> /// <returns></returns> public IWebDriver SetWebDriverBrowser(IWebDriver driver, string browserId, bool islocal) { try { if (driver != null) { driver.Quit(); } var jp = new JsonParser(); string remote = jp.ReadJson("RemoteNode"); var capability = new DesiredCapabilities(); if (remote == "no" || islocal) { switch (browserId) { case "1": case "chrome": driver = new ChromeDriver(); break; case "2": case "firefox": var profile = new FirefoxProfile { EnableNativeEvents = true }; driver = new FirefoxDriver(profile); //driver = new FirefoxDriver(); break; case "3": case "IE": driver = new InternetExplorerDriver(); break; } } else if (remote == "yes") { switch (browserId) { case "1": capability = DesiredCapabilities.Chrome(); break; case "2": var fp = new FirefoxProfile { EnableNativeEvents = true }; //capability.SetCapability(FirefoxDriver.ProfileCapabilityName, fp); capability = DesiredCapabilities.Firefox(); //_driver = new FirefoxDriver(profile); break; case "3": capability = DesiredCapabilities.InternetExplorer(); break; } string hubAddress = jp.ReadJson("HubAddress"); var uri = new Uri("http://" + hubAddress + ":4444/wd/hub"); capability.SetCapability(CapabilityType.TakesScreenshot, true); capability.IsJavaScriptEnabled = true; //capability.BrowserName= setBrowserName(browser); driver = new ScreenShotRemoteWebDriver(uri, capability); //driver = new RemoteWebDriver( uri, capability); } var js = (IJavaScriptExecutor)driver; string defaulturl = jp.ReadJson("DefaultURL"); defaulturl = defaulturl.Replace(@"\", @"\\"); if (driver != null) { driver.Navigate().GoToUrl(defaulturl); } string onboarding = jp.ReadJson("LocalStorageOnboardingMode"); if (onboarding != string.Empty) { if (js != null) { js.ExecuteScript("EToro.storage.localStorage.write('onboardingMode', '" + onboarding + "')"); } } return(driver); } catch (Exception exception) { Logger.Error(exception.Message); return(driver); } }
/// <summary> /// Execute one step generaly called from execution manger (gets vlaue from data table ) /// </summary> public bool ExecuteOneStep(DataRow dr, string inputDataColumn, string inputTableValue, IWebDriver driver) { int guiMapCommandId = -1; string guiMapTagTypeValue = string.Empty; var jp = new JsonParser(); By webelement = By.XPath("null"); bool result = true; int waitElementDisplayed = Convert.ToInt32(jp.ReadJson("WaitElementDisplayed")); int waitElementExists = Convert.ToInt32(jp.ReadJson("WaitElementExists")); int expandedWaitFindElement = Convert.ToInt32(jp.ReadJson("ExpandedWaitFindElement")); int delayBetweenCommands = Convert.ToInt32(jp.ReadJson("DelayBetweenCommands")); if (inputTableValue.IndexOf(Constants.RegularExpressionTestingEnvironment, 0, StringComparison.Ordinal) >= 0) { inputTableValue = inputTableValue.Replace(Constants.RegularExpressionTestingEnvironment, jp.ReadJson("TestingEnvironment")); } try { int guiMapId; using (var adapterGuimap = new GuiMapTableAdapter()) { guiMapId = Convert.ToInt32(dr["GuiMapID"].ToString().Trim()); guiMapCommandId = Convert.ToInt32(dr["GuiMapCommandID"].ToString().Trim()); int guiMapTagTypeId = Convert.ToInt32(adapterGuimap.GetTagTypeID(guiMapId)); if (guiMapId != 0) { guiMapTagTypeValue = adapterGuimap.GetTagTypeValue(guiMapId).Trim(); webelement = (By)GetWebElement(guiMapTagTypeId, guiMapTagTypeValue, inputTableValue); } } if (webelement != null) { Thread.Sleep(delayBetweenCommands); switch (guiMapCommandId) { case 1: //"click": // clickTheLinkAndFocusOnANewWindow(_driver,webelement); driver.FindElement(webelement).Click(); Logger.Done(webelement + " clicked"); break; case 2: //"sendkey": driver.FindElement(webelement).Clear(); driver.FindElement(webelement).SendKeys(inputTableValue); Logger.Done(webelement + " Sentkey with " + inputTableValue); break; case 3: //navigate driver.Navigate().GoToUrl(inputTableValue); Logger.Done("navigated to " + inputTableValue); break; case 4: //findelementt driver.FindElement(webelement); Logger.Done(webelement + " Found"); break; case 6: //"check": driver.FindElement(webelement).Click(); break; case 7: //"mouseover": var builder = new Actions(driver); builder.MoveToElement(driver.FindElement(webelement)).Build().Perform(); Thread.Sleep(1000); Logger.Done(webelement + " Mouse Overed"); break; case 8: //"waituntill-findelement": result = Waituntilfindelement(webelement, waitElementExists, driver); Logger.Done(webelement.ToString().Trim() + " waited"); break; case 9: //"compare text if (String.CompareOrdinal(driver.FindElement(webelement).Text, inputTableValue) != 0) { result = false; LocalLogFailure( "The Expected text is wrong actual: " + driver.FindElement(webelement).Text + " vs expected :" + inputTableValue, null, Constants.Failed); } Logger.Done(webelement + " compared text to " + inputTableValue); break; case 10: //select drop down by Index // select the drop down list////System.Windows.MessageBox IWebElement dropdown = driver.FindElement(webelement); //create select element object var selectElement = new SelectElement(dropdown); //select by index selectElement.SelectByIndex(Convert.ToInt32(inputTableValue)); ExecuteJavaScript( "$('" + guiMapTagTypeValue + "').val('" + inputTableValue + "').change()", driver); Logger.Done(webelement + " dropeddown with index " + inputTableValue); break; case 11: //wait untill displayed WaituntilelementDisplayed(webelement, waitElementDisplayed, driver, false); break; case 12: //verify is exists IWait <IWebDriver> wait = new WebDriverWait(driver, TimeSpan.FromSeconds(waitElementExists)); //IWebElement a = ExpectedConditions.ElementExists(webelement); wait.Until(ExpectedConditions.ElementExists(webelement)); break; case 13: //select drop down // select the drop down list////System.Windows.MessageBox dropdown = driver.FindElement(webelement); if (dropdown.Displayed) { //create select element object selectElement = new SelectElement(dropdown); selectElement.SelectByText(inputTableValue); // select by text //selectElement.SelecyByText("HighSchool"); } ExecuteJavaScript( "$('" + guiMapTagTypeValue + " option:selected').val('" + inputTableValue + "').change()", driver); Logger.Done(webelement + " dropeddown with text " + inputTableValue); break; case 14: //select drop down // select the drop down list////System.Windows.MessageBox dropdown = driver.FindElement(webelement); if (dropdown.Displayed) { //create select element object selectElement = new SelectElement(dropdown); //select by Value selectElement.SelectByValue(inputTableValue); } ExecuteJavaScript( "$('" + guiMapTagTypeValue + "').val('" + inputTableValue + "').change()", driver); Logger.Done(webelement + " dropeddown with value " + inputTableValue); break; case 15: //SetlocalStorage Run JavaScript(any java script) // select the drop down list////System.Windows.MessageBox ExecuteJavaScript(inputTableValue, driver); Logger.Done("Java script executed with " + inputTableValue); break; case 16: //wait untill find element long time expanded WaituntilelementDisplayed(webelement, expandedWaitFindElement, driver, false); break; case 17: //Count number of elements and Compare int elementcount = driver.FindElements(webelement).Count(); if (elementcount != Convert.ToInt32(inputTableValue)) { result = false; LocalLogFailure( "The Expected count is wrong:" + inputTableValue + " vs actual: " + elementcount, null, Constants.Failed); } Logger.Done("number of elements " + webelement + "is " + elementcount + "compared to: " + inputTableValue); break; case 18: //scrolldown ExecuteJavaScript("window.scroll(0,document.body.scrollHeight)", driver); Logger.Done("Scrolled Down"); break; case 19: //scrollup ExecuteJavaScript("window.scroll(0,0)", driver); Logger.Done("Scrolled Up"); break; case 20: //switchtowindow SwitchTowindow(driver, inputTableValue); break; case 21: //validateOpenTrades break; case 22: //case close current window driver.Close(); break; case 23: //close window by name string currentwindowhandle = driver.CurrentWindowHandle; SwitchTowindow(driver, inputTableValue); driver.Close(); //back to current window driver.SwitchTo().Window(currentwindowhandle); break; case 24: //clear cookeis driver.Manage().Cookies.DeleteAllCookies(); // driver.Navigate().Refresh(); break; case 25: //wait untill find element with refresh WaituntilelementDisplayed(webelement, waitElementDisplayed, driver, true); break; case 26: //create new user break; case 27: //create commenter badge break; case 28: //refresh page driver.Navigate().Refresh(); break; case 29: //runexe string automaticHedgerPath = jp.ReadJson("ExePath"); Process newProcess = Process.Start(automaticHedgerPath); Thread.Sleep(10000); if (newProcess != null) { newProcess.Kill(); } break; case 30: //sleep sleep(guiMapId); break; case 31: //ComapreDB to... savedText or value // connect string + query split var guimapadapter = new GuiMapTableAdapter(); string ConString_Query = guimapadapter.GetTagTypeValue(guiMapId); string[] ConString_QuerySplit = ConString_Query.Split('!'); var sql = new Sql(); string DBResult = sql.GetDBSingleValue(ConString_QuerySplit[0], ConString_QuerySplit[1]); if (String.CompareOrdinal(DBResult, inputTableValue) != 0) { result = false; LocalLogFailure( "The Expected text is wrong actual: " + DBResult + " vs expected :" + inputTableValue, null, Constants.Failed); } Logger.Done(ConString_QuerySplit[1] + " compared text to " + inputTableValue); break; case 32: //SaveElementText SetLastCreatedValue(inputDataColumn, driver.FindElement(webelement).Text); break; case 33: //Accept Alert driver.SwitchTo().Alert().Accept(); break; case 34: //Accept Dissmiss driver.SwitchTo().Alert().Dismiss(); break; case 35: //SaveElementText to memmory SetLastCreatedValue("memmory", driver.FindElement(webelement).Text); break; case 36: //ComapreDB to... savedText or value in memmory // connect string + query split var guimapadapter36 = new GuiMapTableAdapter(); string ConString_Query36 = guimapadapter36.GetTagTypeValue(guiMapId); ConString_Query36 = GetDBElement(ConString_Query36, inputTableValue); string[] ConString_QuerySplit36 = ConString_Query36.Split('!'); var sql36 = new Sql(); string DBResult36 = sql36.GetDBSingleValue(ConString_QuerySplit36[0], ConString_QuerySplit36[1]); if (String.CompareOrdinal(DBResult36, GetLastCreatrdValue("memmory")) != 0) { result = false; LocalLogFailure( "The Expected text is wrong actual: " + DBResult36 + " vs expected :" + GetLastCreatrdValue("memmory"), null, Constants.Failed); } Logger.Done(ConString_QuerySplit36[1] + " compared text to " + inputTableValue); break; default: LocalLogFailure("Can't run this command:" + guiMapTagTypeValue.Trim(), null, Constants.Failed); break; } } else { result = false; LocalLogFailure(guiMapCommandId + ": web element was not found : " + guiMapTagTypeValue.Trim(), null, Constants.Failed); } } catch (Exception exception) { LocalLogFailure(exception.Message, exception, Constants.Error); result = false; } if (result) { Logger.Passed(guiMapCommandId + ": TestStep : " + guiMapTagTypeValue.Trim()); } else { Logger.Failed(guiMapCommandId + ": TestStep : " + guiMapTagTypeValue.Trim()); } return(result); }
/// <summary> /// Unitest will cal this one /// </summary> /// <param name="batchId"></param> /// <returns></returns> public bool ExecuteOneBatch(string batchId) { var jp = new JsonParser(); string remote = jp.ReadJson("RemoteNode"); int timeoutAllScenarios = Convert.ToInt32(jp.ReadJson("TimeoutAllScenarios")) * 1000; var sel = new Selenium(); if (batchId == string.Empty) { MessageBox.Show("Select Batch first", "Applenium"); return(false); } var sql = new Sql(); _batchId = Convert.ToInt32(batchId); DataTable dtScenario = sql.GetDataTable(Constants.StrBatchScenariosToSelenium, _batchId.ToString(CultureInfo.InvariantCulture)); SetAllScenariusStatusToRunorNot(dtScenario, Constants.Pending); var adapterBatches = new BatchesTableAdapter(); var adapterBatchLogic = new BatchLogicTableAdapter(); var adapterBrowser = new BrowsersTableAdapter(); string batchname = adapterBatches.GetBatchName(_batchId); var adapterScenario = new ScenarioTableAdapter(); _projectId = Convert.ToInt32(adapterBatches.GetProjectID(Convert.ToInt32(_batchId))); LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Started", Constants.Done, "0", _projectId, 0); Singleton myInstance = Singleton.Instance; myInstance.BatchResult = true; var threadFinishEvents = new List <EventWaitHandle>(); foreach (DataRow row in dtScenario.Rows) { if (myInstance.StopExecution) { myInstance.BatchResult = false; break; } var threadFinish = new EventWaitHandle(false, EventResetMode.ManualReset); threadFinishEvents.Add(threadFinish); string browserId = row["BrowserID"].ToString(); string batchLogicId = row["BatchLogicID"].ToString(); string browserName = adapterBrowser.GetBrowserName(Convert.ToInt32(browserId)); IWebDriver driver = null; ThreadStart ts = delegate { driver = sel.SetWebDriverBrowser(driver, browserId, false); if (driver == null) { return; } string scenarioId = row["ScenarioID"].ToString(); adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId), Constants.Running, Convert.ToInt32(batchLogicId)); string scenarioname = adapterScenario.GetScenarioName(Convert.ToInt32(scenarioId)); LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, scenarioname + " Scenario will run on " + browserName + " browser.", Constants.Done, "0", _projectId, 0); // Do long work here bool scanearioresult = ExecuteOneScenario(scenarioId, driver); Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (EventHandler) delegate { if (scanearioresult == false) { myInstance.BatchResult = false; adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId), Constants.Failed, Convert.ToInt32(batchLogicId)); } else { adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId), Constants.Passed, Convert.ToInt32(batchLogicId)); } driver.Quit(); threadFinish.Set(); }, null, null); }; ts.BeginInvoke(delegate(IAsyncResult aysncResult) { ts.EndInvoke(aysncResult); }, null); if (remote == "no") { WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); } } WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios)); if (myInstance.BatchResult) { LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Passed", Constants.Passed, "0", _projectId, 0); } else { LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Failed", Constants.Failed, "0", _projectId, 0); //LogFailiure(_runExecutionID, 0, null, 0, null, "Description in the scenario"); } SetAllScenariusStatusToRunorNot(dtScenario, Constants.NotRunnig); return(myInstance.BatchResult); }
internal bool ExecuteOneTest(string testId, string inputDataRow, IWebDriver driver) { if (testId == string.Empty) { MessageBox.Show("Select test first", "Applenium"); return(false); } var sql = new Sql(); DataTable dt = sql.GetDataTable(Constants.StrTestStepsToSelenium, testId); bool testresult = true; bool recursivetestresult = true; var adapterGuiproject = new GuiProjectPageTableAdapter(); var adapterTest = new TestTableAdapter(); string testname = adapterTest.GetTestName(Convert.ToInt32(testId)); LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0, testname + " Test Started with data row : " + inputDataRow, Constants.Done, "0", _projectId, _projectPageId); var jp = new JsonParser(); string skipTestOnStepFail = jp.ReadJson("SkipTestOnStepFail"); Singleton myInstance = Singleton.Instance; // Will always be the same instance... if (inputDataRow != null) { if (inputDataRow.IndexOf("-", 0, StringComparison.Ordinal) >= 0) { string[] rows = inputDataRow.Split('-'); for (int i = Convert.ToInt32(rows[0].ToString(CultureInfo.InvariantCulture)); i <= Convert.ToInt32(rows[1].ToString(CultureInfo.InvariantCulture)); i++) { testresult = ExecuteOneTest(testId, i.ToString(CultureInfo.InvariantCulture), driver); if (testresult == false) { recursivetestresult = false; } } return(recursivetestresult); } if (inputDataRow.IndexOf(",", 0, StringComparison.Ordinal) >= 0) { string[] rows = inputDataRow.Split(','); foreach (string key in rows) { testresult = ExecuteOneTest(testId, key, driver); if (testresult == false) { recursivetestresult = false; } } return(recursivetestresult); } foreach (DataRow testrow in dt.Rows) { testrow["InputDataRow"] = inputDataRow; } } foreach (DataRow row in dt.Rows) { if (myInstance.StopExecution) { testresult = false; break; } bool stepresult = ExecuteStep(row, driver); if (stepresult == false) { testresult = false; if (skipTestOnStepFail == "yes") { LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0, " Previous Step is Failed => Skipping test " + testname + " moving to next test : ", Constants.Error, "0", _projectId, _projectPageId); break; } } } adapterTest.GetTestName(Convert.ToInt32(testId)); _projectPageId = Convert.ToInt32(adapterTest.GetProjectPageID(Convert.ToInt32(Convert.ToInt32(testId)))); _projectId = Convert.ToInt32(adapterGuiproject.GetProjectID(_projectPageId)); if (testresult) { LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0, testname + " Test Passed with data row : " + inputDataRow, Constants.Passed, "0", _projectId, _projectPageId); } else { LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0, testname + " Test Failed with data row : " + inputDataRow, Constants.Failed, "0", _projectId, _projectPageId); //LogFailiure(_runExecutionID, flowID, null, Convert.ToInt32(TestId), test_name, "Description in the step"); } return(testresult); }