Disable image in Selenium ChromeDriver - node.js

Is there a way to disable images in Chromedriver with Javascript ( Node.js )? I couldn't find a proper answer to this question anywhere!

I do realise this question is quite old, but still - it is the first Google search result for the node chromedriver disable images query. So I decided to give it a go anyway.
I don't know the exact setup the OP was trying to use, so I'll refer to my own. I'm using nightwatch.js with pre-built Selenium running chromedriver. In my nightwatch.conf.js file I have the following setup for the chromedriver:
module.exports = {
"test_settings": {
"default": {
...
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions": {
"args": ["disable-web-security"],
"prefs": {
"profile.managed_default_content_settings.images": 2
}
}
}
}
}
};
The setup above works with
"chromedriver": "^2.21.2",
"selenium-server": "^2.53.0"
and is running Chrome 51.0.2704.84 stable.
I hope that helps someone, as I lost about 3 hours trying to come up with this solution.

Related

Adding browser info into cypress cucumber preprocessor report

I'm currently trying cypress-cucumber-preprocessor in our application test suite.
Even if it seems there is no additional parameter except below ones:
"cypress-cucumber-preprocessor": {
"cucumberJson": {
"generate": true,
"outputFolder": "cypress/cucumber-json",
"filePrefix": "",
"fileSuffix": ".cucumber"
}
}
I was wondering if there's any chance to have info about browser, browser version and maybe the os where test have been executed into the .cucumber.json generated files.
Thanks for your replies

Angular 8 - GET styles.js net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK) when served over USB

I am using ng serve to run an Angular 8 project locally. The total bundle size is around 7 MB, and it loads with no trouble on the desktop machine where it's hosted.
However, when connecting a phone via USB and using port forwarding (for localhost:4200), the website frequently fails to load completely. The error reported by Chrome is:
GET http://localhost:4200/styles.js net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)
This error was logged in https://github.com/angular/angular-cli/issues/7197, and is now marked as resolved. However, even with Angular CLI and NodeJS both up-to-date (Angular CLI v8.3.18 using Node v10.15.0) the error persists. It appears to be caused by the Angular Live development server timing out while serving its assets.
It occurs at random, but especially after a code change it can occur over 90% of the time. Reloading the site and re-running ng serve do not generally fix the issue. It appears to occur more frequently on browsers other than Chrome.
If the error is caused by a timeout in the Angular development server, how can I increase that timeout? If not, how can I prevent this error?
A temporary solution that is working for me is refresh the page multiple times until the vendor.js and main.js files are downloaded.
This issue took me a while to debug and to fix, hopefully this can help someone else. This bug appeared with NodeJS v8, and it still happens with Angular 14 and nodeJS 18.
This issue happens because the download speed of your device is limited, and the server raises a timeout to break the connection before the necessary angular js files are downloaded. This issue can happen over USB but also inside the Android Studio AVD emulator (my case). It can be reproduced artificially on a desktop computer by using the Chrome browser DevTools > Network > enable "Disable Cache" and set "Throttling" to "Slow 3G", then try to access your locally served webapp.
The major issue is that ng serve does not offer a way to manually set the timeout, so it is set to a constant time for all. As is written in the github issue you linked to, there used to be a workaround but only for nodejs 8, which was since then dropped and anyway never applied to any further versions, so it was only a temporary fix.
The solution is to serve the Angular web app manually, so that you can either:
minify js files, so that they are small enough to be downloaded fast.
ng serve --configuration production --watch
In angular.json, the production configuration should be something like this:
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"myproject": {
"architect": {
"build": {
"configurations": {,
"production": {
"baseHref": "",
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": {
"scripts": true,
"styles": {
"minify": true,
"inlineCritical": false
},
"fonts": true
},
"outputHashing": "all",
"sourceMap": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"serviceWorker": false
}
}
}
}
}
}
}
serve the pre-built app using your own server (not ng serve), so that you can disable timeouts.
In one terminal, launch the following to build the app and monitor changes:
ng build --watch
In a separate terminal (while the first one is running), launch the HTTP server with the following (-t0 disables timeouts):
http-server ./dist -p <port> -t0
PS: if you are trying to access the Angular app from inside the Android emulator, make sure to either use the WebView Browser Tester app, or enable the network permission to access HTTP cleartext addresses for your Android app.

disable jshint for project using Sublime 3

I have a project in which I'm using standard as the default linter, according to sublimeLinter documentation y need to create a .sublime-project file with the following info:
{
"folders":
[
{
"path": "."
}
],
"SublimeLinter":
{
"linters":
{
"jshint": {
"disable": true
}
}
}
}
however this isn't working, I've tried using both disable and #disable, created a .sublimelinterrc file with the same info, also tried with a .sublime-workspacefile, didn't worked, created a .jshintignore... didnt work.
Until now, the only thing that has worked is using this line in top of the file // jshint ignore: start but I don't want to write this in every single file, I want to disable it for all the project. Any idea of how can I do it?
As mentioned by OdatNurd the file won't do nothing by itself, it has to be loaded through the sublime project option in menu.
There is a newer, easier syntax for this. In your sublime project file add the following under settings.
{
"settings":
{
"SublimeLinter.linters.jshint.disable": true
}
}

intern chromeOptions.args window-size seemingly not working

i'm requiring a capabilities.js file with an object to my intern suites so i can specify which environments to use for various tests. here is my default chrome:
chrome: {
browserName: 'chrome',
chromeOptions: {
args: [
// 'start-maximized',
'window-size=1024x768'
]
}
}
from this i'd expect something like environments: [caps.chrome] to open a browser window that is 1024x768. I need to specify window size in a per-environment way. (also, start-maximized isn't working- though i do have several mobile emulators set up and doing well).
I did find this which seems to hint that it won't work on a mac. can anyone confirm?
However, the issue linked in the question has been closed for some time.
Arguments not being applied to Google chromedriver in Selenium with python
I use these configs to control windows size on windows, should work on Mac too.
"chromeOptions": {
"args": [
"--window-size=800,600"
]
"chromeOptions": {
"args": [
"--start-maximized"
]

Set proxy in nightwatch.js

I'm writing Integration Tests using nightwatch.js in a Node.js application. For a particular test case, I want nightwatch to connect via a proxy. What would be the right way to do this? I can't find anything from its official documentation, or from its Google Group.
The Selenium documentation suggests setting it on the webdriver instance as described here. I'm not sure how to do this via nightwatch.
In the nightwatch.json configuration file, you should be able to set a proxy parameter in the desiredCapabilities:
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions" : {
"args" : [
"disable-extensions",
"start-maximized"
]
},
"proxy": {
"proxyType": "manual",
"httpProxy": "your_proxy:8080"
}
}
},
Check this doc: https://code.google.com/p/selenium/wiki/JsonWireProtocol#Proxy_JSON_Object
I stumbled over this Question on my search for socks5 proxy solution.
When I used the implementation from the JsonWireProtocol documentation using the socksProxy property, I always got the following error:
message: 'unknown error: cannot parse capability: proxy from unknown error:
proxyType is \'manual\' but no manual proxy capabilities were found
Using a socks5 proxy configured via a proxy.pac file - proxyType: 'pac' using proxyAutoconfigUrl was working without any problem. But this wasn't suitable for my use case.
After some fiddling around, I finally found two solutions to that problem:
Using CLI args for chromedriver
desiredCapabilities: {
browserName: 'chrome',
/* … */
chromeOptions: {
args: [
'--proxy-server=socks5://proxy_url:proxy_port'
]
}
}
*edit: looks like this has been removed
2. Using sslProxy property
Since socks proxy is in theory nothing more than a ssl tunnel I thought I could give that property another try. The solution that made it finally working looked like this:
desiredCapabilities: {
browserName: 'chrome',
/* … */
proxy: {
proxyType: 'manual',
sslProxy: 'socks5://proxy_url:proxy_port'
}
}
Hope that answer help anyone looking for help regarding socks5 proxy. :)
But more important would be that chromedriver will implement the JsonWireProtocol properly in the future.
Nightwatch changed how the proxy object in the nightwatch.conf.js file works when they started using proxy-agent instead of http-proxy, unfortunately it seems to not be documented anywhere. But it does still exist you just need to pass in different parameters in the proxy object. The 'protocols' it accepts are listed on the proxy-agent github See below for an example.
firefox: {
desiredCapabilities: {
browserName: 'firefox',
version: 'latest',
},
proxy: {
host:'127.0.0.1',
port:8001,
protocol: 'http',
},
},

Resources