How to use Microsoft Edge with Selinum Java - java

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

Related

Selenium java.net.SocketException: Connection reset when calling driver.quit();

I saw these threads:
java.net.SocketException: Connection reset on Selenium driver.close() or driver.quit() statements
selenium/java- java.net.SocketException: Connection reset
But I still don't understand the issue here. Everything is working fine, I get the response and content from the website and when I'm done I call the driver.quit(); / driver.close(); and get the exception. If I don't call that .quit(); I don't get the exception.
I get this exception after I get the web scraping content:
2023-01-31T21:28:31.222+01:00 WARN 8400 --- [cHttpClient-1-4] o.a.netty.handler.WebSocketHandler : onError
java.net.SocketException: Connection reset
at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426) ~[na:na]
at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:259) ~[netty-buffer-4.1.87.Final.jar:4.1.87.Final]
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132) ~[netty-buffer-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.87.Final.jar:4.1.87.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.87.Final.jar:4.1.87.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.87.Final.jar:4.1.87.Final]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
2023-01-31T21:28:31.229+01:00 WARN 8400 --- [cHttpClient-1-4] o.openqa.selenium.remote.http.WebSocket : Connection reset
java.net.SocketException: Connection reset
at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426) ~[na:na]
at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:259) ~[netty-buffer-4.1.87.Final.jar:4.1.87.Final]
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132) ~[netty-buffer-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.87.Final.jar:4.1.87.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.87.Final.jar:4.1.87.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.87.Final.jar:4.1.87.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.87.Final.jar:4.1.87.Final]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
This is the code from the main:
String url = "https://relatedwords.org/relatedto/";
System.setProperty("webdriver.chrome.driver", filePath);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get(url + "Fishsticks");
WebElement words = driver.findElement(By.className("words"));
final List<WebElement> wordList = words.findElements(By.tagName("a"));
wordList.forEach(word -> System.out.println(word.getText()));
// when I remove this I do not get any exceptions
driver.quit();
I use the latest chrome version I just checked, and there are no updates available (Version 109.0.5414.120) and I am using chrome driver version ChromeDriver 109.0.5414.74 and the latest selenium version 4.8.0
So what is the solution here? I tried to read so many stack threads but have not found any solution
Below is the same code I have tried and it works fine with no exceptions. Only difference is that I have not added following code System.setProperty("webdriver.chrome.driver", filePath);. You do not need to set property when you are using the latest version of selenium(which you are using anyways). Try removing this line and see if it resolves your issue.
public static void main(String[] args){
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
WebDriver driver = new ChromeDriver(options);
driver.get("https://relatedwords.org/relatedto/" + "Fishsticks");
WebElement words = driver.findElement(By.className("words"));
final List<WebElement> wordList = words.findElements(By.tagName("a"));
wordList.forEach(word -> System.out.println(word.getText()));
driver.quit();
}
Here is the console output:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 109.0.5414.74 (e7c5703604daa9cc128ccf5a5d3e993513758913-refs/branch-heads/5414#{#1172}) on port 2732
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
batter
cod
united kingdom
ketchup
herring
whitefish
hake
haddock
pollock
refrigerator
british english
breaded
american english
europe
food processing
supermarket
grilling
tartar sauce
fish
machine
backbone
parents
frozen food
wheel
blade
television commercial
southampton
shallow frying
skin
breadcrumbs
salmon
bone
deep frying
world war ii
gorton's of gloucester
clarence birdseye
store brand
vegetable oil
java.net.SocketException: Connection reset
java.net.SocketException may occur due to several possible reasons as follows:
It can occur on the server-side when the client closed the socket connection before the response could be returned over the socket. For example, by quitting the browser before the response was retrieved.
It can also occur by writing to a connection that the other end has already closed normally resulting in an application protocol error.
This usecase
I took your program and executed it. Here is the result:
Code block:
System.setProperty("webdriver.chrome.driver", "C:\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get("https://relatedwords.org/relatedto/Fishsticks");
WebElement words = driver.findElement(By.className("words"));
final List<WebElement> wordList = words.findElements(By.tagName("a"));
wordList.forEach(word -> System.out.println(word.getText()));
driver.quit();
Console output:
batter
cod
united kingdom
ketchup
herring
whitefish
hake
haddock
pollock
refrigerator
british english
breaded
american english
europe
food processing
supermarket
grilling
tartar sauce
fish
machine
backbone
parents
frozen food
wheel
blade
television commercial
southampton
shallow frying
skin
breadcrumbs
salmon
bone
deep frying
world war ii
gorton's of gloucester
clarence birdseye
store brand
vegetable oil
Conclusion
Programmatically, I don't see any error in your code block. However ensure that:
JDK is upgraded to current levels JDK 8u351.
Selenium is upgraded to current levels Version 4.8.0.
ChromeDriver is updated to current ChromeDriver v109.0 level.
Chrome Browser is updated to current chrome=109.0 (as per chromedriver=109.0.5414.74 release notes).
Take a System Reboot.
Execute your Test as a non-root user.
References
You can find a couple of relevant detailed discussions in:
Selenium shows java.net.SocketException: Connection reset
java.net.SocketException: Connection reset
What's causing my java.net.SocketException: Connection reset?

java.lang.NoClassDefFoundError: org/openqa/selenium/ElementNotSelectableException

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.

Cucumber step definitions not linked

I upgraded my serenity and cucumber tests today to version 2.6.0 en cucumber 6. Only to have a lot of package needed to change and the steps of my feature files no longer linked to the step definitions. If if this setup for my cucumberrunner
import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(features = {"src/test/resources/features"},
glue = {"be.nbb.hive.cucumber.steps"})
public class CucumberRunner {
}
But if I look in intellij in the feature files you can no longer click through the steps to go to the definition. And when I run a feature file I get following exception:
10:40:50.005 [main] DEBUG n.thucydides.core.steps.StepEventBus - Test suite started for story net.thucydides.core.model.Story#aa2c74aa
10:40:50.006 [main] INFO - Test Suite Started: Smoke Test Login
sep 09, 2021 10:40:50 AM io.cucumber.core.runtime.Runtime run
SEVERE: Exception while executing pickle
java.util.concurrent.ExecutionException: java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 15
^I click on (?:?:the )?\?(?:.*)?(?:?:.*)? \((name|id|css|xpath\): \?(?:.+)?\\)$
^
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at io.cucumber.core.runtime.Runtime.run(Runtime.java:93)
at net.serenitybdd.cucumber.cli.Main.run(Main.java:27)
at net.serenitybdd.cucumber.cli.Main.main(Main.java:18)
Caused by: java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 15
^I click on (?:?:the )?\?(?:.*)?(?:?:.*)? \((name|id|css|xpath\): \?(?:.+)?\\)$
^
at java.util.regex.Pattern.error(Pattern.java:1955)
at java.util.regex.Pattern.sequence(Pattern.java:2123)
at java.util.regex.Pattern.expr(Pattern.java:1996)
at java.util.regex.Pattern.group0(Pattern.java:2821)
at java.util.regex.Pattern.sequence(Pattern.java:2051)
at java.util.regex.Pattern.expr(Pattern.java:1996)
at java.util.regex.Pattern.compile(Pattern.java:1696)
at java.util.regex.Pattern.<init>(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1054)
at io.cucumber.cucumberexpressions.DefaultPatternCompiler.compile(DefaultPatternCompiler.java:12)
at io.cucumber.cucumberexpressions.TreeRegexp.<init>(TreeRegexp.java:22)
at io.cucumber.cucumberexpressions.CucumberExpression.<init>(CucumberExpression.java:37)
at io.cucumber.cucumberexpressions.ExpressionFactory.createExpression(ExpressionFactory.java:34)
at io.cucumber.core.stepexpression.StepExpressionFactory.crateExpression(StepExpressionFactory.java:88)
at io.cucumber.core.stepexpression.StepExpressionFactory.createExpression(StepExpressionFactory.java:61)
at io.cucumber.core.stepexpression.StepExpressionFactory.createExpression(StepExpressionFactory.java:49)
at io.cucumber.core.runner.CachingGlue.lambda$prepareGlue$3(CachingGlue.java:244)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at io.cucumber.core.runner.CachingGlue.prepareGlue(CachingGlue.java:243)
at io.cucumber.core.runner.Runner.runPickle(Runner.java:70)
at io.cucumber.core.runtime.Runtime.lambda$execute$5(Runtime.java:110)
at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:117)
at io.cucumber.core.runtime.Runtime.lambda$execute$6(Runtime.java:110)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:233)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at io.cucumber.core.runtime.Runtime.lambda$run$2(Runtime.java:86)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.SliceOps$1$1.accept(SliceOps.java:204)
at java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1351)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at io.cucumber.core.runtime.Runtime.run(Runtime.java:87)
... 2 more
I'm not sure what is going wrong as the same code worked with the previous version
This is a question related to upgrading to Cucumber 6, which has a different API, syntax and and architecture compared to Cucumber 2. You will need to rewrite many of the step definition methods, as the regular expressions used in Cucumber 2 will need updating, and the parameter conversion logic will also need updating (different classes are used).

Unable to open Browser in Selenium

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

Exception on starting Selenium with Firefox web driver

My code is the following:
startServer();
Integer port = 4545;
String browserString= "*firefox";
selenium = new DefaultSelenium("localhost",port,browserString, url) {
public void open(String url) { commandProcessor.doCommand("open", new String[] {url,"true"});};
};
logger.info("Start Selenium ");
selenium.start(); // <------ SeleniumException here
logger.info("Selenium started");
The stacktrace that I get is:
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:109)
at com.example.test.infrastruttura.util.SeleniumHolder.initAll(SeleniumHolder.java:55)
at com.example.test.infrastruttura.util.SeleniumHolder.<init>(SeleniumHolder.java:23)
at com.example.test.infrastruttura.util.SeleniumHolder.createInstance(SeleniumHolder.java:43)
at com.example.test.infrastruttura.util.SeleniumHolder.getInstance(SeleniumHolder.java:28)
at com.example.test.infrastruttura.util.SgateSeleneseTestCase.setUp(SgateSeleneseTestCase.java:38)
at com.example.sgate.test.selenium.GenericLogin.executeNavigation(GenericLogin.java:18)
at com.example.test.infrastruttura.checks.CheckObject.executeSelenium(CheckObject.java:424)
at com.example.test.infrastruttura.MainTestCase.executeNode(MainTestCase.java:312)
at com.example.test.infrastruttura.MainTestCase.execute(MainTestCase.java:244)
at com.example.test.infrastruttura.MainTestCase.execute(MainTestCase.java:157)
at com.example.sgate.test.functional.verificaEsitiAnagrafici.VerificaEsitiAnagrafici019AltroUtenteStessoComune.testComune(VerificaEsitiAnagrafici019AltroUtenteStessoComune.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:96)
at org.apache.maven.surefire.junit.JUnit3Provider.executeTestSet(JUnit3Provider.java:117)
at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:109)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:103)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:272)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:234)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:100)
... 39 more
I use selenium-java-2.40.0 and Firefox 26.
But the following code works:
WebDriver driver = new FirefoxDriver();
driver.get("http://myhostname:myport/myapplicationname");
WebElement userId = driver.findElement(By.name("userId"));
userId.sendKeys("coolusername");
WebElement password = driver.findElement(By.name("password"));
password.sendKeys("ultrasecretpassword");
password.submit();
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
So it is not a problem of Selenium version compatibility with Firefox.
Selenium tries to find some servlet at this URL:
http://localhost:4545/selenium-server/driver/
But receives a 404 error.
Ca you help me?
Ensure that the Firefox is installed in the default location. Optional you can give the absolute path to the browser:
String browserString = "c:\\program files\\mozilla firefox\\firefox.exe";
Check the source and documentation for more information.
However, I recommend to use the Driver (like in the working sample), if you don't want to provide a Selenium RC.
Looking at the source code of the DefaultSelenium class, you can notice that the alloweb browser strings are:
*webdriver
*firefox-wd
*iexplore-wd
So I wrote:
String browserString= "*firefox-wd";
And that fixed the problem.

Categories

Resources