I have an exception when I try to run my project and I do not understand why (Selenium and TestNG)

0

I have the following exception when I try to do some tests with selenium using testng, but it tells me that I have an exception caused by Selenium web driver; as I understand it is by FireFox but I do not know how to fix it.

org.testng.TestNGException: 
Cannot instantiate class TestCases.suite
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
    at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:382)
    at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:295)
    at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:118)
    at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:183)
    at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:128)
    at org.testng.TestRunner.initMethods(TestRunner.java:416)
    at org.testng.TestRunner.init(TestRunner.java:242)
    at org.testng.TestRunner.init(TestRunner.java:212)
    at org.testng.TestRunner.<init>(TestRunner.java:166)
    at org.testng.remote.support.RemoteTestNG6_9_7$1.newTestRunner(RemoteTestNG6_9_7.java:26)
    at org.testng.remote.support.RemoteTestNG6_9_7$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_9_7.java:59)
    at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:587)
    at org.testng.SuiteRunner.init(SuiteRunner.java:161)
    at org.testng.SuiteRunner.<init>(SuiteRunner.java:114)
    at org.testng.TestNG.createSuiteRunner(TestNG.java:1290)
    at org.testng.TestNG.createSuiteRunners(TestNG.java:1277)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1131)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
    ... 21 more
Caused by: org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: MAC
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_101'
Driver info: driver.version: firefox
    at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:50)
    at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:57)
    at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:53)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:96)
    at TestCases.suite.<init>(suite.java:24)
    ... 26 more
    
asked by Laura 21.09.2016 в 23:43
source

1 answer

1

To use your firefox installation, you need to indicate where you have the webdriver the firefox, they are two different things. You need to have a version of firefox installed, use a selenium distribution and depending on the versions chosen up to this point, you will need a webdriver or another.

Until version 3.0 of selenium it was not necessary to indicate anything, but if you are in a later version you need to download gecko driver and later in the code before starting the driver, indicate to the system where it is located, with a line similar to this:

System.setProperty("webdriver.gecko.driver",
                   "ruta/a/distribuciongecko");
    
answered by 06.10.2017 в 17:33