1

I was having issues with running Selenium tests. I finally found a solution about adding an extra dependency and a line of code to be run before the tests as per https://stackoverflow.com/a/75722029/12865183

Dependency:

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-http-jdk-client</artifactId>
<version>4.5.0</version>
</dependency>

Line of code:

System.setProperty("webdriver.http.factory", "jdk-http-client");

Finally my current testing setup looks like that:

public class seleniumTest {

WebDriver driver;

@BeforeEach
void setup(){

    System.setProperty("webdriver.http.factory", "jdk-http-client");
    driver = WebDriverManager.chromedriver().create();
}

@AfterEach
void teardown(){
    driver.quit();
}

@Test
void test(){
}

}

I wanted to ask if there is a way to set the System property permanently? Meaning for the code not to need the System.setProperty bit each time it's run.

I found the idea.vmoptions and idea.properties files within my InteliJ package contents (Using MacOS BigSur) but I am not sure what syntax would I use to set up System properties there and if it's possible at all.

CowOO
  • 31
  • 1
  • 6
  • 1
    Don't touch idea.vmoptions for this, it's *only* for setting VM options for *the VM that runs IDEA*. That is entirely unrelated to anything that runs your code. Depending on how you launch your code you can either set the system property in the run confication (you might have to enable VM options explicitly in the dialog) or in your build tool configuration (Maven/Gradle). – Joachim Sauer Mar 14 '23 at 14:47
  • 1
    See if this helps: https://stackoverflow.com/questions/29454494/set-java-system-properties-in-intellij-or-eclipse – Mate Mrše Mar 14 '23 at 14:48
  • Thank you both. That allowed me to find the solution – CowOO Mar 14 '23 at 17:14

1 Answers1

1

It was possible to set the system properties with use of Maven Surefire Plugin. Adding below to my pom file sorted it out and now all of the tests are running fine without setting up the property each time I run it.

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <systemPropertyVariables>
                    <webdriver.http.factory>jdk-http-client</webdriver.http.factory>
                    <buildDirectory>${project.build.directory}</buildDirectory>
                </systemPropertyVariables>
            </configuration>
        </plugin>
CowOO
  • 31
  • 1
  • 6