Пример #1
0
        public static BasicAccount CreateAccount(bool auto)
        {
            RapidWebDriver rwd;


            try {
                CliOutput.WriteInfo("Please wait...");
                rwd = RapidWebDriver.CreateQuick(true);
            }
            catch (Exception exception) {
                CliOutput.WriteError("Exception: {0}", exception.Message);
                //throw;
                CliOutput.WriteError("Error creating webdriver");

                return(BasicAccount.Null);
            }

            string uname, pwd, email;

            if (auto)
            {
                uname = Strings.CreateRandom(10);
                pwd   = Strings.CreateRandom(10);
                email = WebAgent.EMail.GetEmail();
            }
            else
            {
                Console.Write("Username: "******"Password: "******"Email: ");
                email = Console.ReadLine();
            }

            Console.WriteLine("\nUsername: {0}\nPassword: {1}\nEmail: {2}\n", uname, pwd, email);


            try {
                CliOutput.WriteInfo("Registering account...");
                var acc = CreateAccountInternal(rwd, uname, email, pwd);


                CliOutput.WriteInfo("Cleaning up...");
                rwd.Dispose();

                return(acc);
            }
            catch (Exception exception) {
                CliOutput.WriteError("Exception: {0}", exception.Message);
                //throw;
                CliOutput.WriteError("Error creating account");

                return(BasicAccount.Null);
            }
        }
Пример #2
0
        private static BasicAccount CreateAccountInternal(RapidWebDriver rwd,
                                                          string username = null,
                                                          string email    = null,
                                                          string password = null)
        {
            var cd = rwd.Value;

            cd.Url = BASE_URL + "user.php";

            var usernameEle = cd.FindElement(ByUsername);

            usernameEle.SendKeys(username);


            var emailEle = cd.FindElement(ByEmail);

            emailEle.SendKeys(email);


            var pwdEle = cd.FindElement(ByPassword);

            pwdEle.SendKeys(password);


            var pwd2Ele = cd.FindElement(ByPasswordConfirmation);

            pwd2Ele.SendKeys(password);

            var regEle = cd.FindElement(ByRegister);

            regEle.Click();

            var body     = cd.FindElement(ByBody);
            var response = body.Text;

            Thread.Sleep(TimeSpan.FromSeconds(5));

            if (cd.Url != ACC_OV_URL || !response.Contains("welcome"))
            {
                CliOutput.WriteError("Error registering: {0} (body: {1})", cd.Url, response);
                return(BasicAccount.Null);
            }

            CliOutput.WriteSuccess("Success!");

            // https://saucenao.com/user.php?page=search-api

            cd.Url = ACC_API_URL;

            var apiEle  = cd.FindElement(ByApiKey);
            var apiText = apiEle.Text.Split(' ')[2];

            return(new BasicAccount(username, password, email, apiText));
        }