Issue : When I run browser launch code then getting below error:
Env : Windows
Java 1.8
Selenium 3.141.59
Browser - Chrome 94 ( Correct crome driver used)
#Test
public void test() {
System.setProperty("webdriver.chrome.driver", "resources\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--enable-automation");
options.addArguments("--no-sandbox");
options.addArguments("--disable-extensions");
options.addArguments("--dns-prefetch-disable");
options.addArguments("--disable-gpu");
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://test.com");
driver.manage().window().maximize();
System.out.println("Loading the application url");
}
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
java.lang.NoClassDefFoundError: okio/Sink
at okhttp3.RealCall.getResponse(RealCall.java:229)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
at okhttp3.RealCall.execute(RealCall.java:57)
at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:105)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
at Base.BrowserLaunch.test(BrowserLaunch.java:34)
Please let me know if any other details required.
I've faced the same issue some time ago. I have used this code and hope it will help you as well.
Properties p=Someutility.getTestConfig();
System.setProperty("webdriver.chrome.driver", p.getProperty("driverPath"));
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.navigate().to(p.getProperty("navigationUrl"));
driver.manage().window().maximize();
Where getTestConfig() is the method where I get the properties file for use like to get the driverPath and navigationUrl.
Where navigationUrl is the url where my application is running.
Here is the getTestConfig() method for reference.
public static Properties getTestConfig() throws IOException, InterruptedException {
FileReader reader = new FileReader("pathoffile/somefile.properties");
Properties p = new Properties();
p.load(reader);
return p;
}
Related
My below code is giving expected result to hit chrome browser with the url and maximize the window.But after that it should go my my test scripts where is have login page and it is doing nothing over there
Please suggest
#BeforeClass
public void beforeClass() {
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\NCRExecutableWorkSpace\\automation-ncr\\Drivers\\chromedriver.exe");
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", map);
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("https://google.com");
I am trying to launch Microsoft Edge Chromium browser using selenium.
Microsoft Edge chromium Version: Version 79.0.309.65 (Official Build) (64-bit)
Downloading driver file from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Using this code to for the same but it is giving unreachable browser Exception and not working.
1.System.setProperty("webdriver.edge.driver", "C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedgedriver.exe");
EdgeOptions options = new EdgeOptions();
BROWSER=properties.getProperty("BrowserName");
options.setCapability(BROWSER, false);
//DesiredCapabilities m_capability = DesiredCapabilities.edge();
driver= new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
2.DesiredCapabilities m_capability = DesiredCapabilities.chrome();
BROWSER=properties.getProperty("BrowserName");`enter code here`
m_capability.setCapability( BROWSER, "chrome" );
driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver",
"C:\\edgedriver_win64-1\\msedgedriver.exe");
It is looking like compatibility issue. You can upgrade or downgrade your msedgedriver driver version to make it work.
I will recommend you to use WebDriverManager
WebDriverManager allows to automate the management of the binary
drivers (e.g. chromedriver, geckodriver, etc.) required by Selenium
WebDriver.
maven dependency
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
Once we have included this dependency, you can let WebDriverManager to manage the WebDriver binaries for you. Now you can set driver instance for Edge.
public class EdgeDevTest {
private WebDriver driver;
#BeforeClass
public static void setupClass() {
WebDriverManager.edgedriver().setup();
}
#Before
public void setupTest() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(
"C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");
EdgeOptions edgeOptions = new EdgeOptions().merge(chromeOptions);
driver = new EdgeDriver(edgeOptions);
}
#After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
public void testservice(){
EdgeOptions opt= new EdgeOptions();
opt.setHeadless();
WebDriver driver= new EdgeDriver(opt);
}
I am trying to run test a run a website in Firefox, but I am getting error "The path to the driver executable must be set by the webdriver.gecko.driver system property;" I have set the path correctly, still don't know where the problem is. Here is my code:
if (browsers.equalsIgnoreCase("Firefox"))
{
String driverPath = System.getProperty("user.dir") + "\\src/test/java\\drivers\\geckodriver.exe";
System.setProperty("webdriver.firefox.marionette", "false");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} else if (browsers.equalsIgnoreCase("Chrome")) {
// String driverPath = System.getProperty("user.dir") +
// "\\src\\Drivers\\chromedriver";
// System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
Here is the Failure Trace of my code:
FAILED CONFIGURATION: #BeforeClass launchBrowser
org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities
Build info: version: '3.8.0', revision: '924c4067df', time: '2017-11-30T11:36:59.109Z'
System info: host: 'DSCHD-PC-180', ip: '192.168.6.122', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'
Driver info: driver.version: FirefoxDriver
remote stacktrace:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at Utility.UtilityMethods.openBrowser(UtilityMethods.java:26)
at TestCases.LoginTestCase.launchBrowser(LoginTestCase.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
SKIPPED CONFIGURATION: #AfterClass quitBrowser
SKIPPED: registration
To keep things simple, as you are using Selenium Client v3.11.0 and Firefox v37 you need to download the latest GeckoDriver from mozilla/geckodriver and save it any where within your system. Next within the System.setProperty() line pass the Key webdriver.gecko.driver along with the Value as the absolute path of the GeckoDriver and finally through DesiredCapabilities class set the capability marionatte to false and merge into an instance of FirefoxOptions instance to initiate the Firefox browser as follows :
System.setProperty("webdriver.gecko.driver", "C:/path/to/geckodriver.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
FirefoxDriver driver = new FirefoxDriver(opt);
driver.get("https://stackoverflow.com");
System.out.println("Application opened");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
Update
As per your comment update you are using GeckoDriver v0.20.1.
But if you look back at the Release Notes of GeckoDriver v0.18.0 it clearly mentions :
geckodriver now recommends Firefox 53 and greater
So using GeckoDriver v0.18.0 and above you have to mandatory use Firefox 53 and greater. To get rid of this constraint you can downgrade either to any of these versions :
GeckoDriver v0.17.0
GeckoDriver v0.16.1
This is how system property is set:
System.setProperty("webdriver.gecko.driver", "C:\\...\\geckodriver.exe");
I had this error for 2 days, the solution for me was in Set.Platform, put Platform.ANY or Platform.Windows because Platform.WIN10 not worked, marionette wasn't necessary.
public class Main { public static RemoteWebDriver driver;
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "D:/Lib/geckodriver.exe");
DesiredCapabilities desiredCapabilities = new
DesiredCapabilities().firefox();
desiredCapabilities.setPlatform(Platform.ANY);
desiredCapabilities.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://172.20.19.182:5557/wd/hub"),
desiredCapabilities);
driver.navigate().to("http://www.google.com");
driver.findElementByName("q").sendKeys("execute automation");
driver.findElementByName("q").sendKeys(Keys.ENTER);
driver.close();
// write your code here
}
you are using user.dir that basically means : current working directory
Here is the code that let you initialize firefox browser using selenium.
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\your\\gecko\\driver\\path\\geckodriver.exe");
driver = new firefoxDriver();
That's it ! you can use Firefox driver to performs several operations like :
1. driver.get(String args0);
2. driver.getCurrentUrl();
3. driver.getPageSource();
4. driver.getTitle();
5. driver.findElememt(By args0);
6. driver.findElements(By args0);
7. driver.naviagate();
8. driver.manage();
9. driver.close();
10. driver.quit();
11. driver.switchTo();
12. driver.getWindowHandle();
13. driver.getWindowHandles();
Please let me know if you have any concerns related to this.
Just updated your code. You will have to set driver path while setProperty and user webdriver.gecko.driver for latest firefox driver.
if (browsers.equalsIgnoreCase("Firefox")) {
String driverPath = System.getProperty("user.dir") + "\\src\\test\\java\\drivers\\geckodriver.exe";
System.setProperty("webdriver.firefox.driver", "driverPath");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("marionette", false);
FirefoxOptions options = new FirefoxOptions();
options.merge(capabilities);
FirefoxDriver driver = new FirefoxDriver(options);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
else if (browsers.equalsIgnoreCase("Chrome")) {
// String driverPath = System.getProperty("user.dir") +
// "\\src\\Drivers\\chromedriver";
// System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
Let me know.
I need to get headless chrome to ignore certificate errors. The option is ignored when running in headless mode, and the driver returns empty html body tags when navigating to an https resource.
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>
This is how I am configuring my chrome driver.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors");
DesiredCapabilities cap=DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
chromeHeadlessDriver = new ChromeDriver(cap);
This thread confirms that --ignore-certificate-errors is ignored in headless mode.
They mention about devtool protocol.
Is it something I can invoke from java? Are there any other alternatives?
There is an excellent article on medium.com by sahajamit
and i have tested the below code, it works perfectly fine with self-signed certificate https://badssl.com/
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("--headless", "--window-size=1920,1200","--ignore-certificate-errors");
DesiredCapabilities crcapabilities = DesiredCapabilities.chrome();
crcapabilities.setCapability(ChromeOptions.CAPABILITY, options);
crcapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
crcapabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "C:\\temp\\chrome\\chromedriver.log");
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "C:\\temp\\chrome\\chromedriver.exe");
ChromeDriverService service = null;
try {
service = new ChromeDriverService.Builder()
.usingAnyFreePort()
.withVerbose(true)
.build();
service.start();
} catch (IOException e) {
e.printStackTrace();
}
RemoteWebDriver driver = new RemoteWebDriver(service.getUrl(),crcapabilities);
driver.get("https://self-signed.badssl.com/");
System.out.println(driver.getPageSource());
driver.quit();
software/framework versions
Google Chrome Version 64.0.3282.186
Google Chrome Driver Version 64.0.3282.186
Selenium version 3.11.0
This works for me on ChromeDriver 80.
ChromeOptions option = new ChromeOptions();
option.AddArgument("--headless");
option.AcceptInsecureCertificates = true;
driver = new ChromeDriver(option);
#amila-kumara is working but, usage of DesiredCapabilities.chrome() gives warning to use ChromeOptions. Please see the updated answer.
Set the chrome option values
System.setProperty("webdriver.chrome.driver", Config.NDAC_WEBDRIVER_PATH);
ChromeOptions options = new ChromeOptions();
options.addArguments("--window-size=1920,1200");
options.setAcceptInsecureCerts(true);
options.setHeadless(true);
Start the service
ChromeDriverService service = null;
try {
service = new ChromeDriverService.Builder()
.usingAnyFreePort()
.withVerbose(true)
.build();
service.start();
remoteWebdriverUrl = service.getUrl();
System.out.println("Starting the url " + remoteWebdriverUrl);
} catch (IOException e) {
e.printStackTrace();
}
Note: I was facing the issue while closing the driver(with RemoteWebDriver), chromedriver.exe process won't close even when you use driver.quit(). To fix the issue use ChromeDriver instead of RemoteWebDriver
RemoteWebDriver driver = new ChromeDriver(service, options);
To properly close the driver, use
driver.close();
driver.quit();
Not able to capture screen shots for electron application using java .
Here is my code for webdriver setup.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("/Applications/betlite.app/Contents/MacOS/appname");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
driver = new ChromeDriver(capabilities);
Using following method to capture screen , it do work for traditional ChromeDriver .
public static void captureScreenMethod() throws IOException, InterruptedException
{
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
Thread.sleep(4000);
FileUtils.copyFile(scrFile, new File("path_of_file/screenshot.png"));
}
I am getting following error -
org.openqa.selenium.WebDriverException: unknown error: cannot get
automation extension from unknown error: page could not be found:
chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
I am using MAC OS
Thanks