java.lang.Exception: Test class should have exactly one public constructor java.lang.Exception: Test class should have exactly one public constructor selenium selenium

java.lang.Exception: Test class should have exactly one public constructor


private WebDriverTest(String os, String version, String browser) { super(); this.os= os; this.version= version; this.browser= browser;}

should be

public WebDriverTest(String os, String version, String browser) { super(); this.os= os; this.version= version; this.browser= browser;}


Point to rememeber while writing JUnit is that while execution it calls constructor of test class before executing test method. You can verify it by putting a System.out.println message in constructor itself

Here in your code you have defined your constructor as private so the test framework will not be able to instantiate your test class for test methods execution change the scope to public.

public WebDriverTest(String os, String version, String browser) { super(); this.os= os; this.version= version; this.browser= browser;}


I got this error while trying to run the unit test in Eclipse, and it turned out that the problem was Eclipse. Running it from the command line using gradle returned a different error - that another unit test was invalid. Fixing the other invalid test fixed this error. Thanks a lot, Eclipse!