/// <summary>
        /// Executes the code to test retrieval of HTTP status codes from the browser.
        /// </summary>
        /// <param name="driver">The driver to use with the browser.</param>
        private static void TestStatusCodes(IWebDriver driver)
        {
            // Using Dave Haeffner's the-internet project http://github.com/arrgyle/the-internet,
            // which provides pages that return various HTTP status codes.
            string url = "http://the-internet.herokuapp.com/redirect";

            Console.WriteLine("Navigating to {0}", url);
            int responseCode = driver.NavigateTo(url);

            Console.WriteLine("Navigation to {0} returned response code {1}", url, responseCode);

            // Demonstrates navigating to a 404 page.
            url = "http://the-internet.herokuapp.com/redirector";
            Console.WriteLine("Navigating to {0}", url);
            responseCode = driver.NavigateTo(url);
            Console.WriteLine("Navigation to {0} returned response code {1}", url, responseCode);
            string elementId = "redirect";

            Console.WriteLine("Clicking on element with ID {0}", elementId);
            IWebElement element = driver.FindElement(By.Id(elementId));

            responseCode = element.ClickNavigate();
            Console.WriteLine("Element click returned response code {0}", responseCode);

            // Demonstrates navigating to a 404 page.
            url = "http://the-internet.herokuapp.com/status_codes/404";
            Console.WriteLine("Navigating to {0}", url);
            responseCode = driver.NavigateTo(url);
            Console.WriteLine("Navigation to {0} returned response code {1}", url, responseCode);
        }
Example #2
0
        public static async Task <string> SetupNexusLogin(IWebDriver browser, Action <string> updateStatus, CancellationToken cancel)
        {
            updateStatus("Please log into the Nexus");
            await browser.NavigateTo(new Uri("https://users.nexusmods.com/auth/continue?client_id=nexus&redirect_uri=https://www.nexusmods.com/oauth/callback&response_type=code&referrer=//www.nexusmods.com"));

            while (true)
            {
                var cookies = await browser.GetCookies("nexusmods.com");

                if (cookies.Any(c => c.Name == "member_id"))
                {
                    break;
                }
                cancel.ThrowIfCancellationRequested();
                await Task.Delay(500, cancel);
            }

            // open a web socket to receive the api key
            var guid = Guid.NewGuid();

            using (var websocket = new WebSocket("wss://sso.nexusmods.com")
            {
                SslConfiguration =
                {
                    EnabledSslProtocols = SslProtocols.Tls12
                }
            })
            {
                updateStatus("Please authorize Wabbajack to download Nexus mods");
                var api_key = new TaskCompletionSource <string>();
                websocket.OnMessage += (sender, msg) => { api_key.SetResult(msg.Data); };

                websocket.Connect();
                websocket.Send("{\"id\": \"" + guid + "\", \"appid\": \"" + Consts.AppName + "\"}");
                await Task.Delay(1000, cancel);

                // open a web browser to get user permission
                await browser.NavigateTo(new Uri($"https://www.nexusmods.com/sso?id={guid}&application={Consts.AppName}"));

                using (cancel.Register(() =>
                {
                    api_key.SetCanceled();
                }))
                {
                    return(await api_key.Task);
                }
            }
        }
Example #3
0
        private void _I_open_Challenge_page()
        {
            _driver.NavigateTo(_url);
            string title = _driver.Title;

            Assert.AreEqual("React App", title);
        }
        /// <summary>
        /// Executes the code to test collection of JavaScript errors on the page.
        /// </summary>
        /// <param name="driver">The driver to use with the browser.</param>
        private static void TestJavaScriptErrors(IWebDriver driver)
        {
            // Using Dave Haeffner's the-internet project http://github.com/arrgyle/the-internet,
            // which provides pages that return various HTTP status codes.
            string url = "http://the-internet.herokuapp.com/javascript_error";

            Console.WriteLine("Navigating to {0}", url);
            driver.NavigateTo(url);
            IList <string> javaScriptErrors = driver.GetJavaScriptErrors();

            if (javaScriptErrors == null)
            {
                Console.WriteLine("Could not access JavaScript errors collection. This is a catastrophic failure.");
            }
            else
            {
                if (javaScriptErrors.Count > 0)
                {
                    Console.WriteLine("Found the following JavaScript errors on the page:");
                    foreach (string javaScriptError in javaScriptErrors)
                    {
                        Console.WriteLine(javaScriptError);
                    }
                }
                else
                {
                    Console.WriteLine("No JavaScript errors found on the page.");
                }
            }
        }
