I am using desired chrome capabilitiees to launch my chrome browser and perform my E2E test but getting below warnings :
WARNING: Support for Legacy Capabilities is deprecated; You are sending the following invalid capabilities: [accessKey, testName, unexpectedAlertBehaviour]; Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/
May 03, 2023 12:05:28 AM org.openqa.selenium.remote.ProtocolHandshake createSession
WARNING: Support for Legacy Capabilities is deprecated; You are sending the following invalid capabilities: [accessKey, testName, unexpectedAlertBehaviour]; Please update to W3C Syntax: https://www.selenium.dev/blog/2022/legacy-protocol-support/
To resolve this warning message I have updated my code as below with the help of ChromeOptions but after doing that I was facing performance issue while executing my test. Initially test was taking 4 mins but now same test is taking more than 15 mins.
I am not sure what it is I need to do further. Can someone help me please? Here is the code so far I have got:
import io.github.bonigarcia.wdm.WebDriverManager;
import io.github.bonigarcia.wdm.config.DriverManagerType;
import io.github.bonigarcia.wdm.managers.ChromeDriverManager;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.thucydides.core.environment.SystemEnvironmentVariables;
import net.thucydides.core.util.EnvironmentVariables;
import org.apache.commons.lang3.SystemUtils;
import org.jetbrains.annotations.NotNull;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.UnreachableBrowserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@AllArgsConstructor
public class ChromeDriver implements WrappedWebDriver {
private static final Logger logger = LoggerFactory.getLogger(ChromeDriver.class);
static String accessKey = System.getenv().get("access_key");
@NotNull
private static ChromeOptions getChromeOptions() {
final ChromeOptions chromeOptions = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("googlegeolocationaccess.enabled", false);
prefs.put("profile.default_content_setting_values.geolocation", 2); // 1:allow 2:block
prefs.put("profile.default_content_setting_values.notifications", 1);
prefs.put("profile.managed_default_content_settings", 1);
prefs.put("download.default_directory", System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "TestData" + File.separator + "clsp" + File.separator + "Downloads");
chromeOptions.setExperimentalOption("prefs", prefs);
chromeOptions.setAcceptInsecureCerts(true);
chromeOptions.addArguments(
"--ignore-certificate-errors",
"--disable-download-notification",
"--no-sandbox",
"--disable-site-isolation-trials",
"--enable-strict-powerful-feature-restrictions",
"--disable-geolocation",
"--disable-gpu",
"--disable-dev-shm-usage"
);
if (SystemUtils.IS_OS_LINUX) {
chromeOptions.addArguments(
"--headless",
"--allow-running-insecure-content",
// "--disable-web-security",
"--window-size=1920,1080"
);
} else if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_WINDOWS) {
chromeOptions.addArguments(
"--incognito",
"--start-fullscreen"
);
}
return chromeOptions;
}
@Override
public WebDriver newDriver() {
RemoteWebDriver driver = null;
final ChromeOptions chromeOptions = new ChromeOptions();
EnvironmentVariables environmentVariables = SystemEnvironmentVariables.createEnvironmentVariables();
boolean remote = Boolean.parseBoolean(environmentVariables.getProperty("remote"));
String serverAddress = environmentVariables.getProperty("experitest.server");
ChromeDriverService service;
try {
binarySetup();
service = new ChromeDriverService.Builder()
.usingAnyFreePort()
.build();
service.start();
chromeOptions.setCapability(CapabilityType.BROWSER_VERSION, "112");
chromeOptions.setCapability(ChromeOptions.CAPABILITY, getChromeOptions());
chromeOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.ACCEPT);
chromeOptions.setCapability("", "Test Execution");
chromeOptions.setCapability("accessKey", XXXX);
chromeOptions.setCapability("acceptInsecureCerts", true);
driver = new RemoteWebDriver(new URL(serverAddress), chromeOptions);
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15));
} catch (Exception e) {
logger.error("Error due to " + e.getMessage());
throw new UnreachableBrowserException(e.getMessage());
}
return driver;
}
private void binarySetup() {
try {
if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_LINUX) {
logger.info("driver binary setup started...");
ChromeDriverManager.getInstance(DriverManagerType.CHROME).setup();
WebDriverManager.chromedriver().setup();
} else {
System.getenv();
}
} catch (Exception e) {
logger.info("Driver binary not setup correctly...");
e.printStackTrace();
}
}
@Override
public boolean takesScreenshots() {
return true;
}
}
right now chromium --headless=new
, which is the new headless mode is facing performance issues:
Chromium issues1
This might be the problem for you as well. A solution would be to use old headless mode, but this won't download or copy text in your tests. This is an issue if you are running tests that interact with external files for example.