Does the safaridriver support proxy configuration? - selenium

I've been trying to use Robot Framework to write some cross browser tests.
One of the requirements is that i need to use a proxy to access the website I am testing. Right now, I am trying to launch the safari browser and get it to go through the proxy to reach the website, but I seem to have an issue.
Here is the Robot framework keyword
# ${MY_PROXY} is a variable located elsewhere in the file
Open Safari
${desired_capabilities} = Evaluate selenium.webdriver.DesiredCapabilities.SAFARI
sys, selenium.webdriver
${safari_proxy} = Create Dictionary proxyType MANUAL httpProxy ${MY_PROXY}
sslProxy ${MY_PROXY}
Set To Dictionary ${desired_capabilities} proxy ${safari_proxy}
Create Webdriver Safari desired_capabilities=${desired_capabilities}
So far, i've been receiving this error
SessionNotCreatedException: Message: Capability 'proxy' could not be honored.
Currently using robotframework-seleniumlibrary 4.5.0 with selenium 3.141.0
Does the safari webdriver allow proxies? I can't seem to find much on this topic

Related

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.

Is there a way to test web application using Selenium and either Driver Firefox or Chrome on a server Centos7 without graphical interface?

On my local machine, I arrived to test my applications with Selenium with any problems.
But, when I'm doing the same operations on a server Centos7 (I have no graphical interface), I've many errors such as web element not found.
I'm using Docker containers for selenium (hub and nodes). The installation is OK and I can see my drivers on Http://:4444/grid/console.
Does Selenium require a graphical interface for its work?
Yes. Selenium requires the browser GUI to be present - which is also called viewport.
If you want that Selenium execution happen, without the browser GUI to be present, then you need to use a headless browser, which , as the name suggests is headless, which means there would be no GUI for them.
Examples of these headless browser include PhantomJS- link. Now Chrome also has a headless mode - link, which you can specify using ChromeOptions. Cheers!

Whitelist domains Selenium / Firefox can connect to

I am using Selenium webdriver with firefox. I am wondering if there is a setting i can change such that it to only requesting resources from certain domains. (Specifically i want it only to request content which is on the same domain as the webpage itself).
My current set up, written in Python, is:
from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
## Here, I change various default setting in Firefox, and install a couple of monitoring extensions
driver = webdriver.Firefox(firefox_profile)
driver.get(web_address)
What i want to do, is if i specify the web address wwww.domain.com, then to only load content served by domain.com, and not e.g. all the tracking content hosted by other domains that would typically be requested. Hoping could be achieved by a change to the profile settings in firefox, or via an extension.
Note - there is a similar question (without an answer) - Restricting Selenium/Webdriver/HtmlUnit to a certain domain - but it is four years old, and i think Selenium has evolved a lot since then.
With thanks to Vicky, (who's approach of using Proxy settings i followed - although directly from Selenium), the code below will change the proxy settings in firefox such that it will not connect to a domain except that on the white-list.
I suspect several setting changes are unnecessary and can be omitted for most purposes. Code in Python.
from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
## replace desired_domain.com below with whitelisted domain. Separate domains by comma.
firefox_profile.set_preference("network.proxy.no_proxies_on","localhost,127.0.0.1,desired_domain.com")
firefox_profile.set_preference("network.proxy.backup.ftp","0.0.0.0")
firefox_profile.set_preference("network.proxy.backup.ftp_port",1)
firefox_profile.set_preference("network.proxy.backup.socks","0.0.0.0")
firefox_profile.set_preference("network.proxy.backup.socks_port",1)
firefox_profile.set_preference("network.proxy.backup.ssl","0.0.0.0")
firefox_profile.set_preference("network.proxy.backup.ssl_port",1)
firefox_profile.set_preference("network.proxy.ftp","0.0.0.0")
firefox_profile.set_preference("network.proxy.ftp_port",1)
firefox_profile.set_preference("network.proxy.http","0.0.0.0")
firefox_profile.set_preference("network.proxy.http_port",1)
firefox_profile.set_preference("network.proxy.socks","0.0.0.0")
firefox_profile.set_preference("network.proxy.socks_port",1)
firefox_profile.set_preference("network.proxy.ssl","0.0.0.0")
firefox_profile.set_preference("network.proxy.ssl_port",1)
firefox_profile.set_preference("network.proxy.type",1)
firefox_profile.set_preference("network.proxy.share_proxy_settings",True)
driver = webdriver.Firefox(firefox_profile)
driver.get(web_address_desired)
I think it is still impossible in selenium.But you can still achieve this by using proxies like browsermob. Webdriver integrates well with browsermob proxy.
Sample pseudeocode in java
//LittleProxy-powered 2.1.0 release
LegacyProxyServer server = new BrowserMobProxyServer();
server.start(0);
// Blacklist websites
server.blacklistRequests("https?://.*\\.blocksite\\.com/.*", 410);//these sites will be blocked
/// get the Selenium proxy object
Proxy proxy = ClientUtil.createSeleniumProxy(server);
// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
// initialize the driver with the capabilities ;
Webdriver driver = new FirefoxDriver(capabilities);
Hope this helps you.Kindly get back if you need any further help

What's difference between protractor (Selenium webdriver) VS ghostdriver (phantomjs webdriver)?

I would like to make it clear about the difference between protractor VS ghostdriver.
With protractor:
start selenium web server for testing.
multiple browser testing.
whenever it start testing, it open the browser.
With ghostdriver:
start phantomjs web server.
can be config multiple browser too.
can run separate with selenium or integrate with selenium.
My question is PhantomJS webdriver can run alone without selenium webdriver, multiple browsers and good for CI. Why do we need to run selenium and integrate selenium with phantomjs using ghostdriver?
While I'm not entirely sure I understand your question, I'll take a stab at answering it. With WebDriver, driving a browser is done via a standardized JSON-over-HTTP wire protocol. This means that you need a "server" component that understands the wire protocol to drive any particular browser. For each of the major desktop browsers (Internet Explorer, Chrome, and Firefox), there is a server component that your WebDriver code talks to (IEDriverServer.exe, chromedriver.exe, or a Firefox browser extension, respectively). PhantomJS also implements a server component that understands the WebDriver wire protocol, so the same high-level WebDriver code can be used with PhantomJS that is used with other browsers. Note that the Selenium server is not required to drive any of the browsers on the local machine.
Now, since the protocol used is simply transmitted over HTTP, that gives WebDriver the opportunity to run the WebDriver code on one machine, while driving a browser located on an entirely different machine. That's where the Selenium server comes in. The Selenium server starts an HTTP server that understands the WebDriver JSON wire protocol. When that server receives a WebDriver command, it can forward that command to another "server" component, either running on that machine (as a standalone remote server), or on yet another machine running another instance of the Selenium server (in a "grid" configuration).
So to answer your question, yes, WebDriver code can be executed against PhantomJS without using the Selenium server. It can likewise be executed against Internet Explorer, Firefox, Chrome, Safari, and some versions of Opera, all without using the Selenium server. Notice that all of this is true without mentioning Protractor at all. Since Protractor is based on WebDriverJS, as long as there's a "server" component running, whether that's a Selenium server, chromedriver.exe, IEDriverServer.exe, or PhantomJS, the driver should be able to communicate with and drive that browser. Looking at the code, it appears that WebDriverJS (and, by extension, Protractor), should be able to execute against Chrome and PhantomJS without requiring the Selenium server, but I don't know enough about Protractor's wrapping of WebDriverJS to speak with authority.