Example #5
0
        public static T NavigateToPage <T>(this IWebDriver webDriver)
            where T : BasePage, new()
        {
            T page = new T();

            webDriver.NavigateTo(page.RelativePath);
            webDriver.InitializePage(page);
            return(page);
        }
Example #6
0
        public void Setup()
        {
            var           url     = TestContext.Parameters["webAppUrl"];
            ChromeOptions options = new ChromeOptions();

            options.AddArguments("ignore-certificate-errors", "no-sandbox", "--test-type", "--incognito");

            _driver = new ChromeDriver(options);
            _driver.NavigateTo(url);
        }
Example #7
0
        /// <summary>
        /// Navigates to page.
        /// </summary>
        /// <typeparam name="T">The Type</typeparam>
        /// <param name="webDriver">The web driver.</param>
        /// <returns>The Result</returns>
        public static T NavigateToPage <T>(this IWebDriver webDriver)
            where T : BasePage, new()
        {
            IJavaScriptExecutor js = (IJavaScriptExecutor)webDriver;
            T page = new T();

            webDriver.NavigateTo(page.RelativePath);
            webDriver.InitElements(page);

            Assert.AreEqual(true, js.ExecuteScript("return document.readyState").ToString().Equals("complete"));

            return(page);
        }
Example #8
0
        public async Task <Helpers.Cookie[]> GetAndCacheCookies(IWebDriver browser, Action <string> updateStatus, CancellationToken cancel)
        {
            updateStatus($"Please Log Into {SiteName}");
            await browser.NavigateTo(_loginUri);

            var cookies = new Helpers.Cookie[0];

            while (true)
            {
                cancel.ThrowIfCancellationRequested();
                await WhileWaiting(browser);

                cookies = (await browser.GetCookies(_cookieDomain));
                if (cookies.FirstOrDefault(c => c.Name == _cookieName) != null)
                {
                    break;
                }
                await Task.Delay(500, cancel);
            }

            cookies.ToEcryptedJson(_encryptedKeyName);

            return(cookies);
        }
Example #9
0
        public static async Task <string> SetupNexusLogin(IWebDriver browser, Action <string> updateStatus, CancellationToken cancel)
        {
            updateStatus("Please log into the Nexus");
            await browser.NavigateTo(new Uri("https://users.nexusmods.com/auth/continue?client_id=nexus&redirect_uri=https://www.nexusmods.com/oauth/callback&response_type=code&referrer=//www.nexusmods.com"));

            while (true)
            {
                var cookies = await browser.GetCookies("nexusmods.com");

                if (cookies.Any(c => c.Name == "member_id"))
                {
                    break;
                }
                cancel.ThrowIfCancellationRequested();
                await Task.Delay(500, cancel);
            }


            await browser.NavigateTo(new Uri("https://www.nexusmods.com/users/myaccount?tab=api"));

            updateStatus("Looking for API Key");


            var apiKey = new TaskCompletionSource <string>();

            while (true)
            {
                var key = "";
                try
                {
                    key = await browser.EvaluateJavaScript(
                        "document.querySelector(\"input[value=wabbajack]\").parentElement.parentElement.querySelector(\"textarea.application-key\").innerHTML");
                }
                catch (Exception)
                {
                    // ignored
                }

                if (!string.IsNullOrEmpty(key))
                {
                    return(key);
                }

                try
                {
                    await browser.EvaluateJavaScript(
                        "var found = document.querySelector(\"input[value=wabbajack]\").parentElement.parentElement.querySelector(\"form button[type=submit]\");" +
                        "found.onclick= function() {return true;};" +
                        "found.class = \" \"; " +
                        "found.click();" +
                        "found.remove(); found = undefined;"
                        );

                    updateStatus("Generating API Key, Please Wait...");
                }
                catch (Exception)
                {
                    // ignored
                }

                cancel.ThrowIfCancellationRequested();
                await Task.Delay(500);
            }
        }
