/// <summary> /// take and execute one action from the ConcurrentBag if any item exist /// </summary> public ActionDef TryExecuteAction() { ActionDef action; if (UiActions.TryTake(out action)) { action.ActionService.Act(action.ActionData); } return(action); }
/// <summary> /// Configuration reads test configurations value from TestConfigurations excel file. /// </summary> public static void Configuration() { try { var configCount = ConfigName.TestDataConfigCount; //// Run the configuration for saving the test data in mentioned variable name for (var configIndex = 1; configIndex <= configCount; configIndex++) { //// Loop each testcase steps var isSuccess = true; var configList = ConfigName.TestConfigNames; foreach (var configData in configList) { switch (configData.TestDataType.ToUpper()) { case Constants.String: case Constants.Integer: isSuccess = UiActions.BufferValues(configData); break; default: Result.PassStepOutandSave( configIndex.ToString(), configData.TestStepNo, Constants.TestIterations, Constants.Fail, string.Format(Constants.Messages.NotSupported, configData.ConfigAction), configData.Remarks); isSuccess = false; break; } if (!isSuccess) { break; } } if (!isSuccess && Result.GetTestScriptResult() == Constants.Fail) { Assert.Fail(Constants.Messages.TestCaseFailedError, Reporting.FilePath); } } } catch (Exception ex) { LogHelper.ErrorLog(ex, Constants.ClassName.TestConfigurations, MethodBase.GetCurrentMethod().Name); throw; } }
/// <summary> /// take and execute all actions from the ConcurrentBag if any item exist /// </summary> public bool TryExecuteActions() { int count = 0; while (UiActions.Count > 0) { ActionDef action; if (UiActions.TryTake(out action)) { action.ActionService.Act(action.ActionData); count++; } } return(count > 0); }
public string ProjBuildingFlow(By modElement) { try { try { UiActions.WebDriverWait(ObjectRepo.Driver, modElement, 30, "not found"); ObjectRepo.Driver.FindElement(modElement).Click(); } catch (Exception) { ObjectRepo.Driver.FindElement(modElement).Click(); } Thread.Sleep(5000); ObjectRepo.Driver.FindElement( By.XPath("//form[@name='buildingDimensionsForm']//button[@ng-click='checkAndSave(true)']")).Click(); Thread.Sleep(6000); ObjectRepo.Driver.FindElement(By.XPath("//button[@ng-click='ok()']")).Click(); Thread.Sleep(3000); ObjectRepo.Driver.FindElement(By.XPath("//div[@id='roofDetailsContainer']//button[2]")).Click(); Thread.Sleep(3000); ObjectRepo.Driver.FindElement(By.XPath("//button[text()='Save for all walls']")).Click(); Thread.Sleep(6000); ObjectRepo.Driver.FindElement(By.XPath("//button[@ng-click=\"ok()\"]")).Click(); } catch (Exception e) { failedException = "Fail" + e; return(failedException); } return("Passed"); }
IUiActionHandler IExomiaWebBrowser.CreateJsUiActions() { lock (_services) { UiActions uiActions = new UiActions(); if (_services.TryGetValue(typeof(IUiActionHandler), out object service)) { if (service is IDisposable disposable) { disposable.Dispose(); } JavascriptObjectRepository.UnRegister(EX_UI); _services[typeof(IUiActionHandler)] = uiActions; _services[typeof(IJsUiActions)] = uiActions; } else { _services.Add(typeof(IUiActionHandler), uiActions); _services.Add(typeof(IJsUiActions), uiActions); } return(uiActions); } }
/// <summary> /// add an action to the bag /// </summary> public void AddAction(BaseActionService actionService, object actionData) { UiActions.Add(new ActionDef { ActionData = actionData, ActionService = actionService }); }
public static void Main(string[] args) { Stopwatch stopwatch = Stopwatch.StartNew(); //creates and start the instance of Stopwatch //Decleration Xq2PageSetup xq2 = new Xq2PageSetup(); ProjBuildingAndDoorsNavigationFlowForDataMigration projNavigation = new ProjBuildingAndDoorsNavigationFlowForDataMigration(); //Read data(projectId) from excel GetExcelData getExcelData = new GetExcelData(); var projectIdList = getExcelData.GetProjectIdList(1, "ProjectId"); var pro = projectIdList.ToString().Split(','); //Delete existing csv result file // getExcelData.DeleteFile(); //Login to application xq2.LoginToApplication(); //var rowId = 1; //Building & Doors flow for (int projectIndex = 0; projectIndex < pro.Length - 1; projectIndex++) { var emptyBid = ""; var _result = ""; int iBid = 0; var executionStatus = ""; var xqOneProjectId = ""; var projectId = pro[projectIndex]; try { Thread.Sleep(3000); ObjectRepo.Driver.Url = "http://xq-perf.azurewebsites.net/" + "#!/project/" + projectId; Thread.Sleep(10000); //Get XQ1 Project number //var migratedProjectText = ObjectRepo.Driver // .FindElement(By.XPath("//div[@ng-if=\'project.dataMigrationLogId\']")).Text; //var firstMigratedProjectText = migratedProjectText.Split('#'); //var secondMigratedProjectText = firstMigratedProjectText[1].Split(','); //xqOneProjectId = secondMigratedProjectText[0].Trim(); //Check Bid is present or not By byNoBid = By.XPath("//div[@ng-if=\'pcBids.length == 0 && !addingBid\']"); bool elementDisplayedAndVisible = UiActions.IsElementDisplayedAndVisible(byNoBid, null); if (elementDisplayedAndVisible) { Thread.Sleep(3000); emptyBid = ObjectRepo.Driver.FindElement(byNoBid).Text.Trim(); } var emptyBidString = (" There are no current bids for selected customer. ").Trim(); if (emptyBid != emptyBidString) { var noOfBids = ObjectRepo.Driver.FindElements( By.XPath("//li[@select=\'tabSelected(bid)\']/a//div[contains(text(),\'Bid\')]")); if (noOfBids.Count > 0) { for (iBid = 1; iBid <= noOfBids.Count; iBid++) { Thread.Sleep(7000); ObjectRepo.Driver .FindElement(By.XPath("//li[@select=\'tabSelected(bid)\'][" + iBid + "]/a//div[contains(text(),\'Bid\')]")).Click(); //var projStatus = ObjectRepo.Driver // .FindElement(By.XPath("//li[@select=\'tabSelected(bid)\'][" + iBid + "]/a//span")).Text; // Project Status = Lead //if (projStatus.Equals("Lead")) //{ // Thread.Sleep(5000); // var noOfMods = ObjectRepo.Driver.FindElements( // By.XPath( // "//div[@ng-click=\'checkAndCollapseProjectDetails(building.isOpen)\']//a")); // bool moDisplayedAndVisible = UiActions.IsElementDisplayedAndVisible(By.XPath( // "//div[@ng-click=\'checkAndCollapseProjectDetails(building.isOpen)\']//a"), null); // if (moDisplayedAndVisible) // { // for (int iModIndex = 1; iModIndex <= noOfMods.Count; iModIndex++) // { // By modElement = // By.XPath( // "//div[@ng-click=\'checkAndCollapseProjectDetails(building.isOpen)\'][" + // iModIndex + "]//a"); // executionStatus = projNavigation.ProjBuildingFlow(modElement); // if (executionStatus != "Passed") // { // _result = executionStatus; // } // } // executionStatus = projNavigation.ProjDoorsFlow(); // if (executionStatus != "Passed") // { // _result = executionStatus; // } // } // //Project Status = Quote or Sales Order // else if (projStatus.Equals("Quote") || projStatus.Equals("Sales Order")) // { // Thread.Sleep(5000); // } //} executionStatus = projNavigation.ViewReports(); if (executionStatus != "Passed") { _result = executionStatus; } //getExcelData.ResultOfProjectId(executionStatus, _result, projectId, xqOneProjectId, // "Bid[" + iBid + "]"); getExcelData.ResultOfProjectId(executionStatus, _result, projectId, "Bid[" + iBid + "]"); } } } else { executionStatus = "Passed"; _result = emptyBidString; //getExcelData.ResultOfProjectId(executionStatus, _result, projectId, xqOneProjectId, "No Bid"); getExcelData.ResultOfProjectId(executionStatus, _result, projectId, "No Bid"); } } catch (Exception e) { //getExcelData.ResultOfProjectId("Project Loading Failed", _result, projectId, xqOneProjectId, // "Bid[" + iBid + "]"); getExcelData.ResultOfProjectId("Project Loading Failed", _result, projectId, "Bid[" + iBid + "]"); } } ObjectRepo.Driver.Quit(); Thread.Sleep(5000); stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds); //getExcelData.ResultOfProjectId("", "", stopwatch.Elapsed.TotalMinutes.ToString(),"", "Total Execution Time in minutes"); getExcelData.ResultOfProjectId("", "", stopwatch.Elapsed.TotalMinutes.ToString(), "Total Execution Time in minutes"); //for (int rowId = 1; rowId < pro.Length; rowId++) //{ // getExcelData.ResultOfProjectId(rowId, "Pass", "Failedexception", pro[rowId]); //} }
/// <summary> /// Executes test steps. /// </summary> public static void Execute() { try { TestSessionId = Guid.NewGuid(); //// Initiliaze test data TestCase.TestDataCount = Constants.Zero; var errorMessage = string.Empty; if (!Data.InitiliazeTestCaseAndTestData(ref errorMessage)) { Assert.Inconclusive(Constants.Messages.TestInitializationError, errorMessage); } //// Run the test case once for every test data that exist var testCaseCount = TestCase.TestDataCount; for (var testCaseIndex = 1; testCaseIndex <= testCaseCount; testCaseIndex++) { var isSuccess = true; var testStepLength = TestCase.TestStepList.Count; for (var testStepCount = 0; testStepCount <= testStepLength - 1; testStepCount++) { var teststep = new TestStep(); var testStep = teststep; testStep.TestDataKeyToUse = Convert.ToString(testCaseIndex); testStep.Action = TestCase.TestStepList[testStepCount].Action; testStep.TestData = TestCase.TestStepList[testStepCount].TestData; testStep.TestStepNumber = TestCase.TestStepList[testStepCount].TestStepNumber; testStep.UiControl = TestCase.TestStepList[testStepCount].UiControl; testStep.Verification = TestCase.TestStepList[testStepCount].Verification; testStep.Remarks = TestCase.TestStepList[testStepCount].Remarks; switch (testStep.Action.ToUpper()) { case Constants.TestStepAction.CloseBrowsers: isSuccess = UiActions.CloseAllBrowsers(testStep); break; case Constants.TestStepAction.ClearBrowserCookies: isSuccess = UiActions.ClearBrowserCookies(testStep); break; case Constants.TestStepAction.ClearBrowserCashe: isSuccess = UiActions.ClearBrowserCache(testStep); break; case Constants.TestStepAction.LaunchBrowser: isSuccess = UiActions.LaunchBrowser(testStep); break; case Constants.TestStepAction.LaunchWindow: isSuccess = UiActions.LaunchWindow(testStep); break; case Constants.TestStepAction.EditUiControl: isSuccess = UiActions.EditUiControl(testStep); break; case Constants.TestStepAction.Verify: isSuccess = UiActions.Verify(testStep, true); break; case Constants.TestStepAction.WaitForUi: isSuccess = UiActions.WaitForUi(testStep); break; case Constants.TestStepAction.SendKeys: isSuccess = UiActions.SendKeys(testStep); break; case Constants.TestStepAction.SaveUiControlValue: isSuccess = UiActions.SaveUiControlValue(testStep); break; default: Result.PassStepOutandSave( testStep.TestDataKeyToUse, testStep.TestStepNumber, Constants.TestIterations, Constants.Fail, string.Format(Constants.Messages.NotSupported, testStep.Action), testStep.Remarks); isSuccess = false; break; } if (!isSuccess) { break; } //// Exit if one test step failed } if (!isSuccess && Result.GetTestScriptResult() == Constants.Fail) { //// Some test step failed, raise Assert.Fail after all test data iterations are completed var bounds = Screen.GetBounds(Point.Empty); using (var bitmap = new Bitmap(bounds.Width, bounds.Height)) { using (var objGraphic = Graphics.FromImage(bitmap)) { objGraphic.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size); } bitmap.Save( new StringBuilder() .Append(Reporting.PathString) .Append(Constants.DoubleBackslash) .Append(Path.GetFileNameWithoutExtension(TestCase.Name)) .Append(Constants.Jpg).ToString(), ImageFormat.Jpeg); Hyplink = new StringBuilder() .Append(Constants.Hyperlink) .Append(Reporting.PathString) .Append(Constants.DoubleBackslash) .Append(Path.GetFileNameWithoutExtension(TestCase.Name)) .Append(Constants.Jpg) .Append(@""",""") .Append(Path.GetFileNameWithoutExtension(TestCase.Name)) .Append(@""")").ToString(); } Assert.Fail(Constants.Messages.TestCaseFailedError, Reporting.FilePath); } } LogHelper.EventLog( string.Format( Constants.Messages.SuccessfullCompletion, MethodBase.GetCurrentMethod().Name), Constants.ClassName.TestCases, MethodBase.GetCurrentMethod().Name); } catch (Exception ex) { LogHelper.ErrorLog(ex, Constants.ClassName.TestCases, MethodBase.GetCurrentMethod().Name); throw; } }
public string ViewReports() { try { Thread.Sleep(5000); ObjectRepo.Driver.FindElement(By.XPath("//button[@id='quote-button']")).Click(); Thread.Sleep(7000); try { ObjectRepo.Driver.FindElement(By.XPath("//li[@ng-click='generateMaterialList(bid)']/a")).Click(); Thread.Sleep(15000); ObjectRepo.Driver.FindElement(By.XPath("//button[@ng-click='close()']")).Click(); Thread.Sleep(15000); ObjectRepo.Driver.FindElement(By.XPath("//button[@id='quote-button']")).Click(); Thread.Sleep(15000); ObjectRepo.Driver.FindElement(By.XPath("//li[@ng-click='getQuote(bid, false)']/a")).Click(); Thread.Sleep(15000); ObjectRepo.Driver.FindElement(By.XPath("//button[@ng-click='close()']")).Click(); } catch (NoSuchElementException e) { bool moDisplayedAndVisible = UiActions.IsElementDisplayedAndVisible(By.XPath( "//div[@ng-click=\'checkAndCollapseProjectDetails(building.isOpen)\']//a"), null); bool additionalMaterialAvailable = UiActions.IsElementDisplayedAndVisible(By.XPath( "//div[@ng-click=\'checkAndCollapseProjectDetails(bid.isMiscOpen)\']//i[@class=\'glyphicon glyphicon-hand-down\']"), null); if (moDisplayedAndVisible) { ObjectRepo.Driver.FindElement(By.XPath("//span[@ng-if=\'building.errorMsgs\']")).Click(); var buildingErrorMessage = ObjectRepo.Driver .FindElement(By.XPath("//span[@ng-if=\'building.errorMsgs\']/following-sibling::div//li")) .Text; failedException = "Building Error Message: " + buildingErrorMessage; return(failedException); } if (additionalMaterialAvailable) { Thread.Sleep(10000); ObjectRepo.Driver.FindElement(By.XPath("//button[@id='quote-button']")).Click(); Thread.Sleep(10000); ObjectRepo.Driver.FindElement(By.XPath("//li[@ng-click='getQuote(bid, false)']/a")).Click(); Thread.Sleep(10000); var additionalMaterialsErrorMessage = ObjectRepo.Driver .FindElement(By.XPath("//div[@id=\'toast-container\']//button/following-sibling::div")) .Text; Thread.Sleep(5000); ObjectRepo.Driver.FindElement(By.XPath("//div[@id=\'toast-container\']//button")).Click(); Thread.Sleep(5000); failedException = "Additional Materials Error Message: " + additionalMaterialsErrorMessage; return(failedException); } } } catch (ArgumentNullException elementException) { Console.WriteLine(elementException); return("Failed");; } catch (NoSuchElementException elementException) { Console.WriteLine(elementException); return("Failed");; } catch (Exception e) { failedException = "Fail" + e; return("Failed"); } return("Passed"); }