/// <summary>
        /// Logins the user.
        /// </summary>
        /// <param name="browser">The <paramref name="browser"/> instance.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="userPassword">The user password.</param>
        /// <returns>If User login was successfully or not</returns>
        public static bool LoginUser(IE browser, string userName, string userPassword)
        {
            // Login User
            browser.GoTo("{0}yaf_login.aspx".FormatWith(TestConfig.TestForumUrl));

            // Check If User is already Logged In
            if (browser.Link(Find.ById(new Regex("_LogOutButton"))).Exists)
            {
                browser.Link(Find.ById("forum_ctl01_LogOutButton")).Click();

                browser.Button(Find.ById("forum_ctl02_OkButton")).Click();
            }

            browser.GoTo("{0}yaf_login.aspx".FormatWith(TestConfig.TestForumUrl));

            browser.ShowWindow(NativeMethods.WindowShowStyle.Maximize);

            browser.TextField(Find.ById(new Regex("Login1_UserName"))).TypeText(userName);
            browser.TextField(Find.ById(new Regex("Login1_Password"))).TypeText(userPassword);

            browser.Button(Find.ById(new Regex("LoginButton"))).ClickNoWait();

            browser.GoTo(TestConfig.TestForumUrl);

            return browser.Link(Find.ById(new Regex("LogOutButton"))).Exists;
        }
