Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created March 23, 2021 15:47
Show Gist options
  • Save muditlambda/f5231941adf2c6c3f0c4703abe3bb80c to your computer and use it in GitHub Desktop.
Save muditlambda/f5231941adf2c6c3f0c4703abe3bb80c to your computer and use it in GitHub Desktop.
import com.google.common.util.concurrent.Uninterruptibles;
import com.sun.xml.messaging.saaj.util.Base64;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.v86.network.Network;
import org.openqa.selenium.devtools.v86.network.model.Headers;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import com.google.common.util.concurrent.Uninterruptibles;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Auth {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Shalini\\Downloads\\chromedriver\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
DevTools dev = driver.getDevTools();
dev.createSession();
dev.send(Network.enable(Optional.<Integer>empty(), Optional.<Integer>empty(), Optional.<Integer>empty()));
Map<String, Object> map = new HashMap<>();
map.put("Authorization", "Basic " + new String(new Base64().encode("admin:admin".getBytes())));
dev.send(Network.setExtraHTTPHeaders(new Headers(map)));
driver.navigate().to("https://the-internet.herokuapp.com/basic_auth");
Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS);
driver.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment