I am facing a weird issue in my project while running it as I am coming across an issue org.openqa.selenium.chrome.ChromeOptions.setExperimentalOption. Actually, I had first stuck with NoClassDefError. To solve that I had put httpclient5 dependency explicitly in pom. Once I had put that, I started getting java.lang.NoSuchMethodError:org.openqa.selenium.chrome.ChromeOptions.setExperimentalOption
Below is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>corporate-action-tests-ui</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>corporate-action-parent</artifactId>
<groupId>com.mst.indexes</groupId>
<version>0.5.1-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<suitefile>SmokeSuite_stg.xml</suitefile>
<env>stg</env>
<browser>localChrome</browser>
<suite>Smoke</suite>
<test_region>us-west-2</test_region>
<updateBugInJira>false</updateBugInJira>
<updateTestRail>true</updateTestRail>
<updateReportPortal>false</updateReportPortal>
<quitBrowserAfterExecution>true</quitBrowserAfterExecution>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>com.mst.indexes</groupId>
<artifactId>ui-automation-base</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>tech.grasshopper</groupId>
<artifactId>extentreports-cucumber6-adapter</artifactId>
<version>2.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mst.indexes</groupId>
<artifactId>corporate-action-dto</artifactId>
<version>0.5.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/cisuite/${suitefile}</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<env>${env}</env>
<browser>${browser}</browser>
<suitefile>${suitefile}</suitefile>
<suite>${suite}</suite>
<test_region>${test_region}</test_region>
<updateBugInJira>${updateBugInJira}</updateBugInJira>
<updateTestRail>${updateTestRail}</updateTestRail>
<rp.enable>${updateReportPortal}</rp.enable>
<quitBrowserAfterExecution>${quitBrowserAfterExecution}</quitBrowserAfterExecution>
<webdriver.chrome.driver.cachePath>C:/Users/ppathar/.cache/selenium/chromedriver/win64/126.0.6478.126
</webdriver.chrome.driver.cachePath>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
We use a common framework ui automation base and there we have selenium and webdrivermanager dependencies defined
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.6.0</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
I tried hardcoding webdriver.chrome.driver.cachePath as shown to let webdriver use the chromedriver from my cache path but that too is not working. Even tried to hardcode browserversion with setbrowserversion("") method but then too I am getting the same error. Also tried excludting httpclient5 dependency from each of the dependencies.Even I updated the selenium version and webdrivermanager version. Still no success. Then too getting the same error. Can I have some solution for this? Nothing seems to work for us.
Below is the error stack trace
2024-07-10 07:50:22,622 level="INFO" class="i.g.bonigarcia.wdm.WebDriverManager" env="stg" description="Using chromedriver 126.0.6478.126 (resolved driver for Chrome 126)" 2024-07-10 07:50:22,667 level="INFO" class="i.g.bonigarcia.wdm.WebDriverManager" env="stg" description="Exporting webdriver.chrome.driver as C:\Users\ppathar.cache\selenium\chromedriver\win64\126.0.6478.126\chromedriver.exe"
java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.setExperimentalOption(Ljava/lang/String;Ljava/lang/Object;)Lorg/openqa/selenium/chrome/ChromeOptions;
at com.morningstar.indexes.ui.test.Base.initializeBrowserSetup(Base.java:87)
at com.morningstar.indexes.ui.test.Base.setUp(Base.java:173)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:61)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:366)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:320)
at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:701)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
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:1541)
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 com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:65)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)
Below is the code snippet used for initializing webdriver
case "localChrome":
WebDriverManager.chromedriver().setup();
ChromeOptions cp = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("download.default_directory", downloadsPath);
cp.setExperimentalOption("prefs", prefs);
if (headlessModeOn.equalsIgnoreCase("true")) {
cp.addArguments("--headless");
}
driver.set(new ChromeDriver(cp));
break;
mvn dependency:tree
command and see if there are any other selenium dependency along with3.141.59
? Going by the looks of it, there could be a conflicting dependency of the selenium webdriver4.1.4
dependency is the problem that you'll need to resolve. Basically, there are two dependencies in the class path one with 4.1.4 and another one that is3.141.59
which are conflicting with each other.