How to disable "Mark non-secure origins as non-secure" within selenium tests? - selenium

I am running non http url inside of my tests (so migration to https wont be easy) and because of that I am getting an warning inside of browser.
How to disable "Non secure" warning inside of Chrome during selenium tests?
I've tried to play with arguments but nothing works
args: [
'start-maximized',
'disable-webgl',
'blacklist-webgl',
'blacklist-accelerated-compositing',
'disable-accelerated-2d-canvas',
'disable-accelerated-compositing',
'disable-accelerated-layers',
'disable-accelerated-plugins',
'disable-accelerated-video',
'disable-accelerated-video-decode',
'disable-gpu',
'disable-infobars',
'test-type',
'disable-extensions',
'allow-running-insecure-content',
'disable-web-security',
'ignore-certificate-errors',
'ignore-gpu-blacklist',
'no-default-browser-check',
'no-first-run',
'disable-default-apps'
]
The issue is that I need to resize windows to 420x800 but because of warning browser can't do that.

"Not Secure" SSL Error
As per Fix “Not Secure” SSL Error on Chrome Browser | Remove Warning with the release of Chrome 68, Google started showing all the HTTP sites as Not Secure on Chrome Browser.
Treatment of HTTP pages
This feature can be turned On / Off by accessing the page at chrome://flags/#enable-mark-http-as and setting the following attribute:
Mark non-secure origins as non-secure: Changes the UI treatment for HTTP pages on Mac, Windows, Linux, Chrome OS, Android
Default
Enabled
Enabled (mark as actively dangerous)
Enabled (mark with a Non Secure warning and dangerous on form edits)
Disabled
Using Selenium to disable this feature you need to use the ChromeOption --allow-running-insecure-content as follows:
Python:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("start-maximized")
chrome_options.add_argument('disable-infobars')
chrome_options.add_argument('--allow-running-insecure-content')
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("http://www.legislation.vic.gov.au/")

This does not work for chrome on android devices. It's a bad idea for companies to tell users what and what they can not look at. Tech giants like Google have gone too far and the government is letting it happen.

Related

Initializing Chrome with --unsafely-treat-insecure-origin-as-secure=<domain> doesn't enable the chrome flag

I'm looking to write some browser automated tests with chrome + chromedriver in a docker-compose network where localhost isn't an option and one of the features can only function within a secure context (https or localhost). Chrome seems to have a feature flag "Insecure origins treated as secure" to get around this by adding the chromedriver argument --unsafely-treat-insecure-origin-as-secure=. When i add this arg, it adds the domain in chrome://flags/#unsafely-treat-insecure-origin-as-secure but the feature is still marked as disabled. Is there something I can do here to also enable the feature?
I've noticed in chrome://version that when the feature is enabled and i relaunch chrome manually, it's present at the end of the "Command Line" section resembling
--flag-switches-begin --unsafely-treat-insecure-origin-as-secure=http:// --flag-switches-end
But when it's disabled, it's just
--flag-switches-begin --flag-switches-end

Firefox Webdriver, add website cookies exception?

I have a Selenoid Firefox container running some tests but new browser versions are giving me issues.
Since Firefox 103.0 Cross-site tracking cookies are blocked by default and I am looking for a way to add a website exception in Privacy & Security > Cookies and Site Data using Firefox capabilities / Options but nothing seems to do the trick.
A good example of website that causes issues is https://teams.microsoft.com where firefox will now ask you if you "Really want to accept cookies from there ?" which I am trying to bypass by setting website exception in advance.
Done it by selecting a profile at geckodriver start instead of letting it generate one: Add args: ["-profile", "/binary/nameoffirefoxprofile"] to capabilities pref in your code. For this you need to get a firefox profile folder and copy it to your container first. If this works it will replace the generated rust_mozprofile_someID of geckodriver.

How to enable DoH settings in chrome driver in Selenium

