Unable to launch Firefox 81.0 with webdrivermanager - Testng - Java - Maven - java

I am passing mvn command with -Dbrowser=firefox never launches firefox. Below is my code to initialize browser and it works for Chrome but does not launch Firefox nor Edge. I have added webdrivermanager latest maven dependency 4.2.2 to my pom.xml. I have Firefox 81.0 and Edge 85.0 versions, respectively.
public WebDriver Init_Browser(String browser) {
strBrowser = prop.getProperty("browser");
if (strBrowser.equalsIgnoreCase("chrome")) {
System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true"); // This statement will
// remove rendering
// statements while
// page loading
WebDriverManager.chromedriver().setup();
tldriver.set(new ChromeDriver());
} else if (strBrowser.equalsIgnoreCase("ff") || (strBrowser.equalsIgnoreCase("firefox"))) {
WebDriverManager.firefoxdriver().setup();
tldriver.set(new FirefoxDriver());
} else if (strBrowser.equalsIgnoreCase("Edge")) {
WebDriverManager.edgedriver().setup();
tldriver.set(new EdgeDriver());
} else {
System.out.println("Browser not defined");
}
getDriver().manage().deleteAllCookies();
getDriver().manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
return getDriver();
}
Please help in fixing this issue. Thank you.

I was loading default browser value from properties file.
strBrowser = prop.getProperty("browser");
Instead I replaced this statement to,
String strBrowser = System.getProperties().get(browser).toString();
So the browser value coming from parameters sits in get(browser) and it will validate according to the browser requirement. Problem solved. I was able to launch firefox, edge and chrome without any issues.

Related

How to process the same step in Selenium Java using for loop for Chrome and Chrome Incognito browser?

I already have a code for this but what happens is that it opens the two browsers at the same time, failing my code to do what is intended. What I'm trying to do is the Chrome browser will execute first the process then after the first browser, the Chrome Incognito will launch and now do the same process.
I currently have this code:
chromeOptions.addArguments("--incognito");
ChromeDriver chromeIncognitoDriver = new ChromeDriver(chromeOptions);
for (ChromeDriver drivers : new ChromeDriver[] {(ChromeDriver) driver, chromeIncognitoDriver}) {
try {
chromeIncognitoDriver.manage().window().setSize(new Dimension(412, 915));
drivers.get("www.google.com");
//do process 1st for driver then after it, chromeIncognito driver will do the same process
} catch (Exception e) {
throw new IllegalStateException("Execution encountered an Error: " + e.getMessage());
} finally {
driver.close();
}
}
}
}
Your code seems to be throwing illegal argument exception at below code
drivers.get("www.google.com");
This is because driver.get() method accepts only fully qualified URL(See the attached image for reference)
Change the code to:
drivers.get("https://www.google.com");

Selenium Proxy Pop up in Java

Everything is working completely fine except this one proxy login which I can’t bypass.
Here is what I've tried to pass this:
https://{USERNAME}:{PASSWORD}#url - This still displays the same popup
driver.switchTo().alert().sendKeys(proxy.getUsername()); // Alert is never found.
driver.switchTo().activeElement().sendKeys(proxy.getUsername()); // Nothing happens
new Actions(driver).sendKeys(proxy.getUsername()).build().perform(); // Nothing is happening
Here is the code I'm using to connect to the url
public void execute(ProxyConnection proxy) {
WebDriver driver = setupDriver(proxy);
driver.get(URL);
driver.manage().window().maximize();
// Here I use test methods like shown above
}
public WebDriver setupDriver(ProxyConnection proxyConnection) {
System.setProperty("webdriver.chrome.driver", "MY PATH");
String proxyadd = proxyConnection.getHostName() + ":" + proxyConnection.getPort();
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyadd);
proxy.setSslProxy(proxyadd);
ChromeOptions options = new ChromeOptions();
options.setCapability("proxy", proxy);
if (!debugMode) {
options.addArguments("--headless");
}
return new ChromeDriver(options);
}
I'm using ChromeDriver version: 91.0.4472
I'm using selenium-chrome-driver version: 3.8.0
Any help is greatly appreciated.
Still no answer to this.
I even tried playing around with selenium and chrome versions but still no luck. I updated to BETA v4.0.0 and this didn't have any effect.
AutoIT or Robot is not suitable because it needs to be headless.
Try to use
driver.switchTo().alert().sendKeys("username");
You find more exemples in https://www.guru99.com/alert-popup-handling-selenium.html
For anyone wondering what the solution was because I was testing for hours and hours but finally found one that works...
((HasAuthentication) driver).register(UsernameAndPassword.of(ProxyData.getInstance().getUsername(), ProxyData.getInstance().getPassword()));
Note: This requires version Selenium 4.0.0 or higher.

Selenium WebDriver + Firefox which version works fine?

