How to run selenium tests in Chrome browser? - java

I have some tests using JUnit and Selenium, and I need to run it on the Chrome browser. I downloaded the Chrome driver, and configure my SetUp() as:
#Before
public void SetUp() throws Exception{
System.setProperty("webdriver.chrome.driver","");
driver = new ChromeDriver();
baseUrl = ;
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);//Wait 5 seconds to load the page
}
The ChromeDriver.exe are added in my "Referenced Libraries" folder.
When I'll run the tests, the following error is displayed:
java.lang.exception: No runnable methods
Anybody know how can I fix this?
SOLUTION
1º Add the chromedriver in the path of your computer.
2º Update your setProperty as: System.setProperty("webdriver.chrome.driver","C:\\Users\\pedro_nazario\\Desktop\\ChromeDriver\\chromedriver.exe");
The second parameter must be the way where is your Chromedriver.exe in my case, the chromedriver are in a folder on desktop.
The most important thing, that you never forget
When you'll run the tests, before, close your Chrome browser completely. Any chrome browser must be open before you run your tests. If have some chrome browser opened, the selenium will take a error in your screen.

According to the documentation, webdriver.chrome.driver should contain the path to the chromedriver executable:
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
Alternatively, you can add path to the chromedriver to the PATH environment variable.

Related

Selenium webdriver is looking at wrong path for Chrome.exe