Exemple #2
0
        /// <summary>
        /// Screen Scrape Events
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        static List<EventDetail> FetchEvents(string query)
        {
            var eventDetails = new List<EventDetail>();
            using (var _browser = new IE("http://www.gettyimages.com", false))
            {
                _browser.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide);
                _browser.TextField(Find.ById("txtPhrase")).Clear();
                _browser.TextField(Find.ById("txtPhrase")).TypeText(query);
                var editorialChkfield = _browser.CheckBox(Find.ById("cbxEditorial"));

                if (!editorialChkfield.Checked)
                    editorialChkfield.Click();

                _browser.Button(Find.ById("btnSearch")).Click();

                if (_browser.Link(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_lnkSeeMore")).Exists)
                {
                    _browser.Link(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_lnkSeeMore")).Click();
                    _browser.Div(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_refinementContent")).WaitUntilExists();

                    var filterContentDiv = _browser.Div(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_refinementContent"));

                    foreach (var link in filterContentDiv.Links.Filter(Find.ByClass("refineItem")))
                    {
                        var splitList = link.OuterHtml.Split('\'');

                        if (splitList.Length > 5)
                            eventDetails.Add(new EventDetail() { EventId = int.Parse(splitList[1]), EventName = splitList[5].Trim() });
                    }
                }
            }

            return eventDetails;
        }
        public void LocatingThings()
        {
            using (var browser =
                new IE("http://www.pluralsight.com"))
            {
                //// Get a reference to a HTML input element, type=text, id=Name
                //TextField applicantName = browser.TextField(Find.ById("Name"));

                //// Get a reference to a HTML link element with id=HelpLink
                //Link helpHyperlink = browser.Link(Find.ById("HelpLink"));

                //// Get a reference to a HTML input element, type=submit, id=ApplyNow
                //Button applyButton = browser.Button(Find.ById("ApplyNow"));

                //// Get a reference to a HTML paragraph element, id=Name
                //Para nameParagraph = browser.Para(Find.ById("Name"));

            TextField applicantName = browser.TextField(Find.ById("Name"));

            Link helpHyperlink = browser.Link(Find.ById("HelpLink"));

            Button applyButton = browser.Button(Find.ById("ApplyNow"));

            Para nameParagraph = browser.Para(Find.ById("Name"));
            }
        }
Exemple #4
0
        private static void Chat(WebClient client, string path)
        {
            using (File.Create(path))
            {
            }

            using (var browser = new IE("http://widget.chatvdvoem.ru/iframe?mode=production&height=600"))
            {
                browser.Link(Find.ById("chat_start")).Click();

                var lastAnswer = string.Empty;
                var answer = string.Empty;

                while (true)
                {
                    var i = 0;

                    while (string.Equals(lastAnswer, answer,
                        StringComparison.InvariantCultureIgnoreCase))
                    {
                        Thread.Sleep(7000);

                        i++;

                        if (i > 4)
                        {
                            browser.ForceClose();
                            return;
                        }

                        var froms = browser.Elements.Filter(p => p.ClassName == "messageFrom");

                        if (froms.Count == 0)
                            continue;

                        answer = froms.Last().Text;

                        answer = answer.Substring(6);
                    }

                    lastAnswer = answer;

                    if (BlackListed(answer))
                        break;

                    var question = GetAnswer(client, answer);

                    File.AppendAllLines(path, new[] { answer, question });

                    browser.TextField(Find.ByName("text")).TypeText(question);

                    Thread.Sleep(2000);

                    browser.Button(Find.ById("text_send")).Click();
                }

                browser.ForceClose();
            }
        }
 public void BrowsingByGenreReturnsAlbumList()
 {
     using (var browser = new IE("http://localhost:1200/"))
     {
         browser.Link(Find.ByText("Rock")).Click();
         Assert.IsTrue(browser.List(Find.ById("album-list")).Children().Any());
     }
 }
        public void Adding_Items_ToCart()
        {
            using (var browser = new IE())
            {
                browser.GoTo("http://localhost:1100/");

                browser.BringToFront();

                browser.Link(Find.ByText("Pop")).Click();

                browser.Link(Find.ByText("Frank")).Click();

                browser.Link(Find.ByText("Add to cart")).Click();

                Assert.IsTrue(browser.ContainsText("8.99"));
            }
        }
        public void SimpleJavaAlertHandler()
        {
            WatiN.Core.Settings.AutoMoveMousePointerToTopLeft = false;
            WatiN.Core.Settings.MakeNewIeInstanceVisible = true;

            using(WatiN.Core.IE ie = new IE(Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")))
            {
                ie.BringToFront();
                Assert.AreEqual("Alert test", ie.Link("linkAlert").Text);

                WatiN.Core.DialogHandlers.SimpleJavaDialogHandler handler = new SimpleJavaDialogHandler();
                ie.DialogWatcher.Add(handler);

                ie.Link("linkAlert").Click();

                Assert.AreEqual("This is an alert message", handler.Message);
            }
        }
        public void FillCA()
        {
            using (var browser = new IE("http://www.eaa.org/eaa/eaa-membership/eaa-aircraft-insurance-plans/aircraft-insurance/insurance-submit-ca"))
            //using (var browser = new IE("http://dev.eaa.org/eaa/eaa-membership/eaa-aircraft-insurance-plans/aircraft-insurance/insurance-submit-ca"))
            {
                browser.AutoClose = false;
                CAPopulatePersonalInfoPage(browser);
                browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_StartNavigationTemplateContainerID_StartNextButton")).Click();

                CAPopulateAircraftPage(browser, "1");
                browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_StepNavigationTemplateContainerID_StepNextButton")).Click();

                // Add another aircraft
                browser.Link(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_xAircraftList_lnkAircraftAdd")).Click();

                CAPopulateAircraftPage(browser, "2");
                browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_xAircraft_AddButton")).Click();

                // Add another aircraft
                browser.Link(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_xAircraftList_lnkAircraftAdd")).Click();

                CAPopulateAircraftPage(browser, "3");
                browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_xAircraft_AddButton")).Click();

                browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_StepNavigationTemplateContainerID_StepNextButton")).Click();

                GenerateCode(browser);

                CAPopulatePilotPage(browser, "1");
                browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_StepNavigationTemplateContainerID_StepNextButton")).Click();

                browser.Link(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_xPilotList_lnkPilotAdd")).Click();

                CAPopulatePilotPage(browser, "2");
                browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_xPilot_AddButton")).Click();
                browser.Link(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_xPilotList_lnkPilotAdd")).Click();

                CAPopulatePilotPage(browser, "3");
                browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_xPilot_AddButton")).Click();
                browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_StepNavigationTemplateContainerID_StepNextButton")).Click();

                // browser.Button(Find.ById("main_0_eaamain_0_eaacontent_0_acmain_1_Quote_xQuoteWizard_FinishNavigationTemplateContainerID_FinishButton")).Click();
            }
        }
Exemple #9
0
        public void UploadImage(IE ie, string filePath)
        {
            ie.Link(Find.ById("uploadImage")).Click();

            var fu = ie.FileUpload(Find.ByClass("ImageUpload"));
            fu.Set(filePath);

            ie.Button(Find.ById("ctl00_cphAdmin_btnUploadImage")).Click();
            ie.WaitForComplete();
        }
Exemple #10
0
        public void UploadVideo(IE ie, string filePath)
        {
            ie.Link(Find.ById("uploadVideo")).Click();

            var fu = ie.FileUpload(Find.ById("ctl00_cphAdmin_txtUploadVideo"));
            fu.Set(filePath);

            ie.Button(Find.ById("ctl00_cphAdmin_btnUploadVideo")).Click();
            ie.WaitForComplete();
        }
        public void Should_update_product_price_successfully()
        {
            using (var ie = new IE("http://localhost:8084/"))
            {
                ie.Link(Find.ByText("Products")).Click();

                ie.Link(Find.ByText("Edit")).Click();

                var priceField = ie.TextField(Find.ByName("Price"));

                priceField.Value = "389.99";

                ie.Button(Find.ByValue("Save")).Click();

                ie.Url.ShouldEqual("http://localhost:8084/Product");

                ie.ContainsText("389.99").ShouldBeTrue();
            }
        }
        public void Check_That_When_Logged_In_As_Admin_Then_Add_Product_Works()
        {
            var result = false;
            using (IE netWindow = new IE("http://localhost:49573/default.aspx"))
            {
                LoginAsAdmin(netWindow);

                netWindow.Link(Find.ById("ctl00_ucHeader_lnkAdminPage")).Click();
                #region hidden new way
                netWindow.Link(Find.ById(new Regex("AdminPage$")));
                #endregion

                netWindow.WaitForComplete();

                netWindow.Button(Find.ById("ctl00_ucHeader_lnkProductAdmin")).Click();
                netWindow.WaitForComplete();

                netWindow.Button(Find.ById("ctl00_ContentPlaceHolder1_RadDock1_C_btnAddProduct")).Click();
                netWindow.WaitForComplete();

                netWindow.TextField(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_txtProductName")).TypeText(String.Format("Paul Test Product {0}", DateTime.Now.Ticks.ToString()));
                netWindow.SelectList(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_ddlProductManufacturer")).SelectByValue("3");
                netWindow.SelectList(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_ddlCategoryList")).SelectByValue("2");
                netWindow.WaitForComplete(100);
                netWindow.SelectList(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_ddlSubCategoryList")).SelectByValue("2");
                netWindow.WaitForComplete();
                netWindow.Link(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_btnAddCombo")).Click();
                netWindow.WaitForComplete();
                netWindow.TextField(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_txtProductPrice")).TypeText("19.99");
                netWindow.TextField(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_txtProductModel")).TypeText("Paul Test Model 1");
                netWindow.Link(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_btnSave")).Click();

                netWindow.WaitForComplete();

                Span resultMessage = netWindow.Span(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_ucMessage_lblMessage"));
                if (resultMessage.Text == "New Product created successfuly")
                {
                    result = true;
                }
            }
            Assert.IsTrue(result);
        }
        private void LogOffAction(string username, string password)
        {
            using (var browser = new IE(BuildUrl("Login", "Index")))
            {
                CompleteLoginForm(browser, username, password);

                browser.Link("LogOff").Click();

                Assert.AreEqual(BuildBaseUrl(), browser.Url);
            }
        }
        public void RemoveItemsFromCart()
        {
            using (var browser = new IE())
            {
                browser.GoTo("http://localhost:1100/");

                browser.BringToFront();

                browser.Link(Find.ByText("Pop")).Click();

                browser.Link(Find.ByText("Frank")).Click();

                browser.Link(Find.ByText("Add to cart")).Click();

                browser.Link(Find.BySelector("a.RemoveLink")).Click();

                Assert.IsTrue(browser.ContainsText("0"));

            }
        }
        public void Home_ClickOnRockContainsRockAlbumText_True()
        {
            using (var browser = new IE("http://localhost:1100/"))
            {

                browser.BringToFront();

                browser.Link(Find.ByText("Rockssss")).Click();
                Assert.IsTrue(browser.ContainsText("Rock Albums"));

            }
        }
Exemple #16
0
 public Browser Authorize(string login, string password)
 {
     Browser browser = new IE("https://www.codeplex.com/site/login");
     
     browser.GoTo("https://www.codeplex.com/site/login");
     browser.Link("CodePlexLogin").Click();
     browser.TextField("UserName").TypeText(login);
     browser.TextField("Password").TypeText(password);
     browser.Button("loginButton").Click();
     
     return browser;
 }
        public void Should_be_able_to_edit_conference()
        {
            using (var ie = new IE("http://localhost:8084"))
            {
                var conferencesLink = ie.Link(Find.ByText("Conferences"));
                conferencesLink.Click();

                var editCodeMashLink = ie.Link(Find.ByText("Edit"));
                editCodeMashLink.Click();

                var nameBox = ie.TextField(Find.ByName("Name"));
                nameBox.TypeText("CodeMashFoo");

                var submitBtn = ie.Button(Find.ByValue("Save"));
                submitBtn.Click();

                ie.Url.ShouldEqual("http://localhost:8084/Conference");

                ie.ContainsText("CodeMashFoo").ShouldBeTrue();
            }
        }
Exemple #18
0
        void StressThread()
        {
            //Settings.WaitForCompleteTimeOut = 3600;
            //Settings.WaitUntilExistsTimeOut = 3600;
            
            using (IE ie = new IE("http://*****:*****@"C:\Users\Chris\Downloads\Firefox Setup 7.0.exe");

                //_waitEvent.WaitOne();
                ie.Link(Find.ById("uploadButton")).Click();

                while (!ie.ContainsText("Upload Result"))
                {
                    Thread.Sleep(1000);
                    //ie.WaitForComplete();
                }

                Assert.True(ie.ContainsText("Complete"));

                ie.Link(Find.ById("newUploadButton")).Click();
                ie.WaitForComplete();

                SetFileUpload(ie, "slickUpload_selector_html_file0", @"C:\Users\Chris\Downloads\SlickUpload-6.1-S3MetadataFix.zip");
                SetFileUpload(ie, "slickUpload_selector_html_file1", @"C:\Users\Chris\Downloads\MSBuild Extension Pack April 2011 (All Files) (1).zip");
                ie.Link(Find.ById("uploadButton")).Click();

                while (!ie.ContainsText("Upload Result"))
                {
                    Thread.Sleep(1000);
                    //ie.WaitForComplete();
                }

                Assert.True(ie.ContainsText("Complete"));

                //Thread.Sleep(10000);
            }
        }
Exemple #19
0
 public void TestClickNextBlog()
 {
     using (var browser = new IE("http://localhost:8888/Blog/My-New-iMac"))
     {
         var funnyDialog = new AlertDialogHandler();
         using (new UseDialogOnce(browser.DialogWatcher, funnyDialog))
         {
             browser.Link("MainContent_linkNextBlog").ClickNoWait();
             funnyDialog.WaitUntilExists();
             funnyDialog.OKButton.Click();
             Assert.IsTrue(funnyDialog.Message.Contains("I've told you I am writing:)"));
         }
         browser.WaitForComplete(3);
     }
 }
        public void Login_Successful_Should_Have_LogOut_Link()
        {
            using (var browser = new IE())
            {
                browser.GoTo("http://localhost:1100/");

                browser.BringToFront();

                browser.Link(Find.ByText("Admin")).Click();

                //browser.Element(x => x.)

                browser.TextField(Find.ById("UserName")).TypeText("administrator");

                browser.TextField(Find.ById("Password")).TypeText("password123!");

                browser.Element(Find.BySelector("input.LogOn")).Click();

                Assert.IsTrue(browser.Link(Find.ByText("Log Out")).Exists);

                browser.Link(Find.ByText("Log Out")).Click();

            }
        }
        public void UnsuccessfulAdministrationLogin()
        {
            bool result;
            using (var browser = new IE("http://localhost:1200/"))
            {
                browser.Link(Find.ByText("Admin")).Click();
                browser.TextField(Find.ById("UserName")).TypeText("admin");
                browser.TextField(Find.ById("Password")).TypeText("admin");

                browser.Element(Find.ByValue("Log On")).Click();

                result = browser.ContainsText("Login was unsuccessful.");
            }

            Assert.That(result, "Browser Url is incorrect");
        }
        public void SuccessfulAdministrationLogin()
        {
            var browserUrl = string.Empty;
            using (var browser = new IE("http://localhost:1200/"))
            {
                browser.Link(Find.ByText("Admin")).Click();
                browser.TextField(Find.ById("UserName")).TypeText("administrator");
                browser.TextField(Find.ById("Password")).TypeText("password123!");

                browser.Element(Find.ByValue("Log On")).Click();
                browser.WaitForComplete(2);

                browserUrl = browser.Url;
            }

            Assert.That(browserUrl.Contains("/StoreManager"), string.Format("Browser Url is incorrect - it is actually {0}", browserUrl));
        }
        public bool DeletePostByTitle(string title, IE ie)
        {
            ie.GoTo(Url);
            ie.WaitForComplete();

            var tblPosts = ie.Table("Posts");

            if (tblPosts != null)
            {
                foreach (var row in tblPosts.TableRows)
                {
                    if (!string.IsNullOrEmpty(row.Id) && row.InnerHtml.Contains(title))
                    {
                        ie.Link("a-" + row.Id).Click();
                        return true;
                    }
                }
            }
            return false;
        }
        public void ConfirmJavaDialogHandler()
        {
            WatiN.Core.Settings.AutoMoveMousePointerToTopLeft = false;
            WatiN.Core.Settings.MakeNewIeInstanceVisible = true;

            using (WatiN.Core.IE ie = new IE(Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")))
            {
                ie.BringToFront();
                WatiN.Core.DialogHandlers.ConfirmDialogHandler handler = new ConfirmDialogHandler();
                ie.DialogWatcher.Add(handler);

                ie.Link("linkConfirm").ClickNoWait();
                handler.WaitUntilExists(2000);

                Assert.AreEqual("Continue", handler.Message);

                handler.OKButton.Click();

            }
        }
Exemple #25
0
        public static bool IsExist(IE ie, HControl control)
        {
            try
            {
                bool existed = true;
                Regex regex = new Regex(FilterPattern.GetToPattern(control.Value));
                switch (control.Control.ToLower())
                {
                    case ControlType.AHref:
                        existed = ie.Link(Find.ByText(regex)).Exists;
                        break;
                    case ControlType.AHrefNoText:
                        try
                        {

                        }
                        catch (Exception ex)
                        {
                            existed = false;
                        }
                        break;
                    case ControlType.Button:
                        existed = ie.Button(GetControl(ie, control)).Exists;
                        break;
                    case ControlType.Div:
                        existed = ie.Div(GetControl(ie, control)).Exists;
                        break;
                    case ControlType.TextArea:
                        existed = ie.TextField(GetControl(ie, control)).Exists;
                        break;
                    case ControlType.TextBox:
                        existed = ie.TextField(GetControl(ie, control)).Exists;
                        break;
                }
                return existed;// 
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public void Check_For_Admin_Link_Present_When_Logged_In()
        {
            var result = false;
            var url = string.Empty;
            //Act
            using (IE netWindow = new IE("http://localhost:49573/default.aspx"))
            {

                LoginAsAdmin(netWindow);

                url = netWindow.Url;

                var adminLinkExists = netWindow.Link(Find.ById("ctl00_ucHeader_lnkAdminPage")).Exists;
                if (adminLinkExists)
                {
                    result = true;
                }
            }

            Assert.AreEqual("http://localhost:49573/default.aspx", url);
            Assert.IsTrue(result);
        }
        public void InteractingWithElement()
        {
            using (var browser =
                new IE("http://localhost:62727/Pages/ApplyForCreditCard.aspx"))
            {
                browser.AutoClose = false;
                browser.ShowWindow(NativeMethods.WindowShowStyle.Minimize);
                browser.ShowWindow(NativeMethods.WindowShowStyle.Maximize);

            TextField applicantName = browser.TextField(Find.ById("Name"));
            applicantName.TypeText("Jason Roberts");

            Link helpHyperlink = browser.Link(Find.ById("HelpLink"));
            helpHyperlink.Click();

            SelectList title = browser.SelectList(Find.ById("Title"));
            title.Select("Prof");
            title.SelectByValue("4");

            Button applyButton = browser.Button(Find.ById("ApplyNow"));
            applyButton.Click();

            }
        }
        private static void PasswordChange()
        {
            bool nextstage = false;

            var passwordchangeusersnames = (from u in tdc.CybersourceGatewayTranDownloadTrackings
                                            where u.ReportDate.Equals(DateTime.Parse(reportDate)) && u.isDownLoadSuccess.Value.Equals(false) && u.NewPasswordSet.Equals(null)
                                 select u);
            foreach (CybersourceGatewayTranDownloadTracking t in passwordchangeusersnames)
            {
                string merchantid = t.MerchantId ;
                string username = t.UserName;
                string password="******";
                string organizationId = t.UserName;
                string newpassword="";

                List<string> validmessage = new List<string>();
                validmessage.Add("Welcome to the CyberSource Business Center");
                validmessage.Add("The specified user name has been locked.");

                using (var browser = new IE("https://ebc.cybersource.com/ebc/login/Login.do#"))
                {

                    browser.Link(Find.ByText("change")).Click();
                    browser.TextField(Find.ByName("organizationId")).TypeText(organizationId);
                    browser.TextField(Find.ByName("username")).TypeText(username);
                    browser.TextField(Find.ByName("password")).TypeText(password);
                    browser.Button(Find.ByValue("Login")).Click();

                    if (browser.ContainsText(validmessage[0]) || browser.ContainsText(validmessage[1]) )
                    {

                        if (browser.ContainsText(validmessage[0]))
                        { newpassword = password; }
                        else if (browser.ContainsText(validmessage[1]))
                        { newpassword = "******"; }

                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet='" + newpassword + "' where MerchantId = '" + merchantid + "'");
                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                    }
                    else if (browser.ContainsText("Secret Profile Setup"))
                    {
                        if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                        {
                            browser.TextField(Find.ByName("answer")).TypeText("NCO");
                        }

                        browser.Button(Find.ByValue("Submit Request")).Click();
                        string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                        tdc.ExecuteCommand(sql);
                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                    }
                    else
                    {
                        browser.Back();
                        password = "******";
                        browser.Link(Find.ByText("change")).Click();
                        browser.TextField(Find.ByName("organizationId")).TypeText(organizationId);
                        browser.TextField(Find.ByName("username")).TypeText(username);
                        browser.TextField(Find.ByName("password")).TypeText(password);
                        browser.Button(Find.ByValue("Login")).Click();

                        if (browser.ContainsText(validmessage[0]) || browser.ContainsText(validmessage[1]))
                        {

                            if (browser.ContainsText(validmessage[0]))
                            { newpassword = password; }
                            else if (browser.ContainsText(validmessage[1]))
                            { newpassword = "******"; }

                            tdc.ExecuteCommand("update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet='" + newpassword + "' where MerchantId = '" + merchantid + "'");
                            tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        }
                        else if (browser.ContainsText("Secret Profile Setup"))
                        {
                            if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                            {
                                browser.TextField(Find.ByName("answer")).TypeText("NCO");
                            }

                            browser.Button(Find.ByValue("Submit Request")).Click();
                            string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                            tdc.ExecuteCommand(sql);
                            tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        }
                        else
                        {

                            nextstage = step1_RequestForgottenPassword(organizationId, username);

                            if (nextstage)
                                nextstage = step2_RecoverPassword(organizationId, username, ref password);

                            string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + password + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                            tdc.ExecuteCommand(sql);

                            tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        }
                    }
                }
            }
        }
		public static void Descargar(string rfc, string contrasena, string carpeta, DateTime fechaDesde, DateTime fechaHasta, TipoBusqueda busqueda)
		{
			using (IE browser = new IE())
			{
				//limpiar sesion y login 
				browser.ClearCookies();
				Thread.Sleep(1000);

				//java login
				browser.GoTo("https://portalcfdi.facturaelectronica.sat.gob.mx");
				browser.WaitForComplete();

				//entrar por contraseña
				browser.GoTo("https://cfdiau.sat.gob.mx/nidp/app/login?id=SATUPCFDiCon&sid=0&option=credential&sid=0");
				browser.TextField(Find.ByName("Ecom_User_ID")).AppendText(rfc);
				browser.TextField(Find.ByName("Ecom_Password")).AppendText(contrasena);
				browser.Button("submit").Click();

				browser.WaitForComplete();

				//ver si nos pudimos loggear
				if (browser.ContainsText("Login failed, please try again") || browser.ContainsText("La entrada no se ha completado"))
				{
					browser.Close();
					throw new Exception("Los datos de acceso son incorrectos para: " + rfc);
				}

				//seleccionar emitidas o recibidas
				if (busqueda == TipoBusqueda.Emitidas)
				{
					browser.RadioButton("ctl00_MainContent_RdoTipoBusquedaEmisor").Click();
				}
				else
				{
					browser.RadioButton("ctl00_MainContent_RdoTipoBusquedaReceptor").Click();
				}

				browser.Button("ctl00_MainContent_BtnBusqueda").Click();

				Log.Write("Tipo busqueda", Log.Information);

				//Creating the directory if it doesn't exists
				if (!System.IO.Directory.Exists(carpeta))
				{
					System.IO.Directory.CreateDirectory(carpeta);
				}

				//facturas emitidas
				if (busqueda == TipoBusqueda.Emitidas)
				{
					browser.WaitUntilContainsText("Fecha Inicial de Emisión");
					browser.RadioButton("ctl00_MainContent_RdoFechas").Click();
					Thread.Sleep(1000);

					//fecha desde
					browser.TextField("ctl00_MainContent_CldFechaInicial2_Calendario_text").Value = fechaDesde.ToString("dd/MM/yyyy");
					//hasta
					browser.TextField("ctl00_MainContent_CldFechaFinal2_Calendario_text").Value = fechaHasta.ToString("dd/MM/yyyy");
					Thread.Sleep(1000);

					//buscar muchas veces por si marca error de lentitud la pagina del sat >(
					while (true)
					{
						browser.Button("ctl00_MainContent_BtnBusqueda").Click();
						Thread.Sleep(3000);

						if (browser.ContainsText("lentitud"))
						{
							browser.Link("closeBtn").Click();
						}
						else
						{
							break;
						}
					}

					DescargarFacturasListadas(browser, carpeta);
				}
				else
				{
					DateTime mesActual = fechaDesde;
					bool primeraVez = true;

					while (mesActual < fechaHasta)
					{
						browser.WaitUntilContainsText("Fecha de Emisión");
						browser.RadioButton("ctl00_MainContent_RdoFechas").Click();
						Thread.Sleep(1000);

						//seleccionar año adecuado
						browser.SelectList("DdlAnio").SelectByValue(mesActual.Year.ToString());
						//seleccionar mes adecuado
						browser.SelectList("ctl00_MainContent_CldFecha_DdlMes").SelectByValue(mesActual.Month.ToString());

						if (mesActual.Day < 10 && primeraVez)
						{
							//seleccionar dia adecuado
							//click en buscar por que si no no jala
							
							//buscar muchas veces por si marca error de lentitud la pagina del sat >(
							while (true)
							{
								browser.Button("ctl00_MainContent_BtnBusqueda").Click();
								Thread.Sleep(3000);

								if (browser.ContainsText("lentitud"))
								{
									browser.Link("closeBtn").Click();
								}
								else
								{
									break;
								}
							}

							Thread.Sleep(1000);
							primeraVez = false;
						}

						browser.SelectList("ctl00_MainContent_CldFecha_DdlDia").SelectByValue(mesActual.Day.ToString("00"));
						Thread.Sleep(1000);

						//buscar muchas veces por si marca error de lentitud la pagina del sat >(
						while (true)
						{
							browser.Button("ctl00_MainContent_BtnBusqueda").Click();
							Thread.Sleep(3000);

							if (browser.ContainsText("lentitud"))
							{
								browser.Link("closeBtn").Click();
							}
							else
							{
								break;
							}
						}

						DescargarFacturasListadas(browser, carpeta);

						//pasar al siguiente mes
						mesActual = mesActual.AddDays(1);
					}
				}

				browser.Link("ctl00_LnkBtnCierraSesion").Click();
				Thread.Sleep(2000);
				browser.Close();
			}
		}
        private static void FirstimeLoginChangePassword()
        {
            TreasuryDataContext tdc = new TreasuryDataContext();
            List<string> defaultpassword = new List<string>() { "NCO", null, "invalid password", "Account locked", "" };
            var passwordchangeusersnames = (from u in tdc.CybersourceGatewayTranDownloadTrackings
                                            where u.ReportDate.Equals(DateTime.Parse(reportDate)) && u.isDownLoadSuccess.Value.Equals(false) && !(defaultpassword.Contains(u.NewPasswordSet))
                                            select u);

            foreach (CybersourceGatewayTranDownloadTracking t in passwordchangeusersnames)
            {

                string organizationId = t.UserName;
                string username = t.UserName;
                string password = t.NewPasswordSet;
                string newpassword = "";
                string merchantid = t.MerchantId;

                List<string> validmessage = new List<string>();
                validmessage.Add("Welcome to the CyberSource Business Center");
                validmessage.Add("The specified login credentials are incorrect");
                validmessage.Add("The specified user name has been locked.");

                using (var browser = new IE("https://ebc.cybersource.com/ebc/login/Login.do#"))
                {

                    browser.Link(Find.ByText("change")).Click();
                    browser.TextField(Find.ByName("organizationId")).TypeText(organizationId);
                    browser.TextField(Find.ByName("username")).TypeText(username);
                    browser.TextField(Find.ByName("password")).TypeText(password);
                    browser.Button(Find.ByValue("Login")).Click();

                   if (browser.ContainsText(validmessage[0]) || browser.ContainsText(validmessage[1]) || browser.ContainsText(validmessage[2]))
                    {
                        if (browser.ContainsText(validmessage[0]))
                            newpassword = password;
                        else if (browser.ContainsText(validmessage[1]))
                            newpassword = "******";
                        else
                            newpassword = "******";

                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");
                    }
                    else
                    {
                        //newpassword = "******" ;
                        //browser.TextField(Find.ByName("password")).TypeText(password);
                        //browser.TextField(Find.ByName("newPassword")).TypeText(newpassword);
                        //browser.TextField(Find.ByName("newPasswordConfirm")).TypeText(newpassword);
                        //browser.Button(Find.ByValue("Submit")).Click();

                        //if (browser.ContainsText("Secret Profile Setup"))
                        //{
                        //    if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                        //    {
                        //        browser.TextField(Find.ByName("answer")).TypeText("NCO");
                        //    }

                        //    browser.Button(Find.ByValue("Submit Request")).Click();

                        //    string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                        //    tdc.ExecuteCommand(sql);

                        //    tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        //}
                        //else
                        //{
                        //    browser.Back();
                        //    newpassword = "******";
                        //    browser.TextField(Find.ByName("password")).TypeText(password);
                        //    browser.TextField(Find.ByName("newPassword")).TypeText(newpassword);
                        //    browser.TextField(Find.ByName("newPasswordConfirm")).TypeText(newpassword);
                        //    browser.Button(Find.ByValue("Submit")).Click();

                        //    if (browser.ContainsText("Secret Profile Setup"))
                        //    {
                        //        if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                        //        {
                        //            browser.TextField(Find.ByName("answer")).TypeText("NCO");
                        //        }

                        //        browser.Button(Find.ByValue("Submit Request")).Click();

                        //        string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                        //        tdc.ExecuteCommand(sql);

                        //        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        //    }
                        //    else
                        //    {
                                //browser.Back();

                                for (int i = 12; i <= 30; i++)
                                {

                                    newpassword = "******" + i.ToString();
                                    browser.TextField(Find.ByName("password")).TypeText(password);
                                    browser.TextField(Find.ByName("newPassword")).TypeText(newpassword);
                                    browser.TextField(Find.ByName("newPasswordConfirm")).TypeText(newpassword);
                                    browser.Button(Find.ByValue("Submit")).Click();

                                    if (browser.ContainsText("Secret Profile Setup"))
                                    {
                                        if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                                        {
                                            browser.TextField(Find.ByName("answer")).TypeText("NCO");
                                        }

                                        browser.Button(Find.ByValue("Submit Request")).Click();

                                        string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                                        tdc.ExecuteCommand(sql);

                                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");
                                        break;
                                    }
                                    else if (browser.ContainsText("Your new password cannot be a previously used password."))
                                    {
                                        browser.Back();

                                    }

                                    else if (browser.ContainsText("You cannot change your password more than three times in 24 hours"))
                                    {
                                        browser.Back();
                                        browser.Back();
                                        break;

                                    }
                                //}
                            //}
                       }
                    }
               }
            }
        }
Exemple #31
0
        private static void AddPreSale(Model.ManheimEntities manheimModel, Model.Auction auctionEntity, DateTime saleDate, WC.TableCellCollection tds, string vin, WC.IE vehicleInfoIE)
        {
            var rightContent = vehicleInfoIE.Div("rightContent");

            #region Vehicle

            #region Grade
            var grade      = 0.0;
            var lastColumn = rightContent.Div(WC.Find.ByClass("lastColumn"));
            if (lastColumn.Exists)
            {
                var gradeLink = lastColumn.Link(WC.Find.ByText(new Regex("Grade")));
                if (gradeLink.Exists)
                {
                    double.TryParse(Regex.Replace(gradeLink.Text, @"[^\d.]", ""), out grade);
                }
            }
            #endregion


            var mmrElement = vehicleInfoIE.Link("mmrHover");
            int mmrPrice   = 0;
            if (mmrElement.Exists)
            {
                int.TryParse(mmrElement.Text, NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol, NumberFormatInfo.CurrentInfo, out mmrPrice);
            }
            var div   = vehicleInfoIE.Div(new Regex("vdpTab_detail-1"));
            var table = div.Tables.First();
            if (table != null)
            {
                var vehicleEntity = manheimModel.Vehicles.SingleOrDefault(v => v.VIN == vin);
                if (vehicleEntity == null)
                {
                    vehicleEntity       = SetVehicle(table);
                    vehicleEntity.Grade = grade;
                    manheimModel.Vehicles.Add(vehicleEntity);
                }
                else
                {
                    UpdateVehicle(vehicleEntity, table);
                }
                vehicleEntity.MMR = mmrPrice;
                manheimModel.SaveChanges();
                #endregion

                #region Seller
                var sellerElement = rightContent.Div(WC.Find.ByClass("firstColumn")).ElementWithTag("li", WC.Find.First());
                var sellerName    = sellerElement.Exists ? sellerElement.Text : "";
                var sellerEntity  = manheimModel.Sellers.SingleOrDefault(s => s.Name == sellerName);
                if (sellerEntity == null)
                {
                    sellerEntity = new Model.Seller()
                    {
                        Name = sellerName
                    };
                    manheimModel.Sellers.Add(sellerEntity);
                    manheimModel.SaveChanges();
                }
                #endregion

                #region PreSale
                var preSale = new Model.PreSale()
                {
                    Ln       = int.Parse(tds[0].Text.Split('-')[0]),
                    Run      = int.Parse(tds[0].Text.Split('-')[1]),
                    SaleDate = saleDate
                };
                lock (auctionEntity) {
                    preSale.Vehicle = vehicleEntity;
                    preSale.Auction = auctionEntity;
                    preSale.Seller  = sellerEntity;
                    manheimModel.PreSales.Add(preSale);
                }
                #endregion
                manheimModel.SaveChanges();
            }
        }