I am working on writing an automation script to test a website login. Through Firefox IDE, I have written TestCase steps, it is executing fine. I exported the test case as java code compatible with jUnit 4.
When i try to run the java code via Eclipse (with firefox browser), either it opens Mozilla homepage or blank page or proxy issue (if my machine is connected to company LAN).
I am using Selenium 2.44 and Firefox version 44..
Also i read in some websites saying about compatible version of firefox with selenium web driver. I am confused a lot regarding this.
Please let me know which version of Selenium Web driver, Firefox & Java is preferred..!!!
Adding my java code below
public class Firefox {
private WebDriver driver;
private String PROXY = "proxy address:port";
private String baseUrl;
private boolean acceptNextAlert = true;
#Before
public void setUp() throws Exception {
// Code for setting up Firefox proxy
Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
driver = new FirefoxDriver(cap);
baseUrl = "url";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testFirefox() throws Exception {
driver.get(baseUrl);
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try {
if ("".equals(driver.findElement(By.id("userId")).getText())) break;
}
catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("userId")).sendKeys("user name");
driver.findElement(By.id("pwd")).sendKeys("password");
driver.findElement(By.id("sign-in")).click();
}
}
Latest stable compatible configuration which i've found and I am using it is selenium Webdriver 2.48.2 and Firefox 41.0.2
Download Firefox ESR from https://www.mozilla.org/en-US/firefox/organizations/all/
Its stable version browser of Firefox compatible with Webdriver 2.48.2.
Selenium WebDriver 2.48.2 will not work with FF 44.
The latest Firefox always works with the latest version of Selenium (2.x versions) for all non-native events, such as JavascriptExecutor events, but there are some native events (such as driver.navigate.to() and driver.click() that won't work except with the last known native supported version of Firefox, which was 31.6.0 ESR. It's possible that later versions of ESR will work, but I have not read that anywhere.

Selenium WebDriver on IE11 always has "--port=" in URL

I am trying to run some automated tests on IE11 using Selenium Webdriver. Whenever I run my code the URL that IE tries to load is http://--port=38198/
I am trying to simply load Google and return the title, then I will move onto the actual automated testing I intend to do.
Here is a sample of my code so far;
private WebDriver driver;
private String baseUrl;
#Before
public void setUp() throws Exception{
System.setProperty("webdriver.ie.driver", "C:\\Program Files\\Internet Explorer\\iexplore.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
baseUrl = "http//www.google.com";
driver = new InternetExplorerDriver(cap);
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void test() throws Exception{
driver.get(baseUrl);
System.out.println(driver.getTitle());
//driver.navigate().to(baseUrl);
}
Ever time I run my code it always opens the same URL - http://--port=
From my code I can't see where I have gone wrong. I changed the security settings on IE to medium and disabled protected mode (I have tried it with protected mode turned on and still no luck). I have also downloaded and installed Microsofts IE11 web driver.
I am totally mystified by this, can someone give me any insight into this...
It seems that you are using your native Windows IE?
You have to download the IE WebDriver from https://code.google.com/p/selenium/wiki/InternetExplorerDriver and your webdriver.ie.driver property needs the path to the downloaded IEDriverServer.exe
Please try and report if that solves your problem. If not I will change my chrome WebDriver to the IE and try it myself :)

how to over come ssl certifcate error for selenium web driver in Internet Explorer

I am new to Selenium Web driver and using this with Java.
I am able to launch an application but I am getting the SSL certificate error, could anyone please let me know how to overcome this issue.
I am actually learning it and need to implement at my work, if I could overcome this will be very helpful.
I am using the following code :
public class Test1 {
private static InternetExplorerDriver driver;
#Before
public void beforeclass ()
{
System.setProperty("webdriver.ie.driver", "C:\\My Folder\\selenium-2.33.0\\IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setJavascriptEnabled(true);
driver = new InternetExplorerDriver(capabilities);
}
#Test
public void Test() throws Exception
{
driver.get("www.gmail.com");
driver.getTitle();
driver.getCurrentUrl();
System.out.println(driver.getCurrentUrl());
driver.findElement(By.name("username")).sendKeys("Admin1");
driver.findElement(By.name("password")).sendKeys("Password2");
}
#After
public void afterclass()
{
System.out.println("webdriver");
}
}
Thanks in advance.
I dont' think there is a way to properly set it. CapabilityType.ACCEPT_SSL_CERTS won't work for IE I suppose, Selenium is designed to ignore the invalid capability for the particular browser and won't throw an exception.
Here is a workaround you can click link "Continue to this website (not recommended)." to bypass it.
Try
// check if your driver is IEDriver and driver's Title contains "Certificate"
// then
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
driver.findElement(By.name("username")).sendKeys("Admin1");
driver.findElement(By.name("password")).sendKeys("Password2");
Facing the same issue i solved it adding target ssl certificates to IE trusted certificates on machine where test executes.
This solved in local dev machine and also on grid execution.(Certificates imported there)
This precentes certificate revogation warning to display on IE.
I did solve this issue by making changes in the settings.Try
Tools-> Internet options->Advanced-> Settings->under security uncheck " Warn if changing between secure and not secure mode"
and Restart your IE.

Categories

Resources