Example #10
0
 public void NavigateTo(string windowNameOrUri)
 {
     Browser.NavigateTo(windowNameOrUri);
 }
Example #11
0
 public virtual void NavigateTo()
 {
     _webDriver.NavigateTo(Url, _seleniumConfig.BaseUrl);
 }
Example #12
0
 public void NavigateTo(string url)
 {
     _webDriver.NavigateTo(new Uri(url, UriKind.RelativeOrAbsolute), _config.BaseUrl);
 }
 /// <summary>
 /// Executes the code to test collection of JavaScript errors on the page.
 /// </summary>
 /// <param name="driver">The driver to use with the browser.</param>
 private static void TestJavaScriptErrors(IWebDriver driver)
 {
     // Using Dave Haeffner's the-internet project http://github.com/arrgyle/the-internet,
     // which provides pages that return various HTTP status codes.
     string url = "http://the-internet.herokuapp.com/javascript_error";
     Console.WriteLine("Navigating to {0}", url);
     driver.NavigateTo(url);
     IList<string> javaScriptErrors = driver.GetJavaScriptErrors();
     if (javaScriptErrors == null)
     {
         Console.WriteLine("Could not access JavaScript errors collection. This is a catastrophic failure.");
     }
     else
     {
         if (javaScriptErrors.Count > 0)
         {
             Console.WriteLine("Found the following JavaScript errors on the page:");
             foreach (string javaScriptError in javaScriptErrors)
             {
                 Console.WriteLine(javaScriptError);
             }
         }
         else
         {
             Console.WriteLine("No JavaScript errors found on the page.");
         }
     }
 }
Example #14
0
        /// <summary>
        /// Navigates to relative path.
        /// </summary>
        /// <param name="webDriver">The web driver.</param>
        /// <param name="relativePath">The relative path.</param>
        public static void NavigateTo(this IWebDriver webDriver, string relativePath)
        {
            Uri pageUri = Utility.GetUri(relativePath);

            webDriver.NavigateTo(pageUri);
        }
        /// <summary>
        /// Executes the code to test retrieval of HTTP status codes from the browser.
        /// </summary>
        /// <param name="driver">The driver to use with the browser.</param>
        private static void TestStatusCodes(IWebDriver driver)
        {
            // Using Dave Haeffner's the-internet project http://github.com/arrgyle/the-internet,
            // which provides pages that return various HTTP status codes.
            string url = "http://the-internet.herokuapp.com/redirect";
            Console.WriteLine("Navigating to {0}", url);
            int responseCode = driver.NavigateTo(url);
            Console.WriteLine("Navigation to {0} returned response code {1}", url, responseCode);

            // Demonstrates navigating to a 404 page.
            url = "http://the-internet.herokuapp.com/redirector";
            Console.WriteLine("Navigating to {0}", url);
            responseCode = driver.NavigateTo(url);
            Console.WriteLine("Navigation to {0} returned response code {1}", url, responseCode);
            string elementId = "redirect";
            Console.WriteLine("Clicking on element with ID {0}", elementId);
            IWebElement element = driver.FindElement(By.Id(elementId));
            responseCode = element.ClickNavigate();
            Console.WriteLine("Element click returned response code {0}", responseCode);

            // Demonstrates navigating to a 404 page.
            url = "http://the-internet.herokuapp.com/status_codes/404";
            Console.WriteLine("Navigating to {0}", url);
            responseCode = driver.NavigateTo(url);
            Console.WriteLine("Navigation to {0} returned response code {1}", url, responseCode);
        }