I am pretty new to using Selenium and it's webdrivers. I have a need to enable DoH (dns over https) together with an option for selecting which DoH server to connect to in chrome driver in Selenium.
I have been researching online and have gone through recommended switches available here: https://peter.sh/experiments/chromium-command-line-switches/
as well as seen a similar post here: How to disable dns over https in selenium for disabling DoH (I don't even have DoH enabled by default in first place in chromedriver), but haven't figured out yet to how to get it enabled in the headless mode.
I also looked at the switches available for firefox driver but still don't see any right away available switches to use for the same.
Any help would be appreciated.
Thanks!
fbw
To enable DoH you need to do the following:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
local_state = {
"dns_over_https.mode": "automatic",
"dns_over_https.templates": "",
}
options = Options()
options.add_experimental_option('localState', local_state)
driver = webdriver.Chrome(options=options)
This will turn on the DoH which looks like this in browser settings on the chrome://settings/security page:
Also you can set "dns_over_https.mode": "automatic" which will set the secure option of DoH configuration:
Unfortunately I failed to figure out ho to use "dns_over_https.templates": "". Documentation says about it:
String containing a space-separated list of DNS over HTTPS templates
to use in secure mode or automatic mode. If no templates are specified
in automatic mode, we will attempt discovery of DoH servers associated
with the configured insecure resolvers.
I'm not familiar with DoH, so this description tells me nothing. I don't know what a DoH template is. I hope you know what they are talking about.

How to turn off SSL check on Chrome and Firefox for localhost

I'm making a web app that uses WebRTC but it requires https. Is there any way to turn off SSL check on Chrome and Firefox for localhost only or is there any way to make use of WebRTC without https? Thanks.
Chrome has chrome://flags/#allow-insecure-localhost which will ignore certificate errors on localhost. This makes development much easier.
As #vcsjones said
Both Chrome and Firefox treat localhost as a secure context, so localhost should have access to secure context only features like webcam, geolocation, and WebRTC.
It is correct. However, Firefox changed (since Firefox 42) mozSrcObject to srcObject. I changed it to that and it worked.
Since chrome://flags/#allow-insecure-localhost feature is removed from Chrome 88 disable security settings completely helped me to send requests from localhost to server.
Google Security Settings
The way to continue and access the server will be by clicking on an empty location at the background with the browser's error page and type:
thisisunsafe

Selenium RC and Internet Explorer 7 with rspec for HTTPS and HTTP connections

We test our rails web application with rspec and use the selenium-client (gem version 1.2.18) API in our rspec tests to let selenium RC server (version 2.21.0) steer internet explorer 7 under AP to test our application.
This worked very well until we introduced HTTPS for our login and registration process. Now the user is redirected to the secure version of the login and registration form and afterwards redirected back to the unsecure HTTP site.
For our selenium tests to work with HTTPS and internet explorer 7 we are setting up the selenium driver with "*iexploreproxy" instead of "*iexplore" and use port 4444. We also installed the CyberVillans SSL Certificate as describe here http://blog.mogotest.com/2010/04/13/how-to-accept-self-signed-ssl-certificates-in-selenium/. We run selenium rc server with -trustALLSSLCertificates. This solved the self signed SSL Certificate issues (be aware that selenium RC > 2.21 does not work because of a bug which sets a wrong valid from date).
After that we received "Permission Denied" errors, when running our tests. We found out that this is because of the same origin problem described at http://wiki.openqa.org/display/SEL/Selenium+Core+FAQ under "Why do I get a Permission Denied error when accessing my website via HTTPS?". This problem can be solved by adjusting internet explorers 7 proxy settings and using localhost:4444 to route everything through the selenium RC server. It works, but the problem is that after every test run the proxy settings are reset.
My first question is: How is it possible to make those settings persistent in the internet explorer 7? I read about custom profiles for IE but I haven't found out how to set this up for rspec tests. I also read about a proxy.pac file, but googling for solution without success.
The next problem is that when running our tests we also run into "Access denied" errors by selenium. I have no idea how to solve these and why they occur. So my second question is: How do I get rid of those under the setup described.