Skip to content

Instantly share code, notes, and snippets.

@jimevans
Last active July 27, 2021 05:54
Show Gist options
  • Select an option

  • Save jimevans/5be30ff60509541e70e816b5d5652bb9 to your computer and use it in GitHub Desktop.

Select an option

Save jimevans/5be30ff60509541e70e816b5d5652bb9 to your computer and use it in GitHub Desktop.
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();
@HimanshuManchanda78
Copy link
Copy Markdown

HimanshuManchanda78 commented Jul 23, 2021

It is working for me.
Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment