Chrome driver doesn't load resources in a page - selenium

I am trying to load a web page with Selenium 3 and chrome driver in a Docker container and I don't see the resources loading in there. Below is how the web page looks when I load it in the docker container. Chromedriver version here is 86
But when I load it from my local machine the web page loads fine with all the resources. Below is how the remote driver is initiated for execution in Docker.
Below is the list of ChromeOptions I use. (Casting here is because of multiple other browser options returned from this same method)
options = new ChromeOptions();
((ChromeOptions) options).setBinary("/opt/google/chrome/google-chrome");
((ChromeOptions) options).setAcceptInsecureCerts(true);
((ChromeOptions) options).addArguments("--no-sandbox", "--disable-dev-shm-usage");
((ChromeOptions) options).addArguments("--disable-extensions");
options.setCapability("browserVersion", "general");
Then instantiating the driver like this.
driver = new RemoteWebDriver(
url,
SeleniumHelper.getCapabilities("chrome",
myGrid.getForwardProxy()));
What am I doing wrong here? Why aren't the resources loading? Any help would be much appreciated.

Related

Selenium Firefox Headless Connect Remote Debugger

I am running a headless firefox browser with Selenium. If I run it in GUI mode then it works fine but when I run it in headless mode then I get an error about element being obstructed.
I really need a way to connect the Firefox remote debugger so I can see what is happening in the headless browser.
How do I enable remote debugging in selenium headless browser?
You can debug marionette Gecko Driver by enabling trace logs and change the log level in order to get trace logs:
You can use FirefoxOptions in Selenium Java client to change the log level
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.TRACE);
WebDriver driver = new FirefoxDriver(options);
For more information have a look at Firefox Source docs. More reading about debugging is here

Use RemoteWebDriver to test localhost

Very new to Selenium testing and after reading the doc I tried to setup my own Selenium Grid Hub but I'm failing to use it for my local testing.
I setup the Selenium Grid Hub on a kubernetes cluster (following https://github.com/kubernetes/examples/tree/master/staging/selenium) and I manage to reach my nodes.
I've built a simple java application to test this is working as expected and I manage to reach web based url like http://www.google.com but I would like to be able to test my local app by using my RemoteWebDriver.
Here is what is actually working:
log.info("test selenium");
ChromeOptions chromeOptions = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(new URL("http://my-k8-node.com:32223/wd/hub"), chromeOptions);
driver.get("http://www.google.com");
String pageSource = driver.getPageSource();
log.info(pageSource);
driver.quit();
But I get a This site can't be reached - localhost refused to connect. with
driver.get("http://localhost:8080/health/check");
The same with
driver.get("http://host.docker.internal:8080/health/check");
Or with
driver.get("http://127.0.0.1:8080/health/check");
I didn't find any documentation on how to achieve this kind of setup but any hint is welcome.
I would like to further integrate the selenium testing to my Gitlab CI/CD so I should be able to run the test from a "local" point of view.
Thanks for reading.

UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server with Selenium Grid

Error in opening new driver window:
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
server log:
Forwarding newSession on session null to remote
I am running following code on linux:
driver= new RemoteWebDriver((new URL( "http://"+ip+":5555/wd/hub")), capability);
My hub-node already up and running. Then why i am getting this error.
This error message...
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
and the server log...
Forwarding newSession on session null to remote
...implies that the Selenium Grid Hub / Selenium Grid Node wasn't properly initiated/started. As a result a null session was forwarded to the RemoteWebDriver.
Some more information regarding the versions of the binaries which you have used interms of Selenium server/client, WebDriver variant /version and WebBrowser variant /version and the commands you have used to initiate the Selenium Grid Hub / Selenium Grid Node would have helped us to debug your issue in a easier way.
However this issue can happen due to multiple factors as follows:
You are using the uri 5555/wd/hub, so ensure that Selenium Grid Hub is initiated on port 5555.
You may opt to replace the capability argument with an instance of Options class as follows:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browser", "chrome");
//seting the required capabilities
ChromeOptions options = new ChromeOptions();
options.merge(caps);
WebDriver driver = new RemoteWebDriver((new URL( "http://"+ip+":5555/wd/hub")), options);
You can find a relevant discussion in Remote WebDriver UnreachableBrowserException: Could not start a new session
This issue is frequently observed with GeckoDriver/Selenium/Mozilla due to version mismatch of the binaries you are using. As a thumb rule always follow the configuration matrix from the GeckoDriver, Selenium and Firefox Browser compatibility chart
You can find a relevant discussion in WebDriverException: Message: newSession with GeckoDriver Firefox v65 and Selenium through Python 3.7

webGL dependent application in opening in chrome

I have a situation here that we have a webGL dependent application to automate. i have automated the whole application on my laptop, and this application is running fine on chrome on my laptop. but the issue is when i run this application from a seperate machine which is a selenium GRID node. It gives me a message that the application required Webgl and and it ask me to enable the webGL. i have tried different methods like selenium option and ignoring the chrome black list as well.
when i open the browser manually and open the application it runs find and i checked on url chrome://gpu. it shows that the gpu is enaled.
but when i invoke the selenium and run the test cases,. the browser initiates with WebGl as disabled
i found the solution to this. here is the code you can use to enable WebGL for chrome.
DesiredCapabilities capability = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
**options.addArguments("--ignore-gpu-blacklist");**
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capability.setCapability("chrome.binary", "C:\\Temp\\chromedriver.exe");
capability.setVersion("9999");
capability.setCapability(ChromeOptions.CAPABILITY, options);
return new RemoteWebDriver(HUB_URL,capability);

Proxy configuration in Internet Explorer using selenium webdriver

I want to set some proxy setting in internet explorer with the help of webdriver.
Currently I am using this code :
System.setProperty("webdriver.ie.driver", "Path to IEDriverServer.exe");
Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("proxyhost:port");
DesiredCapabilities capability = new DesiredCapabilities();
capability.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName());
capability.setCapability(CapabilityType.PROXY, proxy);
driver=new InternetExplorerDriver(capability);
But it does nothing except giving this message on console :
org.openqa.selenium.browserlaunchers.WindowsProxyManager backupRegistrySettings
INFO: Backing up registry settings...
I have done the settings related to zone and all which are necessary for using IEDriver.
I am able to use Internet explorer through webdriver without using Proxy configuration.
I am using IE9 on Windows 7 with IEDriver.exe version 2.28.0.
Can somebody suggest me some work around for this.Any help is much appreciated.
Possible workaround : Set the PAC file manually in IE. Simply launch the IEdriver. The bad part is is you would keep switching it if u use IE for surfing..