Example #1
0
        /// <summary>
        /// Loads a page state
        /// </summary>
        /// <param name="state">The state to load</param>
        /// <returns>The current step we are on</returns>
        public int LoadState(PageState state)
        {
            Driver.Manage().Cookies.DeleteAllCookies();

            if (state == null)
            {
                return 0;
            }

            foreach (var cookie in state.Cookies)
            {
                Driver.Manage().Cookies.AddCookie(cookie);
            }

            Driver.Navigate().GoToUrl(state.Url);

            return state.Step;
        }
Example #2
0
        /// <summary>
        /// Logs into the bank with the current credentials
        /// </summary>
        /// <param name="creds">The credentials to use</param>
        /// <param name="state">The state to load from, null to start at the beginning</param>
        public override void Login(Credentials creds, PageState state = null)
        {
            try
            {
                var step = LoadState(state);

                switch (step)
                {
                    case 0:
                        Driver.Navigate().GoToUrl("https://www.usaa.com");

                        if (string.IsNullOrEmpty(creds.UserName))
                        {
                            RequireUserName?.Invoke();
                            SaveState(1);
                            break;
                        }
                        goto case 1;
                    case 1:

                        if (string.IsNullOrEmpty(creds.Password))
                        {
                            RequirePassword?.Invoke();
                            SaveState(2);
                            break;
                        }
                        goto case 2;
                    case 2:
                        var user = Driver.FindElement(By.Id("usaaNum"));
                        var pass = Driver.FindElement(By.Id("usaaPass"));
                        var login = Driver.FindElement(By.Id("login"));

                        user.SendKeys(creds.UserName);
                        pass.SendKeys(creds.Password);
                        login.Click();

                        if (string.IsNullOrEmpty(creds.Pin))
                        {
                            RequirePin?.Invoke();
                            SaveState(3);
                            break;
                        }
                        goto case 3;
                    case 3:
                        var pin = Driver.FindElement(By.Id("id3"));
                        var next = Driver.FindElement(By.Id("idf"));
                        pin.SendKeys(creds.Pin);
                        next.Click();
                        var question = Driver.FindElement(By.CssSelector("label[for='id3']")).Text;

                        while (question.ToLower() == "pin")
                        {
                            Thread.Sleep(100);
                            question = Driver.FindElement(By.CssSelector("label[for='id3']")).Text;
                        }

                        if (string.IsNullOrEmpty(creds.Question))
                        {
                            RequireQuestion?.Invoke(question);
                            SaveState(4);
                            break;
                        }
                        goto case 4;
                    case 4:
                        var answer = Driver.FindElement(By.Id("id3"));
                        var submit = Driver.FindElement(By.Id("id10"));
                        answer.SendKeys(creds.Question);
                        submit.Click();
                        goto case 5;
                    case 5:
                        LoginComplete?.Invoke();
                        Driver.Close();
                        break;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                LoginFailed?.Invoke();
            }
        }
Example #3
0
 /// <summary>
 /// Logs into the bank with the current credentials
 /// </summary>
 /// <param name="creds">The credentials to use</param>
 /// <param name="state">The state to load from, null to start at the beginning</param>
 public abstract void Login(Credentials creds, PageState state = null);
Example #4
0
        /// <summary>
        /// Saves the current browser state for loading in the future
        /// </summary>
        /// <param name="step">The current step we are on when we save state</param>
        /// <returns>The page state</returns>
        public PageState SaveState(int step)
        {
            var cookies = Driver.Manage().Cookies.AllCookies;
            var page = Driver.Url;

            var state = new PageState() {Cookies = cookies, Url = page, Step = step};
            return state;
        }