public void RunTheBot(string username, string password) { pdfHandler.DeleteFile(webBrowser.downloadPath); Dictionary <int, int> matchFields = new Dictionary <int, int>(); emailHandler.LoginAndNavigateToInbox(username, password); webBrowser.Click(WebElements.BtnInsuranceLabel); List <IWebElement> unreadMails = emailHandler.GetUnreadEmails(); foreach (IWebElement item in unreadMails) { CustomerDetailsModel cModel = new CustomerDetailsModel(); PolicyDetailsModel pModel = new PolicyDetailsModel(); webBrowser.ClickWithJavaScript(item.FindElement(By.CssSelector(WebElements.ChildElementUnreadEmails))); Dictionary <string, string> paths = emailHandler.DownloadAndGetFilePaths(); //fileHandler.Open(paths.Values.ToList()); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var statusFrom = new Status(paths.Values.ToList()); Application.Run(statusFrom); foreach (KeyValuePair <string, string> path in paths) { if (path.Value.Contains("Customer")) { cModel = GetPDFFromKYCForm(path.Value); } else { pModel = GetDetailsFromInsuranceCopy(path.Value); } } matchFields = MatchingFields(cModel, pModel); string result = $"Using {paths.Keys.ToArray()[0]} and {paths.Keys.ToArray()[1]}, {matchFields.Keys.FirstOrDefault()} fields matching out of 22 fields and {matchFields.Values.FirstOrDefault()} are empty"; // statusFrom.resultText = result; // fileHandler.Close("AcroRd32"); webBrowser.Click(WebElements.BtnReply); webBrowser.EnterText(WebElements.TxtBoxReplyMessage, "Hello," + "\n" + result + "\nThank You\nReliance Bot"); webBrowser.Click(WebElements.BtnSend); webBrowser.Pause(3); webBrowser.Click(WebElements.BtnInsuranceLabel); pdfHandler.DeleteFile(webBrowser.downloadPath); } webBrowser.Dispose(); }
public override void ElementRun(IRootElement root, IWebBrowser browser, ITestElement control) { String xPath = null; if (Text != null) { xPath = $".//div[contains(@class,'a2-tab-bar-item')]/a[contains(@class,'a2-tab-button')]/span[contains(@class,'content')][normalize-space()={Text.XPathText()}]"; } browser.Click(control.GetElementByXPath(xPath)); }
public override void ElementRun(IRootElement root, IWebBrowser browser, ITestElement control) { String xPath = null; if (Icon != null) { xPath = $"./ancestor::div[contains(@class, 'input-group')]//*[contains(@class, 'add-on')]//i[contains(@class, 'ico-{Icon.ToKebabCase()}')]"; } browser.Click(control.GetElementByXPath(xPath)); }
public override void ElementRun(IRootElement root, IWebBrowser browser, ITestElement control) { String xPath = null; if (Text != null) { xPath = $".//button[contains(@class,'dropdown-item')][normalize-space()={Text.XPathText()}]"; } browser.Click(control.GetElementByXPath(xPath)); browser.Escape(); }
public void LoginAndNavigateToInbox(string Username, string Password) { webBrowser.Invoke("https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin"); if (webBrowser.IsElementDisplayed(WebElements.TxtBoxEmail)) { webBrowser.EnterText(WebElements.TxtBoxEmail, Username); webBrowser.Click(WebElements.BtnNext); webBrowser.WaitForElementVisible(WebElements.TxtBoxPassword); webBrowser.EnterText(WebElements.TxtBoxPassword, Password); webBrowser.Click(WebElements.BtnNext); webBrowser.WaitForElementVisible(WebElements.BtnInbox); } else if (webBrowser.IsElementDisplayed(WebElements.TxtBoxPassword)) { webBrowser.EnterText(WebElements.TxtBoxPassword, Password); webBrowser.Click(WebElements.BtnNext); webBrowser.WaitForElementVisible(WebElements.BtnInbox); } else { webBrowser.WaitForElementVisible(WebElements.BtnInbox); } }
public override void ElementRun(IRootElement root, IWebBrowser browser, ITestElement control) { String xPath = null; if (Text != null) { xPath = $".//button[contains(@class,'btn')][normalize-space()={Text.XPathText()}]"; } else if (Icon != null) { xPath = $".//button[contains(@class,'btn')]/i[contains(@class, 'ico-{Icon.ToKebabCase()}')]"; } else if (TestId != null) { xPath = $".//button[contains(@class,'btn') and @test-id='{TestId}']"; } else { throw new TestException("ClickButton. Attributes 'Text' or 'Icon' are required"); } browser.Click(control.GetElementByXPath(xPath)); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { pdfHandler.DeleteFile(webBrowser.downloadPath); Dictionary <int, int> matchFields = new Dictionary <int, int>(); emailHandler.LoginAndNavigateToInbox("*****@*****.**", "Kartik1a$"); webBrowser.Click(WebElements.BtnInsuranceLabel); List <IWebElement> unreadMails = emailHandler.GetUnreadEmails(); UnreadmailCount = unreadMails.Count; foreach (IWebElement item in unreadMails) { count++; CustomerDetailsModel cModel = new CustomerDetailsModel(); PolicyDetailsModel pModel = new PolicyDetailsModel(); webBrowser.ClickWithJavaScript(item.FindElement(By.CssSelector(WebElements.ChildElementUnreadEmails))); Dictionary <string, string> paths = emailHandler.DownloadAndGetFilePaths(); Thread.Sleep(2000); isMinimize = false; backgroundWorker1.ReportProgress(1); myPaths = paths.Values.ToList(); showPdf = true; backgroundWorker1.ReportProgress(1); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); CancellationToken token = cancellationTokenSource.Token; Task task = Task.Run(() => { while (!token.IsCancellationRequested) { foreach (string status in statusValues) { Thread.Sleep(500); statusText = status; backgroundWorker1.ReportProgress(1); } } //while (token.IsCancellationRequested) //{ // token.ThrowIfCancellationRequested(); //} }, token); //CancellationTokenSource tokenSource = new CancellationTokenSource(); //CancellationToken token = tokenSource.Token; //Task t = Task.Run(() => // { // foreach (string status in statusValues) // { // Thread.Sleep(500); // statusText = status; // backgroundWorker1.ReportProgress(1); // } // }, token); foreach (KeyValuePair <string, string> path in paths) { if (path.Value.Contains("Customer")) { cModel = GetPDFFromKYCForm(path.Value); } else { pModel = GetDetailsFromInsuranceCopy(path.Value); } } matchFields = MatchingFields(cModel, pModel); string result = $"Using {paths.Keys.ToArray()[0]} and {paths.Keys.ToArray()[1]}, {matchFields.Keys.FirstOrDefault()} fields matching out of 22 fields and {matchFields.Values.FirstOrDefault()} are empty"; cancellationTokenSource.Cancel(); task.Wait(); // MessageBox.Show(result); statusText = result; backgroundWorker1.ReportProgress(1); Thread.Sleep(1000); isMinimize = true; backgroundWorker1.ReportProgress(1); // fileHandler.Close("AcroRd32"); webBrowser.Click(WebElements.BtnReply); webBrowser.EnterText(WebElements.TxtBoxReplyMessage, "Hello," + "\n" + result + "\nThank You\nReliance Bot"); webBrowser.Click(WebElements.BtnSend); webBrowser.Pause(3); webBrowser.Click(WebElements.BtnInsuranceLabel); pdfHandler.DeleteFile(webBrowser.downloadPath); Thread.Sleep(3000); } ServiceResult = "Completed"; backgroundWorker1.ReportProgress(1); webBrowser.Dispose(); }