I am trying to launch chrome.exe from selenium webdriver i have chrome installed on my machine and chromedriver path is also given in code but selenium webdriver for java is looking for chrome.exe on wrong path and giving error and not launching browser.
I have tried options class to locate the chrome.exe with the actual path of chrome.exe but not working for me.I have done required imports as well but still no success.
I have tried below selenium webdriver java code
public class News24Test
{
public static void main(String[] args) throws Exception
{
System.setProperty("webdriver.chrome.driver","C://News24SA//ChromeDriver//chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setBinary("C://Program Files(x86)//Google//Chrome//Application//chrome.exe"); // Provide absolute executable chrome browser path with name and extension here
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("http://www.news24.com");
}
}
Selenium is looking at below path which is wrong path
C:\Users\orestip\LocalSettings\Application Data\Google\Chrome\Application\chrome.exe
Try setting the options first:
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver","C:\\News24SA\\ChromeDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
Make sure the chromedriver version and the chrome browers versions match.
You can either update your chrome browser to match the driver version or you can choose a chromedriver that matches your browser version.
Hi so old question but if anyone else is a bit stumped by this, I'll give my take.
So, you may one day have a working chromedriver and then it suddenly just stops working. What actually happens is Chrome updates behind the scenes and makes it out of date.
What you need to do is update your chromedriver so it matches your actual, normal Chrome installation.

Unable to find Matching Set of Capabilities and ChromeDriver

Here is the situation. I downloaded the chrome webdriver, unzipped the file, and went through the steps for setting the path through system properties. I am still unable to open chrome from Eclipse. Please help.
Unable to find matching set of capabilities
You are giving wrong parameter in system properties
Gecko driver is for firefox
If you have already downloaded chrome driver simply replace geckodriver.exe with chromedriver.exe.Otherwise, Download chrome driver and place it in your folder given in system properties and run your code.
Your code will appear as:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\...\\Drivers\\chromedriver.exe");
// **Note**: complete your path above
driver = new ChromeDriver();

Java Selenium Gecko driver not loading

The ISSUE:
The geckodriver.exe is not loading when I run with testNG. Firefox will launch, but selenium cannot connect to the browser and I get an error:
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. ....
My setup:
Windows 7
Eclipse Neon 3
Selenium 3.0.1
Geckodriver v0.13.0 (was using v0.11.1)
Firefox 48.0.2
First I created a quick test using Java and selenium. It just opens the browser and navigates to page. When this runs I see geckodriver process then the firefox process appear in the task manager.
Then I created a new project using Maven and testNG following the set-up from GURU99 web site. I have selenium and testNG added to the pom.xml file.
I used the convert project to testNG (xml file) and set the run configuration to run the XML file.
When I run the test I can see firefox process, then ff starts up. But the gecko driver process is never started.
Here is my code (excluding the imports):
public class NewTest {
private WebDriver driver;
#Test
public void test01() {
driver.get("http://www.startpage.com");
System.out.println("Pge title " + driver.getTitle());
}
#BeforeTest
public void beforeTest() {
System.setProperty("webdriver.gecko.driver", "c:\\selenium\\geckodriver.exe");
driver = new FirefoxDriver();
}
#AfterTest
public void afterTest() {
driver.quit();
}
}
You've missed to set the Marionette capability, e.g.
System.setProperty("webdriver.gecko.driver", <<Your driver path here>>);
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability(FirefoxDriver.MARIONETTE, true);
cap.setCapability(FirefoxDriver.BINARY, <<Your firefox.exe path here>>);
cap.setCapability(FirefoxDriver.PROFILE, <<Your firefox profile here>>);
driver = new FirefoxDriver(cap);
I am using the above and it works like charm!
For more, see: Selenium 3 using Firefox Geckodriver.

Selenium 2.53 not working on Firefox 47

I am getting error while using Firefox with WebDriver.
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms.
Firefox version:47.0
Selenium:2.53.0
Windows 10 64 bit
Is anyone getting a similar issue or any idea what is the solution for this? It's working fine with Chrome but with Firefox none of the URLs are getting loaded.
Unfortunately Selenium WebDriver 2.53.0 is not compatible with Firefox 47.0. The WebDriver component which handles Firefox browsers (FirefoxDriver) will be discontinued. As of version 3.0, Selenium WebDriver will need the geckodriver binary to manage Firefox browsers. More info here and here.
Therefore, in order to use Firefox 47.0 as browser with Selenium WebDriver 2.53.0, you need to download the Firefox driver (which is a binary file called geckodriver as of version 0.8.0, and formerly wires) and export its absolute path to the variable webdriver.gecko.driver as a system property in your Java code:
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
Luckily, the library WebDriverManager can do this work for you, i.e. download the proper Marionette binary for your machine (Linux, Mac, or Windows) and export the value of the proper system property. To use this library, you need to include this dependency into your project:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.0</version>
</dependency>
... and then execute this line in your program before using WebDriver:
WebDriverManager.firefoxdriver().setup();
A complete running example of a JUnit 4 test case using WebDriver could be as follows:
public class FirefoxTest {
protected WebDriver driver;
#BeforeClass
public static void setupClass() {
WebDriverManager.firefoxdriver().setup();
}
#Before
public void setupTest() {
driver = new FirefoxDriver();
}
#After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
#Test
public void test() {
// Your test code here
}
}
Take into account that Marionette will be the only option for future (for WebDriver 3+ and Firefox 48+), but currently (version 0.9.0 at writing time) is not very stable. Take a look to the Marionette roadmap for further details.
UPDATE
Selenium WebDriver 2.53.1 has been released on 30th June 2016. FirefoxDriver is working again with Firefox 47.0.1 as browser.
Try using firefox 46.0.1. It best matches with Selenium 2.53
https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64/en-US/
I had the same issue and found out that you need to switch drivers because support was dropped. Instead of using the Firefox Driver, you need to use the Marionette Driver in order to run your tests. I am currently working through the setup myself and can post some suggested steps if you'd like when I have a working example.
Here are the steps I followed to get this working on my Java environment on Mac (worked for me in my Linux installations (Fedora, CentOS and Ubuntu) as well):
Download the nightly executable from the releases page
Unpack the archive
Create a directory for Marionette (i.e., mkdir -p /opt/marionette)
Move the unpacked executable file to the directory you made
Update your $PATH to include the executable (also, edit your .bash_profile if you want)
:bangbang: Make sure you chmod +x /opt/marionette/wires-x.x.x so that it is executable
In your launch, make sure you use the following code below (it is what I used on Mac)
Quick Note
Still not working as expected, but at least gets the browser launched now. Need to figure out why - right now it looks like I need to rewrite my tests to get it to work.
Java Snippet
WebDriver browser = new MarionetteDriver();
System.setProperty("webdriver.gecko.driver", "/opt/marionette/wires-0.7.1-OSX");
If you're on OSX using Homebrew, you can install old Firefox versions via brew cask:
brew tap goldcaddy77/firefox
brew cask install firefox-46 # or whatever version you want
After installing, you'll just need to rename your FF executable in the Applications directory to "Firefox".
More info can be found at the git repo homebrew-firefox. Props to smclernon for creating the original cask.
If you're on a Mac do brew install geckodriver and off you go!
In case anyone is wondering how to use Marionette in C#.
FirefoxProfile profile = new FirefoxProfile(); // Your custom profile
var service = FirefoxDriverService.CreateDefaultService("DirectoryContainingTheDriver", "geckodriver.exe");
// Set the binary path if you want to launch the release version of Firefox.
service.FirefoxBinaryPath = #"C:\Program Files\Mozilla Firefox\firefox.exe";
var option = new FirefoxProfileOptions(profile) { IsMarionette = true };
var driver = new FirefoxDriver(
service,
option,
TimeSpan.FromSeconds(30));
Overriding FirefoxOptions to provide the function to add additional capability and set Firefox profile because selenium v53 doesn't provide that function yet.
public class FirefoxProfileOptions : FirefoxOptions
{
private DesiredCapabilities _capabilities;
public FirefoxProfileOptions()
: base()
{
_capabilities = DesiredCapabilities.Firefox();
_capabilities.SetCapability("marionette", this.IsMarionette);
}
public FirefoxProfileOptions(FirefoxProfile profile)
: this()
{
_capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());
}
public override void AddAdditionalCapability(string capabilityName, object capabilityValue)
{
_capabilities.SetCapability(capabilityName, capabilityValue);
}
public override ICapabilities ToCapabilities()
{
return _capabilities;
}
}
Note: Launching with profile doesn't work with FF 47, it works with FF 50 Nightly.
However, we tried to convert our test to use Marionette, and it's just not viable at the moment because the implementation of the driver is either not completed or buggy. I'd suggest people downgrade their Firefox at this moment.
New Selenium libraries are now out, according to: https://github.com/SeleniumHQ/selenium/issues/2110
The download page http://www.seleniumhq.org/download/ seems not to be updated just yet, but by adding 1 to the minor version in the link, I could download the C# version: http://selenium-release.storage.googleapis.com/2.53/selenium-dotnet-2.53.1.zip
It works for me with Firefox 47.0.1.
As a side note, I was able build just the webdriver.xpi Firefox extension from the master branch in GitHub, by running ./go //javascript/firefox-driver:webdriver:run – which gave an error message but did build the build/javascript/firefox-driver/webdriver.xpi file, which I could rename (to avoid a name clash) and successfully load with the FirefoxProfile.AddExtension method. That was a reasonable workaround without having to rebuild the entire Selenium library.
Its a FF47 issue
https://github.com/SeleniumHQ/selenium/issues/2110
Please downgrade to FF 46 or below (or try out FF48 developer https://developer.mozilla.org/en-US/Firefox/Releases/48)
Instructions on how to downgrade:
https://www.liberiangeek.net/2012/04/how-to-install-previous-versions-of-firefox-in-ubuntu-12-04-precise-pangolin/
Or if you are on Mac, as suggested by someone else in this thread use brew.
Firefox 47.0 stopped working with Webdriver.
Easiest solution is to switch to Firefox 47.0.1 and Webdriver 2.53.1. This combination again works. In fact, restoring Webdriver compatibility was the main reason behind the 47.0.1 release, according to https://www.mozilla.org/en-US/firefox/47.0.1/releasenotes/.
You can try using this code,
private WebDriver driver;
System.setProperty("webdriver.firefox.marionette","Your path to driver/geckodriver.exe");
driver = new FirefoxDriver();
I upgraded to selenium 3.0.0 and Firefox version is 49.0.1
You can download geckodriver.exe from https://github.com/mozilla/geckodriver/releases
Make sure you download zip file only, geckodriver-v0.11.1-win64.zip file or win32 one as per your system and extract it in a folder.
Put the path for that folder in the "Your path to driver" quotes.Don't forget to put geckodriver.exe in the path.
I eventually installed an additional old version of Firefox (used for testing only) to resolve this, besides my regular (secure, up to date) latest Firefox installation.
This requires webdriver to know where it can find the Firefox binary, which can be set through the webdriver.firefox.bin property.
What worked for me (mac, maven, /tmp/ff46 as installation folder) is:
mvn -Dwebdriver.firefox.bin=/tmp/ff46/Firefox.app/Contents/MacOS/firefox-bin verify
To install an old version of Firefox in a dedicated folder, create the folder, open Finder in that folder, download the Firefox dmg, and drag it to that Finder.
Here's what the problem looked like in Wireshark
Just load up 2.53.1 and every thing will work.
As of September 2016
Firefox 48.0 and selenium==2.53.6 work fine without any errors
To upgrade firefox on Ubuntu 14.04 only
sudo apt-get update
sudo apt-get upgrade firefox
It seems to me that the best solution is to update to Selenium 3.0.0, download geckodriver.exe and use Firefox 47 or higher.
I changed Firefox initialization to:
string geckoPathTest = Path.Combine(Environment.CurrentDirectory, "TestFiles\\geckodriver.exe");
string geckoPath = Path.Combine(Environment.CurrentDirectory, "geckodriver.exe");
File.Copy(geckoPathTest, geckoPath);
Environment.SetEnvironmentVariable("webdriver.gecko.driver", geckoPath);
_firefoxDriver = new FirefoxDriver();
I can confirm that selenium 2.53.6 works with firefox 44 for me on ubuntu 15.

Selenium compatability with Firefox and Chrome

I am able to run the script successfully on Firefox and i am not able to run the same script on Chrome. Please help me in finding these issue.
Thanks
Hi to run test in chrome please call chrome driver like below
// call the Chrome driver as below first
System.setProperty("webdriver.chrome.driver", "D:\\eclipseProject\\##\\src\\com\\##\\chromedriver_win32\\chromedriver.exe");
// path to chrome exe that you have downloaded form given url (below)
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.seleniumhq.com"); // link to your web-table web page
now your script as same on firfox
// download chrome exe form this link http://docs.seleniumhq.org/download/

Categories