protected StepLoopResult StepLooping(StepLoopOption option) { int errorCount = 0; for (int i = 0; i < option.MaxLoop; i++) { try { if (option.ActionTask(() => Thread.Sleep(option.SleepInterval))) { return(StepLoopResult.Complete()); } } catch (StepLoopStop ex) { return(StepLoopResult.ForceBreak()); } catch (TransferProcessException ex) { throw ex; } catch (Exception ex) { errorCount++; if ((errorCount / option.MaxLoop) * 100 > 80) { return(StepLoopResult.Error($"在回转线中发生错误已大于80%,系统强行中断 : {ex.Message}")); } } } return(StepLoopResult.SetTimeout()); }
protected override void CheckTransferStatus() { Thread.Sleep(3000); StepLoopResult result = null; if (param.IsSameBank) { result = StepLooping(new StepLoopOption((sleep) => { logger.Debug("TransferOk" + driver.PageSource); sleep(); var time = DateTime.Now.ToString("dd/MM/yyyy"); return((driver.PageSource.Contains("Số tham chiếu") || driver.PageSource.ToLower().Contains("reference number")) && driver.PageSource.Contains("class=\" CONF_OD_SUCCESS_IMG\"") && driver.PageSource.Contains("class=\" CONF_OD_FAILURE_IMG x-hide-display\"")); }) { MaxLoop = 15, SleepInterval = 1 }); } else { throw new NotImplementedException(); } if (result.HasError || !result.IsComplete) { throw new Exception("Transfer failed"); } }
protected override void CheckTransferStatus() { //throw new NotImplementedException(); StepLoopResult result = null; if (param.IsSameBank) { result = StepLooping(new StepLoopOption((sleep) => { logger.Debug("TransferOk" + driver.PageSource); sleep(); return(driver.PageSource.Contains("Transaction is sucessful") || driver.PageSource.Contains("Transaction is successful") || driver.PageSource.Contains("Giao dịch thành công") || (driver.PageSource.Contains("receipt-number") && driver.PageSource.Contains("breadcrumb-item active last"))); }) { MaxLoop = 15, SleepInterval = 1 }); } else { throw new NotImplementedException(); } if (result.HasError || !result.IsComplete) { throw new Exception("Transfer failed"); } }
protected override void CheckTransferStatus() { StepLoopResult result = null; if (param.IsSameBank) { result = StepLooping(new StepLoopOption((sleep) => { logger.Debug("TransferOk" + driver.PageSource); sleep(); return(driver.PageSource.Contains("Your transfer has been successfully processed") || driver.PageSource.Contains("Bạn đã chuyển tiền thành công")); }) { MaxLoop = 15, SleepInterval = 1 }); } else { throw new NotImplementedException(); } if (result.HasError || !result.IsComplete) { throw new Exception("Transfer failed"); } }
protected override void CheckTransferStatus() { StepLoopResult result = null; if (param.IsSameBank) { Thread.Sleep(3000); result = StepLooping(new StepLoopOption((sleep) => { logger.Debug("TransferOk" + driver.PageSource); sleep(); return(driver.PageSource.Contains("Transaction successful!") || driver.PageSource.Contains("Giao dịch chuyển khoản thành công! ")); }) { MaxLoop = 15, SleepInterval = 1 }); } else { throw new NotImplementedException(); } if (result.HasError || !result.IsComplete) { throw new Exception("Transfer failed"); } Thread.Sleep(2000); }
protected override void Transfer() { StepLoopResult result = null; if (param.IsSameBank) { driver.FindElement(By.XPath("//*[contains(text(), 'Transfer')]")).Click(); driver.FindElement(By.CssSelector("a[title^='Internal Transfer']")).Click(); driver.SwitchTo().Frame(0); result = StepLooping(new StepLoopOption((sleep) => { SelectUserAccount(); driver.ToChromeDriver().ExecuteScript("$('input[id^=\"toAcct\"]').val('" + param.RecipientAccount + "');"); driver.ToChromeDriver().ExecuteScript("$('input[id^=\"amt\"]').val('" + param.Amount.ToString() + "');"); driver.FindElement(By.CssSelector("input[id^='amt']")).SendKeys(Keys.Tab); driver.ToChromeDriver().ExecuteScript("$('textarea[id^=\"memo\"]').val('" + param.Remark + "');"); driver.FindElement(By.CssSelector("input[id^='btnSubmit']")).Click(); string errorMsg = null; try { if (driver.IsElementPresent(By.CssSelector("div[id^='serverErrorMsg']"))) { errorMsg = driver.FindElement(By.CssSelector("div[id^='serverErrorMsg']")).Text; throw new TransferProcessException(errorMsg); } else { return(true); } } catch { driver.FindElement(By.CssSelector("input[id^='btnReset']")).Click(); return(false); } }) { MaxLoop = 3, SleepInterval = 1 }); if (result.HasError || !result.IsComplete) { throw new Exception($"Transfer exception - {result.Message}"); } } else { } }
protected override void Transfer() { StepLoopResult result = null; if (param.IsSameBank) { result = StepLooping(new StepLoopOption((sleep) => { driver.FindElement(By.LinkText("Transfer within Vietcombank")).Click(); driver.ToChromeDriver().ExecuteScript("$('#HinhThucChuyenTien').val(1)"); SelectUserAccount(); var account = driver.FindElement(By.Id("SoTaiKhoanNguoiHuong")); account.Clear(); account.SendKeys(param.RecipientAccount); var amount = driver.FindElement(By.Id("SoTien")); amount.Clear(); amount.SendKeys(param.Amount.ToString()); sleep(); if (string.IsNullOrEmpty((string)driver.ToChromeDriver().ExecuteScript("return $('#TenNguoiHuongText').val()"))) { throw new Exception("Invalid recipient account"); } var remark = driver.FindElement(By.Id("NoiDungThanhToan")); remark.Clear(); remark.SendKeys(param.Remark); driver.FindElement(By.Id("btnxacnhan")).Click(); sleep(); return(driver.FindElement(By.Id("LB_TaiKhoanTrichNo")).Text == param.AccountNo); }) { MaxLoop = 3, SleepInterval = 4 }); } else { } if (result.HasError || !result.IsComplete) { throw new Exception("Transfer Step 1 have error. " + result.Message); } }
protected override void OTP() { IsWaitingOTP = true; if (param.IsSameBank) { string btnId = ""; while (string.IsNullOrEmpty(btnId)) { btnId = new Regex("(<button type=\"button\" id=\"(?<id>[a-z0-9\\-]+)\" class=\" x-btn-text\">Submit</button>)").Match(driver.PageSource).Groups["id"].Value; Thread.Sleep(200); } if (param.OTPType == 2)//smart otp { //renew the smart otp to avoid expired too fast driver.ToChromeDriver().ExecuteScript("$('button')[22].click()"); var refNo = driver.ToChromeDriver().ExecuteScript("return $(\"input[name='TRANS_ID']\").val()"); Thread.Sleep(600); socket.Clients.Client(socket.ConnectionId).Receive(JsonResponse.success(refNo, "Otp reference success", 209)); } OTPResult = OTPListener((otp) => { var submitBtn = driver.FindElement(By.Id(btnId)); var otpInput = driver.FindElement(By.Name("KEY_OTP")); otpInput.Clear(); otpInput.SendKeys(Keys.NumberPad0); otpInput.SendKeys(Keys.Backspace); otpInput.SendKeys(otp); Thread.Sleep(1000); submitBtn.Click(); //driver.ToChromeDriver().ExecuteScript("$('button')[24].click()"); Thread.Sleep(800); IsOTPSubmit = true; string invalidMessage = "OTP entered is incorrect. Please try again"; if (driver.PageSource.Contains("Please enter the OTP")) { return(new Tuple <string, bool>("Please enter the OTP, OTP cannot be null", !driver.PageSource.Contains("Please enter the OTP"))); } logger.Debug(driver.PageSource); return(new Tuple <string, bool>(invalidMessage, !driver.PageSource.Contains(invalidMessage))); }, otpExpiredDuration: 0.5, SupportReenter: bankInfo.ReenterOTP); if (OTPResult.ForceStop) { RenewOTP(); } //if (!IsOTPSubmit) //{ if (OTPResult.HasError) { throw new Exception($"[{param.AccountNo}] - Fail during OTP request. EX : {OTPResult.Message}"); } else if (!OTPResult.IsComplete) { throw new TransferProcessException("等待短信验证码超时", 406); } //todo if need extra logic to verify is stuck in the same page //} } else { throw new NotImplementedException(); } }
protected override void Transfer() { StepLoopResult result = null; if (!param.IsSameBank) { driver.FindElement(By.Id("dnn_MENU1_rptRootMenu_lnkRootMenu_3")).Click(); driver.FindElement(By.Id("dnn_MENU1_rptRootMenu_rptSubMenu1_3_lnkSubMenu_1")).Click(); Thread.Sleep(1000); result = StepLooping(new StepLoopOption((sleep) => { var selectedAccount = "627704061777254"; var data = SelectUserAccount(selectedAccount); driver.ToChromeDriver().ExecuteScript("nextto2();"); // Go to 2nd section Thread.Sleep(1000); new SelectElement(driver.FindElement(By.Id("ddlToAcctType"))).SelectByText("VIB Account"); Thread.Sleep(1000); IWebElement addNewAccLabel = driver.FindElement(By.XPath("//*[contains(text(), 'Add new account')]")); addNewAccLabel.FindElement(By.XPath("./..")).FindElements(By.TagName("input"))[0].Click(); driver.ToChromeDriver().ExecuteScript("$('input[placeholder^=\"Enter new account\"]').val('" + param.RecipientAccount + "');"); driver.ToChromeDriver().ExecuteScript("nextto3();"); // Go to 3rd section Thread.Sleep(1000); IWebElement accountNameLabel = driver.FindElement(By.XPath("//span[contains(text(), 'Account name')]")); string accountName = accountNameLabel.FindElement(By.XPath("./../..")).FindElements(By.TagName("td"))[1].Text; driver.ToChromeDriver().ExecuteScript("$('input[id^=\"txtAmout\"]').val('" + param.Amount + "');"); driver.ToChromeDriver().ExecuteScript("$('textarea[id^=\"txtDescription\"]').val('" + param.Remark + "');"); IWebElement tsfrNowLabel = driver.FindElement(By.XPath("//*[contains(text(), 'Transfer now')]")); tsfrNowLabel.FindElement(By.XPath("./..")).FindElements(By.TagName("input"))[0].Click(); driver.FindElement(By.CssSelector("a[title^='Next']")).Click(); IWebElement errorBox = null; try { //errorBox = driver.FindElement(By.CssSelector("p[id^='pMessage']")); return(true); } catch { driver.FindElement(By.CssSelector("input[id^='btnReset']")).Click(); return(false); } }) { MaxLoop = 3, SleepInterval = 1 }); } else { } }