0
votes

I am running simple code in selenium and it throws below exception:-

@Test
public void test(){

System.setProperty("webdriver.chrome.driver", "geckodriver.exe");   
WebDriver driver=new FirefoxDriver();
driver.get("https://google.com");
driver.manage().window().maximize();
}

Following error is shown when I have executed my script:

Previously it was working, my firefox version is 55 and i am using latest gecko driver version. Please help!!

Exception is:- java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136) at org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:41) at org.openqa.selenium.firefox.GeckoDriverService$Builder.usingFirefoxBinary(GeckoDriverService.java:108) at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:204) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:103) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:99) at newTab.Tab.test(Tab.java:16) 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:104) at org.testng.internal.Invoker.invokeMethod(Invoker.java:645) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112) at org.testng.TestRunner.privateRun(TestRunner.java:756) at org.testng.TestRunner.run(TestRunner.java:610) at org.testng.SuiteRunner.runTest(SuiteRunner.java:387) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293) at org.testng.TestNG.runSuitesLocally(TestNG.java:1218) at org.testng.TestNG.runSuites(TestNG.java:1133) at org.testng.TestNG.run(TestNG.java:1104) 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)

3
It seems like you are copy this code from some where else and forget to replace the string from webdriver.chrome.driver to webdriver.gecko.driverJainish Kapadia

3 Answers

1
votes

You are using wrong syntax near "System.setProperty("webdriver.chrome.driver", "geckodriver.exe");". Replace "chrome.driver" with "gecko.driver"

@Test public void test(){
System.setProperty("webdriver.chrome.driver", "geckodriver.exe");       
WebDriver driver=new FirefoxDriver();
driver.get("https://google.com");
driver.manage().window().maximize();
}

Replace it with

@Test public void test(){
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://google.com");
driver.manage().window().maximize();
}
0
votes

The error

Exception is:- java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V at 

is Java's way of telling you that your code is internally invoking a method called

void checkState(boolean, java.lang.String, java.lang.Object)

within the class com.google.common.base.Preconditions but this method is not available.

This usually happens when your classpath is messed up.

You haven't mentioned what version of Selenium you are working with. So I am going to assume that you are working with the latest released version of Selenium viz., 3.5.2.

Please make sure that you are using com.google.guava:guava version 23.0.

If you are using Maven, then you can perhaps add a dependency which looks like below, to your pom file.

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>23.0</version>
</dependency>
0
votes

it's conflict problem, you should check on Project Structure, if it exists 2 Maven, it's conflict problem, you have to delete "Maven: com.google.guava: guava:jdk...". If it exists only 1 Maven guava, just need update the dependency