I'm writing simple test cases for automatization of testing web app. Installed Maven in my VS Code, I guess made everything correct (since mvn -version returns Apache Maven 3.8.7...). Created project and tried to write some sort of setUp for WebDriver. The thing is that it calls error and I can't understand why.
Full Code:
package com.pocselenium;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import org.junit.jupiter.api.*;
import org.openqa.selenium.edge.*;
import org.openqa.selenium.remote.service.DriverFinder;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
public class LogInTestCase {
WebDriver webDriver;
@BeforeEach
public void setUp()
{
System.setProperty("webdriver.edge.driver", "C:\\Users\\MyUser\\Documents\\GitCloneJava\\PocSelenium\\javapoc\\msedgedriver.exe");
EdgeOptions options = new EdgeOptions();
options.addArguments("user-data-dir=C:\\Users\\MyUser\\Documents\\GitCloneJava\\PocSelenium\\javapoc\\User Data");
options.setBrowserVersion("stable");
DriverFinder finder = new DriverFinder(ChromeDriverService.createDefaultService(), options);
File driverPath = new File(finder.getDriverPath());
File browserPath = new File(finder.getBrowserPath());
EdgeDriverService service = new EdgeDriverService.Builder().usingDriverExecutable(driverPath).build();
//EdgeDriverService service = new EdgeDriverService.Builder().withLogOutput(System.out).build(); //Output of error to the console
options.setBinary(browserPath);
webDriver = new EdgeDriver(service, options);
assertTrue(webDriver != null);
}
@Test
public void logInTest()
{
webDriver.get("https://www.google.com");
}
}
Full Error:
[ERROR] Errors:
[ERROR] LogInTestCase.setUp:35 » SessionNotCreated Could not start a new session. Response code 500. Message: session not created: Microsoft Edge failed to start: crashed.
(chrome not reachable)
(The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so msedgedriver is assuming that msedge has crashed.)
Host info: host: 'HOSTNAME', ip: 'xx.xx.xx.xx'
Build info: version: '4.20.0', revision: '866c76ca80'
System info: os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.23'
Driver info: org.openqa.selenium.edge.EdgeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: MicrosoftEdge, browserVersion: stable, ms:edgeOptions: {args: [user-data-dir=C:\Users\MyUser...], binary: C:\Program Files (x86)\Micr..
., extensions: []}}]}]
P.S.: Versions of used technologies: Maven - Apache Maven 3.8.7 Java - openjdk version "21.0.3" 2024-04-16 LTS OpenJDK Runtime Environment Microsoft-9388422 (build 21.0.3+9-LTS) OpenJDK 64-Bit Server VM Microsoft-9388422 (build 21.0.3+9-LTS, mixed mode, sharing) Selenium - 4.20.0
I have already checked versions both of Edge and Driver, downloaded new Driver couple times, changed paths to Driver and Edge, killed all Microsoft Edge processes, tried to find out where is exception raised step-by-step (I guess it has something to deal with ClassLoader).
So the solution was to add next lines:
options.addArguments("--no-sandbox");
options.addArguments("--remote-debugging-port=9222");
options.addArguments("--disable-dev-shm-usage");
and change content of setBrowserVersion()
to appropriate version of browser.
Important: those must be the very first arguments passed. Solution was combined out of proposed solution on this post