TestProject Forum

Exception in thread "main" org.openqa.selenium.WebDriverException: Failed to create an instance of io.testproject.sdk.drivers.web.ChromeDriver [OPEN]

Hi,

I am getting below issue when I run simple code.
Exception

Exception in thread “main” org.openqa.selenium.WebDriverException: Failed to create an instance of io.testproject.sdk.drivers.web.ChromeDriver
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘XXXXXXXXX’, ip: ‘XXXXXXXX’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘16.0.2’
Driver info: driver.version: unknown
at io.testproject.sdk.DriverBuilder.build(DriverBuilder.java:246)
at demotestproj.TestProj.main(TestProj.java:18)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at io.testproject.sdk.DriverBuilder.build(DriverBuilder.java:235)
… 1 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not “opens java.io” to unnamed module @158da8e
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
at com.google.gson.internal.reflect.UnsafeReflectionAccessor.makeAccessible(UnsafeReflectionAccessor.java:44)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:159)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at com.google.gson.Gson.getAdapter(Gson.java:458)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
at com.google.gson.Gson.getAdapter(Gson.java:458)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at com.google.gson.Gson.getAdapter(Gson.java:458)
at com.google.gson.Gson.toJson(Gson.java:696)
at com.google.gson.Gson.toJson(Gson.java:683)
at com.google.gson.Gson.toJson(Gson.java:638)
at com.google.gson.Gson.toJson(Gson.java:618)
at io.testproject.sdk.internal.rest.AgentClient.startSession(AgentClient.java:656)
at io.testproject.sdk.internal.rest.AgentClient.(AgentClient.java:275)
at io.testproject.sdk.internal.rest.AgentClient.getClient(AgentClient.java:547)
at io.testproject.sdk.drivers.web.ChromeDriver.(ChromeDriver.java:757)
… 7 more

Code

package demotestproj;

import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeOptions;

import io.testproject.sdk.DriverBuilder;
import io.testproject.sdk.drivers.web.ChromeDriver;

public class TestProj {

public static void main(final String[] args) throws Exception {
	ChromeDriver driver = new DriverBuilder<ChromeDriver>(new ChromeOptions())
			
			  .withRemoteAddress(new URL("http://localhost:8585/"))
			  .withToken("XXXXXXX")
			  .build(ChromeDriver.class);

// ChromeDriver driver = new ChromeDriver(new ChromeOptions());

    driver.navigate().to("https://example.testproject.io/web/");

    driver.findElement(By.cssSelector("#name")).sendKeys("John Smith");
    driver.findElement(By.cssSelector("#password")).sendKeys("12345");
    driver.findElement(By.cssSelector("#login")).click();

    boolean passed = driver.findElement(By.cssSelector("#logout")).isDisplayed();
    if (passed) {
        System.out.println("Test Passed");
    } else {
        System.out.println("Test Failed");
    }

    driver.quit();
}

}

Please help me to resolve this issue

=============================================

Hi Vaishnavi,

I was also getting the same error. Once I switched back to version 11 of JDK, it works fine.
I can see you are using java.version: ‘16.0.2’. Please uninstall it and install JDK 11.0 from the below site:-

Java SE Development Kit 11- - Downloads.

If you are using Eclipse and it fails to launch after the downgrade, please do update the vm value in the eclipse.ini