private void LogIn(IE browser)
        {
            if (browser.Links.Count(link => link.Title == "Log back into your account") > 0)
            {
                // Just been logged out. Need to press the above link
                browser.Link(Find.ByTitle("Log back into your account")).Click();
            }
            else
            {
                browser.Link(Find.ByTitle("Sign in ")).Click();
            }

            if (browser.Links.Count(link => link.Title == "Log back into your account") > 0)
            {
                // Just been logged out. Need to press the above link
                browser.Link(Find.ByTitle("Log back into your account")).Click();
            }

            browser.TextField(Find.ById("frmLogin:strCustomerLogin_userID")).Value = Config.UserId;
            browser.TextField(Find.ById("frmLogin:strCustomerLogin_pwd")).Value    = Config.Password;
            browser.Form(Find.ByName("frmLogin")).Submit();

            LloydsGroupHelpers.FillLloydsGroupMemorableInformation(browser, Config);
            browser.Element(Find.ByName("frmentermemorableinformation1:btnContinue")).Click();
        }
        public void RequestContacts()
        {
            // this test does a full end-to-end integration (request token, user authoriazation, exchanging request token
            // for an access token and then using then access token to retrieve some data).

            // the access token is directly associated with a google user, by them logging in and granting access
            // for your request - thus the client is never exposed to the users credentials (not even their login).

            IOAuthSession consumer = CreateGoogleContactsSession();

            using (With.NoCertificateValidation())
            {
                IToken requestToken = consumer.GetRequestToken();

                string userAuthorize = consumer.GetUserAuthorizationUrlForToken(requestToken, null);

                string verificationCode;

                using (var ie = new IE(userAuthorize))
                {
                    Link overrideLink = ie.Link("overridelink");
                    if (overrideLink.Exists)
                    {
                        overrideLink.Click();
                    }

                    if (ie.Form("gaia_loginform").Exists)
                    {
                        ie.TextField("Email").Value  = "*****@*****.**";
                        ie.TextField("Passwd").Value = "oauth_password";
                        ie.Form("gaia_loginform").Submit();
                    }

                    ie.Button("allow").Click();

                    string html = ie.Html;

                    Assert.IsTrue(html.Contains("Authorized") || html.Contains("successfully granted"));

                    int index = html.IndexOf("verification code:");

                    Assert.IsTrue(index > 0);

                    int startIndex = html.IndexOf("<B>", index, StringComparison.InvariantCultureIgnoreCase);
                    int endIndex   = html.IndexOf("</B>", startIndex + 1, StringComparison.InvariantCultureIgnoreCase);

                    verificationCode = html.Substring(startIndex + 3, endIndex - (startIndex + 3));
                }

                // this will implicitly set AccessToken on the current session...

                IToken accessToken = consumer.ExchangeRequestTokenForAccessToken(requestToken, verificationCode);

                try
                {
                    string responseText = consumer.Request().Get().ForUrl("https://www.google.com/m8/feeds/contacts/default/base").ToString();

                    Assert.IsTrue(responseText.Contains("*****@*****.**"));
                }
                catch (WebException webEx)
                {
                    var response = (HttpWebResponse)webEx.Response;
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        Console.WriteLine(reader.ReadToEnd());
                    }
                    Assert.Fail();
                }
            }
        }