Webdriver : how to set IE in virtual environment? - selenium

I am setting up the Virtual Environment for my grid-based Webdriver tests. And sure enough, there are problems with IE driver.
First of all, Internet Options → Security should have the same Protected Mode setting. It's an easy fix if you have an access to the browser, but in my case, I won't have physical access to the browser.
In Webdriver's FAQ it says you can do the following:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.set(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(capabilities);
Ruby bindings have no reference to setting up this capability in IE. It there a way to code it out in Ruby?
The other thing is what can be done against "unsecure connection" pop-ups? Again, they are easy to deal with manually after the first run, but what about running "clean" IE instance each time?
There are probably more concerns,
I'd like to hear your opinion.
Thank you!

Related

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.

why the code //RemoteWebDriver driver= new FirefoxDriver(); is not used instead of //WebDriver driver= new FirefoxDriver()?

Why is the code //RemoteWebDriver driver= new FirefoxDriver(); not used instead of //WebDriver driver= new FirefoxDriver() to create a driver object?
I feel that RemoteWebDriver gives more capabilities for the driver instance than webdriver reference. Can someone clarify this?
WebDriver will start up a web browser on the computer where the code instantiates it. For example. If you write a bit of code, and then run it to see how you are doing, the browser will pop up on your screen and you will see WebDriver begin to manipulate that web browser window (if everything went well!)
With a major exception which I will explain below, RemoteWebDriver will do the same thing; it will open and manipulate a browser window (if everything went well!) Generally speaking, You can actually switch the instatiation of a WebDriver with a RemoteWebDriver (well, there are advanced cases where you might not be able too do this) The major difference is that RemoteWebDriver sends that request to open and control a web browser to a server, so you normally wouldn’t see the browser open and do it’s thing.
Selenium server is the program that runs and waits for RemoteWebDriver connections. You can run it on your local computer to test it out. If you get it set up and running, you’ll be able to create a RemoteWebDriver and see that the Selenium server accepts the connection and allows you to control the web browser window.
The gains from using RemoteWebDriver?
If you can do connect to a local Selenium server, you can be confident that you have the knowledge and skills needed to connect to a remote Selenium server, or even to a paid service like SauceLabs (Hosting Selenium for you) that allows you to run lots of tests on lots of OS’s and lots of browsers without having to actually maintain or install any of them (Linux, Windows 8, Windows 10, MacOS, Andriod, IOS, IE, Firefox, Opera, Safari, Firefox Mobile, etc) You’ll want to look into running tests asynchronously at this point. You don’t have to run them one at a time, so can test a large number of OS/Browser variations in a very short time.
What does it mean when something is used only for client/server communication?
When you uses a Selenium grid with have one hub and multiple clients, you invoke RemoteWebDriver through which you instantiate the server and and make the request to it.
WebDriver is an interface in selenium which extends SearchContext interface (super most interface in selenium)
Where as RemoteWebdriver is a class which implements WebDriver,
We can use RemoteWebdriver, when we going to execute the test in romote environment,(selenium grid).
WebDriver interface will invoke the driver locally,
Currently in automation mostly we are using WebDriver only.
Grid not using widely.
WebDriver driver=new ChromeDriver() ;
driver is the reference variable where used to access chromedriver class.
Using driver instance we can access all the unimplemented methods available in WebDriver interface, also able to access all the properties available in chromedriver class.
For more details
https://www.softwaretestingmaterial.com/webdriver-driver-new-firefoxdriver/

Run Selenium tests in one browser while using a second browser window

I am running Selenium automation test in one browser, but at the same time, I want to open the browser in another window and do something like checking mail, googling email then active mode or focus is coming to the current working window, not the automation test run browser.
Is it possible to work on the browser while automation test is run?
In general, when doing UI automation, you cannot use the test machine to do any other tasks that involve using the keyboard or mouse.
Since WebDriver automation performs keyboard and mouse input, such as typing text and clicking items, you will be constantly interfering by taking focus away from the WebDriver instance of the browser and doing your own mouse and keyboard interaction in other applications.
This will adversely affect both you and the automation, with neither being able to do what they want to do!
You should either use a separate test machine, or setup a virtual machine using software such as VirtualBox (free).
Did you try doing that?
Selenium uses WebDriver to communicate with a specific instance of a browser, not the currently focused window. So you should be able do continue to use other instances of browser windows. The best thing to do would be try.
If it isn't working, I would recommend getting a VM up and running and using that as your test environment. Generally that is the way I work to keep everything separate.
I ran my tests on Firefox and then used chrome on the side. Otherwise, run your tests on a remote machine.
You can do 2 things
1. Use a third tool to run test cases like Jenkins. so that test will run in memory.
2. If you are using firefox you can create a seperate firefox profile so that if you use firefox at the same time there should be any issue.
To Create new FF profile use below code:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(false);
profile.setAssumeUntrustedCertificateIssuer(true);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(dc);

Selenium drivers don't remember user authentication

The application I'm testing requires a login with the user's Google account. Every time I log in, it displays/requires that I select the 'Allow Access' button as if it doesn't remember that I have already added it to my list of Authorized Access for my Google account. This doesn't happen when I test manually, only when I'm running Selenium. Has anyone come across an issue like this or know of a solution? Thanks in advance.
WebDriver driver = selenium_driver.get(); // using chrome driver
baseUrl = defaults.getProperty("base_url"); // this is set to my localhost
helper.ConnectToURL(baseUrl);
When this started happening, I had been using Selenium 2.28.0--since then, I've updated to 2.31.0 but it's exhibiting the same behavior.
Disclaimer: This is currently not possible according to the ChromeDriver wiki. It states in the "Known Issues" section "Cannot specify a custom profile". (https://code.google.com/p/selenium/wiki/ChromeDriver)
At some point when it is fixed, I would suggest creating or using the default chrome profile that has your authorized access set that your test uses whenever it starts up.
According to the ChromeDriver wiki: "By default, ChromeDriver will create a new temporary profile for each session".
Checkout this post for more in depth information regarding capabilities: http://code.google.com/p/chromedriver/wiki/CapabilitiesAndSwitches
I do my work in .NET and Windows; my set up would look something like this:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("start-maximized");
chromeOptions.AddArgument("user-data-dir=C:\\Users\\username\\AppData\\Local\\Google\\Chrome\\User Data\\Default");
capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability(ChromeOptions.Capability, chromeOptions);
ChromeDriver chromeDriver= new ChromeDriver(this.Environment.ChromeDriverLocation, chromeOptions);
If you are not limited to using Chrome for your tests you are able to create and use custom profiles using Firefox.

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..