I am new on using Selenium and I faced some questions on using RemoteWebDriver in Selenium Grid 2. I would like to what's wrong in my code. Thanks.
I set the RemoteWebDriver in 3 steps:
Set the Chrome driver to system property, I checked the path is correct.
Set the capabilities
Turn on the driver by RemoteWebDriver
logger.info("1. Start");
File file = new File("/path/of/chromedriver");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
logger.info("2. Get Path: " + file.getAbsolutePath());
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
logger.info("3. Set capabilities: " + caps);
URL url = new URL(URL);
RemoteWebDriver driver = new RemoteWebDriver(url, caps);
logger.info("4. Initialize driver: " + driver);
logger.info("5. End");
return driver;
The result pass first 2 steps but fail in the last step because the log does not show. It seems there is a problem in setting RemoteWebDriver. The log is shown as below:
May 16, 2017 8:28:16 PM com.test.Setup setupDriver
INFO: 1. Start
May 16, 2017 8:28:16 PM com.test.Setup setupDriver
INFO: 2. Get Path: /path/of/chromedriver
May 16, 2017 8:28:16 PM com.test.Setup setupDriver
INFO: 3. Set capabilities: Capabilities [{browserName=chrome}]
May 16, 2017 8:28:16 PM com.test.Setup setupDriver
SEVERE: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
Can anyone suggest where is the problem, thanks!
selenium-server-standalone-3.4.0.jar
selenium-java-3.4.0
chromedriver 2.29
java version "1.8.0_111"
TestNG
The exception says it all.
May 16, 2017 8:28:16 PM com.test.Setup setupDriver SEVERE: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
Please ensure you do the following on the machine in which you are running the node.
Have the location of the chromedriver binary made available as part of your PATH environment variable.
Now to ensure that the location is properly set, open up a new command prompt/terminal and type chromedriver.
You should see an output as below (my output is from a MAC)
12:16 $ chromedriver
Starting ChromeDriver 2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b) on port 9515
Only local connections are allowed.
Once you see a similar output, you can try running your test again and you should be fine.
Related
I need to turn off the Marionette/GeckoDriver logging; is there is any way to do that? I've been searching a lot, but I am not getting the proper answer.
The INFO logs were:
1484653905833 geckodriver INFO Listening on 127.0.0.1:15106
Jan 17, 2017 5:21:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1484653906715 mozprofile::profile INFO Using profile path C:\Users\vtiger\AppData\Local\Temp\3\rust_mozprofile.7d2LEwDKoE8J
1484653906720 geckodriver::marionette INFO Starting browser C:\Program Files\Mozilla Firefox\firefox.exe
1484653906731 geckodriver::marionette INFO Connecting to Marionette on localhost:58602
1484653908388 addons.manager DEBUG Application has been upgraded
1484653908843 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
1484653908846 addons.manager DEBUG Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
1484653908852 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/GMPProvider.jsm
1484653908855 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/PluginProvider.jsm
1484653908857 addons.manager DEBUG Starting provider: XPIProvider
1484653908857 addons.xpi DEBUG startup
1484653908858 addons.xpi INFO SystemAddonInstallLocation directory
How do I turn off this logging?
You can disable the logs by sending them to /dev/null via a system property like so:
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
return new FirefoxDriver();
Working solution on Windows and Linux.
# python 3
# windows
PATH_TO_DEV_NULL = 'nul'
FIREFOX_DRIVER_PATH = 'D:\\path\\to\\geckodriver.exe'
# linux
PATH_TO_DEV_NULL = '/dev/null'
FIREFOX_DRIVER_PATH = '/path/to/geckodriver'
# start browser
driver = webdriver.Firefox(executable_path=FIREFOX_DRIVER_PATH,
service_log_path=PATH_TO_DEV_NULL)
Tried the following code, but didn't work. Seems like a bug in selenium 3.0
LoggingPreferences pref = new LoggingPreferences();
pref.enable(LogType.BROWSER, Level.OFF);
pref.enable(LogType.CLIENT, Level.OFF);
pref.enable(LogType.DRIVER, Level.OFF);
pref.enable(LogType.PERFORMANCE, Level.OFF);
pref.enable(LogType.PROFILER, Level.OFF);
pref.enable(LogType.SERVER, Level.OFF);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, pref);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
driver.get("https://www.google.com/");
driver.findElement(By.id("lst-ib")).sendKeys("something");
Thread.sleep(2000);
driver.quit();
One option that has worked for some is proposed here, and uses a batch file to pass in command line arguments to the executable. Unfortunately, this oftentimes leaves extra processes open (geckodriver.exe, cmd.exe) and no solution to this next problem has been proposed as of yet...
GeckoDriverService gecko = new GeckoDriverService(new File("c:/selenium/geckodriver.exe"), 4444, ImmutableList.of("--log=fatal"), ImmutableMap.of());
gecko.sendOutputTo(new FileOutputStream("gecko_log.txt"));
gecko.start();
FirefoxOptions opts = new FirefoxOptions().setLogLevel(Level.OFF);
DesiredCapabilities capabilities = opts.addTo(DesiredCapabilities.firefox());
capabilities.setCapability("marionette", true);
FirefoxDriver driver = new FirefoxDriver(gecko, capabilities);
This might be a bit hacky but it can quickly get the job done. Given that you know the exact location of your file and you run your code on Linux you can just cd into that dir and
rm geckodriver.log
ln -s /dev/null geckodriver.log
service_log_path seems to be deprecated in python:
driver.py:77: DeprecationWarning: service_log_path has been deprecated, please pass in a Service object
This worked for me now:
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium import webdriver
service = FirefoxService(driver_path, log_path='nul') # Disable logs in windows, for linux probably /dev/null
driver = webdriver.Firefox(
service=service
)
This is the only output I get when I run the tests. Do I need to add the geckodriver.exe somewhere in my build path or linked resources?
Console Output:
Jun 16, 2016 4:17:38 PM io.github.bonigarcia.wdm.BrowserManager getLatest
INFO: Latest version of [wires, geckodriver] is 0.8.0
C:\Users\aconte/.m2/repository/webdriver/geckodriver\0.8.0/geckodriver-v0.8.0-win32.zip
Jun 16, 2016 4:17:38 PM io.github.bonigarcia.wdm.BrowserManager exportDriver
INFO: Exporting webdriver.gecko.driver as C:\Users\aconte\.m2\repository\webdriver\geckodriver\win32\0.8.0\geckodriver.exe
<- |50:{"applicationType":"gecko","marionetteProtocol":3}|
54:{"name":"getMarionetteID","to":"root","parameters":{}}
This my code for setting up the driver.
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setEnableNativeEvents(true);
ffprofile.setPreference("xpinstall.signatures.required", false);
driver = new MarionetteDriver(ffprofile);
I am trying to start opera(v 36.0) using selenium 2.53.0 and Opera chromium driver _win64 (0.2.2).
When I try to run sample code, an exception occurred and browser didn't started.
Sample code:
File pathToOpera = new File("E://operadriver.exe");
DesiredCapabilities cap = DesiredCapabilities.operaBlink();
cap.setCapability("webdriver.opera.driver",pathToOpera);
driver = new OperaDriver(cap);
I am getting error as
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.opera.driver system property; for more information, see https://github.com/operasoftware/operachromiumdriver. The latest version can be downloaded from https://github.com/operasoftware/operachromiumdriver/releases
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at org.openqa.selenium.opera.OperaDriverService.access$0(OperaDriverService.java:1)
at org.openqa.selenium.opera.OperaDriverService$Builder.findDefaultExecutable(OperaDriverService.java:118)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.opera.OperaDriverService.createDefaultService(OperaDriverService.java:82)
at org.openqa.selenium.opera.OperaDriver.<init>(OperaDriver.java:137)
My execution environment: win 8, 64 bit
Add before Your code:
System.setProperty("webdriver.opera.driver","E://operadriver.exe");
System.setProperty("opera.binary","E://yourOperaPath.exe");
I am trying to run my test cases on Chrome and I had copied the path in the Properties file,but still console is throwing annoying statements like:
ERROR: The path to the chromedriver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromium/downloads/list
FAILED CONFIGURATION: #BeforeTest startWebSession
java.lang.NullPointerException
One thing I have found is that the Chrome driver cannot be started from within Eclipse. It must be run from a command prompt. At least on Windows 7 64-bit.
Trying to run it from within Eclipse produces this exception:
Exception in thread "main" java.lang.IllegalStateException: The webdriver.chrome.driver system property defined chromedriver executable does not exist: C:\Windows\System32\chromedriver.exe
This problem only occurs for Chrome. IE and FireFox work fine from within Eclipse.
Download the chrome driver from http://code.google.com/p/chromedriver/downloads/list
Initialize your driver object in the following manner -
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
By doing this the chrome driver works properly.
This is how do I initialize the ChromeDriver:
public RegulationUI() throws Exception{
ChromeDriverService service = ChromeDriverService.createDefaultService();
File file = new File(RegulationUI.class.getResource("/chromedriver.exe").toURI());
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(service,options);
}
BTW my test class is named RegulationUI
Try this, it works for me and moreover, I know that this is "multicomputer" solution - our project is in subversion and this way everybody can run it, even if we have differently setup where exactly on disk the "working folder" for IDE is
Please download chromedriver.exe for Google chrome browser
please download IEdriver.exe for Internet explore.
Please And kept these files in a root folder of windows for simplicity. Lets consider your operating systems installed on c:\ (C Driver) create a folder name Selenium on C-Drive and Kept these binary(.exe) files. like c:\selenium
in your Testcase/testScript Write as
//For Chrome Browser:
Webdriver driver = new ChromeDriver();
java.io.File file = new File("c:\\selenium\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
If you are using maven then try to use following in your pom:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>RELEASE</version>
</dependency>
and use it like this for chrome in your setup:
ChromeDriverManager.getInstance().setup();
driver = new ChromeDriver();
Unable to find/open Firefox Binary - webdriver/robot framework
My tests run fine in java and fitnesse. They also run fine when executing them through robot framework with Internet Explorer and Chrome. However when I execute them through Firefox, using 'new FirefoxDriver()', I receive the following error:
DEBUG java.lang.ExceptionInInitializerError
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java: 81)
Caused by: java.lang.NullPointerException
org.openqa.selenium.firefox.FirefoxBinary.<clinit>(FirefoxBinary.java: 42)
... 183 more
In the FirefoxBinary and FirefoxDriver classes these lines correspond to the following code:
FirefoxBinary ln42-43
private static final String PATH_PREFIX = "/" +
FirefoxBinary.class.getPackage().getName().replace(".", "/") + "/";
and FirefoxDriver ln 80-82
public FirefoxDriver(FirefoxProfile profile) {
this(new FirefoxBinary(), profile);
}
I have tried setting the path to the Firefox binary in my classpath, pythonpath (used by robotframework) and path. I have also written the following lines of code to try to force the binary to be found:
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(FirefoxDriver.BINARY, "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
I have tried to execute the tests on two computers, my work and home machines. Further I have tried to use a firefox profile created using firefox.exe –p and also by creating one in the java code. I have tried Firefox 6-8. Unfortunately none of these things have worked.
I am also using/have used:
Java 1.6
Selenium 2.9.0/2.13.0
Windows 7
I am unsure if this is related but as a work around I have been trying to get Firefox to run through a remote browser. I have been trying the following code:
rcc = new RemoteControlConfiguration();
rcc.setPort(4447);
rcc.setPortDriversShouldContact(4447);
rcc.setInteractive(true);
rcc.setSingleWindow(true);
rcc.setTimeoutInSeconds(30);
ss = new SeleniumServer(rcc);
ss.start();
DesiredCapabilities cap = new DesiredCapabilities();
cap.setJavascriptEnabled(true);
cap.setBrowserName("firefox");
URL url = new URL ("http://www.google.com/");
driver = new RemoteWebDriver(url,cap);
However when I run the above I get the following error message:
Exception in thread "main" org.openqa.selenium.WebDriverException: Error communicating with the remote browser. It may have died.
Build info: version: '2.13.0', revision: '14794', time: '2011-11-18 17:49:47'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: Selenium2Driver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:412)
Does anyone have any idea on how to fix either of my problems?
Any help would be greatly appreciated, I feel very stuck on this issue atm. Two days of trying to get Firefox to work when Internet Explorer already does….. It feels as if the world is about to end.
Thanks,
James
EDIT:1
It is possible for me to run Firefox by using selenium-server.
James, FYI, URL for RemoteWebDriver appears incorrect in post above. Should be something more like "localhost:4444/wd/hub";? Interestingly, I'm having the opposite problem with Web Driver, having issues starting Firefox via RemoteWebDriver but Firefox runs fine via native FirefoxDriver. IE works fine over remote. – David Dec 4 '11 at 4:51
Thanks David!
I am not understanding why you have not configured your Firefox binary in your remote grids config.json file? That's how I would do it. Then, your DesiredCapabilities object would not need to define it. A hint can be found here.
If it works, the line in the JSON file might look like:
"binary": "C:/Program Files/Mozilla Firefox/firefox.exe",
I guess it doesn't allow you to dynamically set the binary location from your code, but perhaps you can try it that way to prove if it should work or not as a troubleshooting step.
FirefoxProfile profile = new FirefoxProfile();
FirefoxBinary binary = new FirefoxBinary(new File("C:\\path to firefox\\firefox.exe"));
driver = new FirefoxDriver(binary, profile);
try this
This kind of issue obtained because of selenium web driver fail to find the .exe files of Firefox. Please check whether C:\Program Files (x86)\Mozilla Firefox you have exe file in the location and don’t forget to set environment variable having the java jdk path.
Source:- read [Solved Cannot find firefox binary in PATH Selenium][1]http://www.tech4crack.com/solved-cannot-find-firefox-binary-in-path/