Last active
July 27, 2021 05:54
-
-
Save jimevans/5be30ff60509541e70e816b5d5652bb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INetwork networkInterceptor = driver.Manage().Network; | |
| NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler() | |
| { | |
| UriMatcher = (url) => url.Host == "the-internet.herokuapp.com" && url.PathAndQuery.Contains("basic_auth"), | |
| Credentials = new PasswordCredentials("admin", "admin") | |
| }; | |
| await networkInterceptor.StartMonitoring(); | |
| driver.Url = "http://the-internet.herokuapp.com/basic_auth"; | |
| string bodyText = driver.FindElement(By.CssSelector("body")).Text; | |
| if (bodyText.Contains("Not authorized")) | |
| { | |
| Console.WriteLine("Authentication Denial PASSED"); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Authentication Denial FAILED"); | |
| } | |
| networkInterceptor.AddAuthenticationHandler(handler); | |
| driver.Url = "http://the-internet.herokuapp.com/basic_auth"; | |
| string text = driver.FindElement(By.CssSelector("h3")).Text; | |
| if (text == "Basic Auth") | |
| { | |
| Console.WriteLine("Authentication PASSED"); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Authentication FAILED"); | |
| } | |
| await networkInterceptor.StopMonitoring(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is working for me.
Thanks :)