i wrote a class for signing up with social network testing on java (17) + testng (7.6.0) + selenium (4.3.0):
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.Test;
public class ChromeOK extends OKTest {
public void chromeOKTest() throws InterruptedException {
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.setAcceptInsecureCerts(true);
//options.setCapability("acceptInsecureCerts", true);
WebDriver driverChrome = new ChromeDriver(options);
run(driverChrome);
}
}
implementing the OKTest, containing a run() method:
//buttons xpaths
...
public void run(WebDriver driver) throws InterruptedException {
driver.get("https://ezochat.com");
sleep(5000);
//driver.findElement(btnReject).click();
driver.findElement(btnLogIn).click();
sleep(10000);
driver.findElement(btnOK).click();
sleep(10000);
driver.findElement(inputOKPhone).sendKeys(okPhone);
driver.findElement(inputOKPassword).sendKeys(okPass);
sleep(2000);
driver.findElement(btnJoinOK).click();
sleep(10000);
try {
if (driver.findElements(btnDeposit).isEmpty()) throw new InterruptedException("Ошибка авторизации через ОК");
} catch (InterruptedException e) {
driver.quit();
System.err.println("Ошибка авторизации через ОК");
System.exit(1);
}
driver.quit();
}
works just fine if it runs without the --headless specification but once i enable the headless mode, an error comes up when trying to open the domain (the first row in the run() method):
driver.get("https://ezochat.com")).
here's what is listed in console:
INFO: Found exact CDP implementation for version 103
org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'YAROSLAV', ip: '192.168.0.106', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '17.0.3'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [9630c7c8a9fa207edfd40b72d669c654, get {url=https://ezochat.com/}]
Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 103.0.5060.114, chrome: {chromedriverVersion: 103.0.5060.53 (a1711811edd7..., userDataDir: C:\Users\SMM-MA~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:59380}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:59380/devtoo..., se:cdpVersion: 103.0.5060.114, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 9630c7c8a9fa207edfd40b72d669c654
at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:65)
at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
at org.openqa.selenium.remote.http.netty.NettyHttpHandler.execute(NettyHttpHandler.java:49)
at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
at org.openqa.selenium.remote.http.netty.NettyClient.execute(NettyClient.java:98)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:181)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:332)
at OKTest.run(OKTest.java:25)
at ChromeOK.chromeOKTest(ChromeOK.java:18)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:677)
at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221)
at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:962)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:806)
at org.testng.TestRunner.run(TestRunner.java:601)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:433)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:427)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:387)
at org.testng.SuiteRunner.run(SuiteRunner.java:330)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
at org.testng.TestNG.runSuites(TestNG.java:1099)
at org.testng.TestNG.run(TestNG.java:1067)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: java.util.concurrent.TimeoutException
at java.base/java.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1960)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2095)
at org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:206)
at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:59)
... 40 more
tried to look up for the solution, usually the problem is with incompatibility of browser and the driver - which is not my case, im using 103 version of both. tried to run with the following specifications:
options.addArguments("--headless", "--disable-gpu", "--ignore-certificate-errors","--disable-extensions","--no-sandbox","--disable-dev-shm-usage");
and the options.setCapability("acceptInsecureCerts", true);, doesn't change anything.
console shows networkConnectionEnabled: false, maybe that's where the problem is, however i couldn't find anything useful about that.
UPDATE
i just realised where the problem is. tried to run a different test (basic sign up), which goes to one site (email-address generator), copies email there and goes to my site (ezochat.com). it reaches the first site, test works perfectly as it should but once the email is copied and it goes to https://ezochat.com - there's just " :data" in the address bar and for about 2 minutes or so it just doesnt open this exact website.
the funny thing is that it works in none-headless mode on chrome and on both modes on firefox - the exact same test (except the FirefoxOptions and FirefoxDriver declarations) that for some reason cant reach the website on one browser and reaches it fine on the other. here's what the console shows after the working firefox test:
[GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at C:\\Users\\SMM-MA~1\\AppData\\Local\\Temp\\rust_mozprofileR8aufg\\search.json.mozlz4", (void 0)))
DevTools listening on ws://localhost:53331/devtools/browser/5a1b32cc-a83a-46b6-ae68-820b44577746
июл. 11, 2022 6:48:21 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected upstream dialect: W3C
JavaScript error: https://www.googletagmanager.com/gtm.js?id=GTM-5FQMLW, line 35: uncaught exception: [object Object]
JavaScript error: https://ezochat.com/ line 42 > injectedScript, line 1: ReferenceError: queueManager is not defined
JavaScript warning: https://mc.yandex.ru/metrika/tag.js, line 18: WEBGL_debug_renderer_info is deprecated in Firefox and will be removed. Please use RENDERER.
console.warn: LoginRecipes: "getRecipes: falling back to a synchronous message for:" "https://ezochat.com"
console.warn: LoginRecipes: "getRecipes: falling back to a synchronous message for:" "https://ezochat.com"
JavaScript error: resource://gre/modules/LoginManagerParent.jsm, line 136: TypeError: gRecipeManager is null
1657540176300 Marionette INFO Stopped listening on port 64272