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)
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();
}
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>
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
Related
While writing cide for Selenium with Java in intellij, I am getting this error.
This issue is occuring for new projecting. Old projects are working fine.Though I am copying the same data from old project to new project.
Code:
#Test
public void testcase1() throws IOException {
driver = initializeDriver();
driver.manage().window().maximize();
driver.get(props.getProperty("url"));
}
Error:
java.lang.NoClassDefFoundError: org/openqa/selenium/ElementNotSelectableException
at org.openqa.selenium.remote.ErrorCodes.<clinit>(ErrorCodes.java:228)
at org.openqa.selenium.remote.ErrorHandler.<init>(ErrorHandler.java:68)
at org.openqa.selenium.remote.ErrorHandler.<init>(ErrorHandler.java:59)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:113)
at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:108)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:93)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
at resources.Base.initializeDriver(Base.java:28)
at testcases.HomePageTest.testcase1(HomePageTest.java:15)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:135)
at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:673)
at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:220)
at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:945)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:193)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:808)
at org.testng.TestRunner.run(TestRunner.java:603)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:429)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:423)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:383)
at org.testng.SuiteRunner.run(SuiteRunner.java:326)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1249)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.runSuites(TestNG.java:1092)
at org.testng.TestNG.run(TestNG.java:1060)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.ElementNotSelectableException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 35 more
It was Dependency issue.Though I had added selenium dependencies in pom.xml file but it did not get added successfully.
So issue was occuring.
If you also get this issue,
Open terminal, navigate till path of the project and execute command "mvn install"
and then run your program.
hope that you're fine. I'm trying to run my first Selinuim test but it fails every time, most of the tutorials use Chrome but I'm using Microsoft Edge and I would like to run tests each time on there, I downloaded the right Edge Webdriver version according to edge://settings/help, here what I did in my code and in the project files:
My code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.edge.EdgeDriver;
public class Test {
#org.testng.annotations.Test
public void test() {
WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver", "msedgedriver.exe");
driver.get("http://automationpractice.com/index.php?controller=authentication&back=my-account");
}
} ```
The error:
[RemoteTestNG] detected TestNG version 7.3.0
FAILED: test
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
at com.google.common.base.Preconditions.checkState(Preconditions.java:847)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at Test.test(Test.java:7)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
Default suite
Total tests run: 1, Passes: 0, Failures: 1, Skips: 0
===============================================```
enter image description here
System.setProperty("webdriver.chrome.driver", "msedgedriver.exe");
instead of relative path provide full path
also rearrange the order
System.setProperty("webdriver.chrome.driver", "c:\\somepath\\msedgedriver.exe");
WebDriver driver = new ChromeDriver();
and instead of chrome use:
webdriver.edge.driver
use like
System.setProperty("webdriver.edge.driver","D:\\msedgedriver.exe");
WebDriver driver = new EdgeDriver();
https://www.selenium.dev/documentation/en/webdriver/driver_requirements/
see the documentation
I am getting NullPointerException everytime I try to run below code at code line element.click()
Note : It passes if I comment the last line of code.
Also similar question was asked here but it didn't help.
AndroidDriver driver;
#Test
public void TestAppium() throws Exception{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "MotoG5s Plus");
capabilities.setCapability("platformVersion", "7.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("noReset", "true");
File file = new File("D:\\Appium Workspace\\AppiumDemo\\apk\\MakeMyTrip Flights Hotels Cabs IRCTC Rail Bookings_v7.3.2_apkpure.com.apk");
capabilities.setCapability("app", file.getAbsolutePath());
driver = new AndroidDriver(new URL("http://10.80.196.55:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Thread.sleep(10000);
WebElement element = driver.findElementById("com.makemytrip:id/my_profile_icon");
element.click();
}
Also my driver onject is not null as you can see from below screenshot
Also the element is not null as you can see in screenshot below :-
I have even put the thread.sleep() in case it is because of loading.
The ID given in findelementbyid() method is correct. And also it launches the app and then it
It Launches the app and then it throws below error message :-
java.lang.NullPointerException
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
at Appiumcapabilities.TestAppium(Appiumcapabilities.java:34)
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.Invoker.invokeMethod(Invoker.java:580)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
I am using selenium-java-3.9.1 and appium server 1.7.1, testNG
Windows 10, appium-java-client version 4.1.0
Do not set selenium dependency explicitly as appium-java-client dependency already has it in-built: you are running into library incompatibility issue.
If it is necessary to change the version of Selenium then you can configure pom.xml like following:
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>${version.you.require}</version>
<scope>test</test>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version.you.require}</version>
</dependency>
Same thing can be done with Gradle:
repositories {
jcenter()
maven {
url "http://repo.maven.apache.org/maven2"
}
}
dependencies {
...
testCompile group: 'io.appium', name: 'java-client', version: requiredVersion {
exclude module: 'selenium-java'
}
testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java',
version: requiredSeleniumVersion
...
}
As per your code block it seems you are using Java as the Selenium Language Binding Art. Now, as per the Java Docs the supported methods of a WebElement are:
findElement(By by)
findElements(By by)
Where as findElementById() is associated with the JavaScript Selenium Language Binding Art.
Solution
If you desire to work with the id attribute of an element, you need to replace the line:
WebElement element = driver.findElementById("com.makemytrip:id/my_profile_icon");
By:
WebElement element = driver.findElement(By.id("com.makemytrip:id/my_profile_icon"));
Maybe issue to this problem is that it can't find Your package or activity, try putting these desired capsabilities:
appActivity = Activity name for the Android activity you want to wait for
(eg. "MainActivity, .Settings")
appPackag = Java package of the Android app you want to run
(eg. "com.example.android.myApp, com.android.settings")
appWaitActivity = Activity name for the Android activity you want to wait for
(eg. Splash)
It might be that You did everything OK, but wrong activity is shown.
Good practice is to put appPackage, and appActivity.
Hope this helps,
P.S.: and please also implement solution/answer from #dmle, it also could cause this kind of issues.
When i am trying to invoke chrome browser in eclipse using selenium driver with Java , i am getting an error.
Please help me out in resolving this issue.
Below is my code -
package packagedefault;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeBrowser {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://google.com");
}
}
Below is the error message i am getting -
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/config/RegistryBuilder
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:69)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:57)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:60)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:242)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:219)
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:63)
at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:36)
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:123)
at packagedefault.ChromeBrowser.main(ChromeBrowser.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.config.RegistryBuilder
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
You can try using below code inside main() function
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");
Works properly here in my windows PC
Exception you mentioned
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/http/config/RegistryBuilder
Occured when jars files are not available.
Import only the selenium-server-standalone- jars and try your code .
System.setProperty("webdriver.chrome.driver", "Path of chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://google.com");
This question already has answers here:
Official reasons for "Software caused connection abort: socket write error"
(14 answers)
Closed 7 years ago.
My settings :
TestNG 6.9.10 - Java 1.8 - Eclipse Mars.1 Release (4.5.1)
Windows 10
Every time I run a TestNG test suite I have this error :
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source)
at java.io.ObjectOutputStream.<init>(Unknown Source)
at org.testng.remote.strprotocol.SerializedMessageSender.sendMessage(SerializedMessageSender.java:24)
at org.testng.remote.strprotocol.MessageHub.sendMessage(MessageHub.java:43)
at org.testng.remote.RemoteTestNG$RemoteSuiteListener.onStart(RemoteTestNG.java:257)
at org.testng.SuiteRunner.invokeListeners(SuiteRunner.java:208)
at org.testng.SuiteRunner.run(SuiteRunner.java:266)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
Even if my test class is empty :
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class sample {
public WebDriver driver;
#Test
public void f() {
}
#BeforeTest
public void beforeTest() {
driver = new FirefoxDriver();
driver.get("http://localhost:8081/login.html?profile=desktop");
}
#AfterTest
public void afterTest() {
driver.close();
}
}
The test is running, so it doesn't interfere with the test case, but I really would like to understand and remove this Exception.
Thank you for any idea.
I'm thinking somewhere in WebDriver, java.net is used. Your localhost webserver is closing the socket or it was closed prematurely. Instead of using Before and After test, try to write it all in one Test method and debug. Unfortunately, there's no mention of your class in the stack trace to pinpoint which call is causing the problem.
Step through the following and see where the exception is thrown. If it's on the driver.get call, then your http server is likely rejecting the connections. If it's thrown at the close(), the connection has already been dropped (probably rejected by the server).
#Test
public void test() {
driver = new FirefoxDriver();
driver.get("http://localhost:8081/login.html?profile=desktop");
driver.close();
}