-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
-
I am trying to see the activities that are happening in my container using VNC but instead I am getting a blank screen showing nothing.... tried to set my tests to run in non-headless mode but I am still getting the same view... please assist
Beta Was this translation helpful? Give feedback.
All reactions
Yes, I see. But I saw something might happen in your code
GetChromeOptions(testConfig.DriverSettings.Headless) is underif (testConfig.DriverSettings.Debugging). What if not in debug mode? or the config is not retrieved correctly?
GetChromeOptions(bool isHeadless = true), can you change this default to false and see how it behaves?
Replies: 1 comment 11 replies
-
Can you share the session capabilities (which can be seen on GUI, click on (I) button in view Sessions)
Beta Was this translation helpful? Give feedback.
All reactions
-
No, this is session caps detail image
Hi @VietND96.... were you able to troubleshoot the issue at hand?
Beta Was this translation helpful? Give feedback.
All reactions
-
No clue is found from session caps.
Can you share code snippet to reproduce? Or are you using on top of a framework which control to creat a session?
Beta Was this translation helpful? Give feedback.
All reactions
-
I am using Selenium, Selenium Grid, Xunit and Reqnroll.
this is my selenium code setup:
using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Edge; using OpenQA.Selenium.Remote; using OpenQA.Selenium.Support.UI; using Webtrack.AutomationTests.Services.TestConfig; using Webtrack.AutomationTests.WebDriverManagement.WebtrackDriver.Options; using Webtrack.AutomationTests.WebDriverManagement.WebtrackDriver.Waiters; using Webtrack.AutomationTests.WebDriverManagement.WebtrackDriver.Windows; namespace Webtrack.AutomationTests.WebDriverManagement.WebtrackDriver; public class WebtrackWebDriver : IWebtrackWebDriver { private readonly static ThreadLocal<IWebDriver> _threadDriver = new(); public IWebDriver Driver => _threadDriver.Value!; public WebDriverWait Wait { get; private set; } public WebDriverWaiters Waiters { get; private set; } public WebDriverWindows Windows { get; private set; } public void InitializeDriver(string browser, TestConfiguration testConfig) { try { if (testConfig.DriverSettings != null) { if (testConfig.DriverSettings.Debugging) { _threadDriver.Value = browser.ToLowerInvariant() switch { "chrome" => new ChromeDriver(WebDriverOptions.GetChromeOptions(testConfig.DriverSettings.Headless)), "edge" => new EdgeDriver(WebDriverOptions.GetEdgeOptions(testConfig.DriverSettings.Headless)), _ => throw new NotSupportedException($"Browser '{browser}' not supported. Supported browsers are: Chrome and Edge.") }; } else { DriverOptions options = browser switch { "chrome" => WebDriverOptions.GetChromeOptions(), "edge" => WebDriverOptions.GetEdgeOptions(), _ => throw new ArgumentException("Invalid browser type.", nameof(browser)) }; if (string.IsNullOrEmpty(testConfig?.GridUrl)) { throw new InvalidOperationException("Grid URL is not specified in the configuration."); } _threadDriver.Value = new RemoteWebDriver(new Uri(testConfig.GridUrl), options); } _threadDriver.Value.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(testConfig.DriverSettings.ImplicitWait); Wait = new WebDriverWait(_threadDriver.Value, TimeSpan.FromSeconds(testConfig.DriverSettings.PageLoadTimeout)); Waiters = new WebDriverWaiters(_threadDriver.Value, TimeSpan.FromSeconds(testConfig.DriverSettings.PageLoadTimeout)); Windows = new WebDriverWindows(_threadDriver.Value, TimeSpan.FromSeconds(testConfig.DriverSettings.PageLoadTimeout)); } else throw new InvalidOperationException("TestSettings configuration is missing."); } catch (InvalidOperationException) { throw; } catch (ArgumentException) { throw; } catch (NotSupportedException) { throw; } } public void DisposeDriver() { if (_threadDriver.Value != null) { _threadDriver.Value.Quit(); _threadDriver.Value.Dispose(); } } public string CaptureScreenshot() { if (Driver == null) { return string.Empty; } var basePath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..\\..\\..\\")); var screenshotDirectory = Path.Combine(basePath, "Screenshots"); if (!Directory.Exists(screenshotDirectory)) { Directory.CreateDirectory(screenshotDirectory); } string timestamp = DateTime.Now.ToString("yyyy_MM_dd-HH_mm_ss"); string filePath = Path.Combine(screenshotDirectory, $"screenshot_{timestamp}.png"); ((ITakesScreenshot)Driver).GetScreenshot().SaveAsFile(filePath); return filePath; } }
these are the options I am using:
using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Edge; namespace Webtrack.AutomationTests.WebDriverManagement.WebtrackDriver.Options; public static class WebDriverOptions { public static ChromeOptions GetChromeOptions(bool isHeadless = true) { var options = new ChromeOptions(); // General Chrome Browser Options if (isHeadless) { options.AddArgument("--headless"); } options.AddArgument("--start-maximized"); options.AddArgument("--disable-autofill"); options.AddArgument("--disable-infobars"); options.AddArgument("--disable-extensions"); // Add excluded argument options.AddExcludedArgument("enable-automation"); // Disable cache options.AddArgument("--disable-cache"); // Disable cache options.AddArgument("--disable-application-cache"); // Disable application cache options.AddArgument("--disk-cache-size=0"); // Set disk cache size to 0 options.AddArgument("--disable-dev-shm-usage"); // Address shared memory issues options.AddArgument("--no-sandbox"); // Avoid sandboxing issues options.AddArgument("--disable-gpu"); // Disable Password Manager options.AddArgument("--disable-save-password-bubble"); options.AddUserProfilePreference("credentials_enable_service", false); options.AddUserProfilePreference("profile.password_manager_enabled", false); return options; } public static EdgeOptions GetEdgeOptions(bool isHeadless = true) { var options = new EdgeOptions(); // General Edge Browser Options if (isHeadless) { options.AddArgument("--headless"); } options.AddArgument("--start-maximized"); options.AddArgument("--disable-autofill"); options.AddArgument("--disable-infobars"); options.AddArgument("--disable-extensions"); options.AddExcludedArgument("enable-automation"); // Disable cache options.AddArgument("--disable-cache"); // Disable cache options.AddArgument("--disable-application-cache"); // Disable application cache options.AddArgument("--disk-cache-size=0"); // Set disk cache size to 0 options.AddArgument("--disable-dev-shm-usage"); // Address shared memory issues options.AddArgument("--no-sandbox"); options.AddArgument("--disable-gpu"); // Disable Password Manager options.AddUserProfilePreference("credentials_enable_service", false); options.AddUserProfilePreference("profile.password_manager_enabled", false); // Disable Save Password Bubble options.AddArgument("--disable-save-password-bubble"); return options; } }
Note: IsHeadless is set to false in my config file
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes, I see. But I saw something might happen in your code
GetChromeOptions(testConfig.DriverSettings.Headless) is underif (testConfig.DriverSettings.Debugging). What if not in debug mode? or the config is not retrieved correctly?
GetChromeOptions(bool isHeadless = true), can you change this default to false and see how it behaves?
Beta Was this translation helpful? Give feedback.
All reactions
-
this is my config file:
{
"WebDriverSettings": {
"ImplicitWait": 5, // In seconds
"PageLoadTimeout": 60, // In seconds
"Debugging": false,
"Headless": false
},
}When I set debugging to true it will run my tests locally on my machine and with headless set to false the browser will instantiate locally for me to see what is happening visually.
When debugging is set to false it will run my tests in selenium grid using the remote web driver with headless set to false but then when checking the session video I just get that blank screen..... I tried to explicitly set it to false but it still doesnt work
Beta Was this translation helpful? Give feedback.
All reactions
-
I will try removing the that assignment and have the config take complete control.... I only put it there because I wanted to ensure that the tests run in headless mode when running in my CI environment.... with the session video being handled in the grid now I will just make it work directly with the config without assigning a default value
Beta Was this translation helpful? Give feedback.
All reactions
-
I will try removing the that assignment and have the config take complete control.... I only put it there because I wanted to ensure that the tests run in headless mode when running in my CI environment.... with the session video being handled in the grid now I will just make it work directly with the config without assigning a default value
Thanks for pointing it out, I didnt notice that the GetChromeOptions() for the remote driver was not parsed the config values which defaulted to true.... I have added the config value and its working now....
Beta Was this translation helpful? Give feedback.
All reactions
-
if (testConfig.DriverSettings.Debugging) { _threadDriver.Value = browser.ToLowerInvariant() switch { "chrome" => new ChromeDriver(WebDriverOptions.GetChromeOptions(testConfig.DriverSettings.Headless)), "edge" => new EdgeDriver(WebDriverOptions.GetEdgeOptions(testConfig.DriverSettings.Headless)), _ => throw new NotSupportedException($"Browser '{browser}' not supported. Supported browsers are: Chrome and Edge.") }; } else { DriverOptions options = browser switch { // Config values were not being passed to the methods therefore defaulting to true "chrome" => WebDriverOptions.GetChromeOptions(), "edge" => WebDriverOptions.GetEdgeOptions(), _ => throw new ArgumentException("Invalid browser type.", nameof(browser)) }; if (string.IsNullOrEmpty(testConfig?.GridUrl)) { throw new InvalidOperationException("Grid URL is not specified in the configuration."); } _threadDriver.Value = new RemoteWebDriver(new Uri(testConfig.GridUrl), options); }
Beta Was this translation helpful? Give feedback.