My Auth functionality is working great in chrome but as Firefox handle it differently I am not able to login the auth by anyway.
My Firefox version : 72.02
I have found that it is known bug but they are 1 year old post, if anyone has solution kindly share
https://bugzilla.mozilla.org/show_bug.cgi?id=1556026
https://bugzilla.mozilla.org/show_bug.cgi?id=1556307
Normal code will not work as below as I need to add token to url runtime as similar shown in chrome but not in Firefox
driver.get("https://your-username:your-password@example.com");
So I need to do some sendKeys in this case which is failing for me
I am getting error as :
Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: User prompt of type promptUserAndPass is not supported Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: '', ip: '', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_66' Driver info: org.openqa.selenium.firefox.FirefoxDriver
Code I am trying:
public static void main(String[] args) throws InterruptedException, AWTException {
/* BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);*/
// put our custom header to each request
/* proxy.addRequestFilter((request, contents, messageInfo)->{
request.headers().add("my-test-header", "my-test-value");
System.out.println(request.headers().entries().toString());
return null;
});*/
// Setting up Proxy for chrome
// ChromeOptions opts = new ChromeOptions();
WebDriver driver = null;
String url = "https://qa.xyz-domain/new-request/";
String UserName = "xyzuser";
String Password = "xyz@202";
System.setProperty("webdriver.gecko.driver",
"D:\\Demoproject\\src\\main\\resources\\drivers\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setCapability("network.http.phishy-userpass-length", 255);
options.setCapability("network.automatic-ntlm-auth.trusted-uris","testcloud");
// options.setp
// options.setCapability(CapabilityType.);
String val=UserName+":"+Password;
String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString(val.getBytes()));
options.setCapability("Authorization",encodedCreadentials);
// String proxyOption = "--proxy-server=" + seleniumProxy.getHttpProxy();
// options.addArguments(proxyOption);
// options.addArguments(arguments)
driver = new FirefoxDriver(options);
driver.get(url);
Thread.sleep(5000);
driver.findElement(By.name("loginfmt")).sendKeys("user.name@xyz.com");
driver.findElement(By.name("loginfmt")).sendKeys(Keys.ENTER);
Thread.sleep(15000);
driver.switchTo().alert().sendKeys(UserName);
/*BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
browserMobProxy.addHeader("Authorization", encodedCreadentials);
browserMobProxy.start();*/
//ProxyServer bmp = new ProxyServer(4444);
/* Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
driver.switchTo().alert().sendKeys(UserName);*/
/* Alert alert = driver.switchTo().alert();
System.out.println(alert.getText());
if (alert.getText().contains("jjjj")) {*/
// alert.sendKeys("UserName");
//driver.switchTo().alert().dismiss();;
//driver.switchTo().alert().sendKeys(UserName + Keys.TAB + Password);
//alert.sendKeys(UserName + Keys.TAB + Password);
/*String url2 = driver.getCurrentUrl().replaceAll("https://", "");
System.out.println("url2 = " + url2);
String url3 = "https://" + UserName + ":" + Password + "@" + url2 + "/";
System.out.println("url3 = " + url3);
driver.get(url3);
//driver.switchTo().alert().sendKeys(UserName + Keys.TAB + Password);
//driver.switchTo().alert().accept();
String url2 = driver.getCurrentUrl().replaceAll("https://", "");
System.out.println("url2 = " + url2);
String url3 = "https://" + UserName + ":" + Password + "@" + url2 + "/";
System.out.println("url3 = " + url3);
driver.get(url3);*/
/*} else {
System.out.println("not appearing");
}*/
}
}
I tried to use BrowserMobProxy but I believe it works with http request only I guess and for https har required, let me know if there is issue with my understanding. or we can use it anyway for https
refer: