Using proxy with password/username with Selenium headless in C# - c#

After a lot of research and many tries, I wanted to know how it was possible to work with Selenium AND proxy with username/password in C#, with an headless solution (so no AutoIT script alternative).
For Chrome :
-There is no options and arguments available, an authenticate window will always pop up asking for the credentials, there is apparently noway to bypass it, and the only solution would be to use an external tool to write in the window. This solution is obviously not compatible with an headless. I tried to downgrade my Selenium version to the 2.53.0 in order to test the solution with the Alert handling, but it appears that now, Chrome browser doesn't treat that windows as an alert anymore. I could maybe downgrade also my Chrome browser version, but I don't want that for now.
For FireFox :
-Exactly same problem.
For IE :
-The proxy is set in the registry, so I don't even know how to run manually multiple instance with different proxy.
So, my question is, how, in C#, within an HEADLESS Selenium browser (I don't mind which one), I can run a session with a proxy user/pw (without any manual of course, and if possible without any third party program, but only within Selenium) ?

Related

Is it possible to run selenium as a windows service using C#? [duplicate]

So that we may perform front-to-back web UI testing, we are using Selenium and ChromeDriver to automate page loads/interaction as part of our testing pack.
This is behaving as expected during developer testing (on a developer's local machine), but we are struggling to perform these checks as part of our continuous integration build.
Our server plant is *NIX based, and all of our CI infrastructure runs on these machines. So that we may test Chrome under Windows (our delivery mechanism), we have configured a Selenium Grid. When the CI tests run, they access the grid, in order to locate a Windows node to run the tests on.
We have had a Windows desktop provisioned solely for the purpose of running these tests. This contains our standard enterprise build of Windows 7. This machine will be periodically rebooted in-line with the IT department's update policy.
In an effort to ensure the Selenium server is always running, we have added the Selenium Server (running in "node" mode) as a Windows service. The selenium Server is configured to start-up ChromeDriver to invoke the simulated user-interaction.
However, when running the tests from CI they fail due to timeout. Our working theory is, the system user that is running the service cannot create interactive windows. A web search has raised reference to the "Session 0" problem, but with little to no constructive advice on how to move forward.
Starting the Selenium Server process manually from an interactive session is not a viable solution, as this is leading to brittle tests - which are failing due to an infrastructure problem, rather than a genuine test regression.
How can we have an instance of Selenium Server started via a Windows Service whenever the system reboots, that is capable of launching Chrome instances?
It could be easily done with NSSM.
Installation of services looks like these:
nssm install seleniumhub java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role hub -hubConfig C:\selenium\hub.json
nssm install seleniumnode java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role node -nodeConfig C:\selenium\node.json
It provides easily way to remove service if needed:
nssm remove seleniumnode confirm
Add destination to nssm to your PATH variable and run from console as admin
UPDATE April 2021
NSSM is not supported for more than 3 years. So please consider other options like winsw or any other. WinSW does the same job as NSSM and allows to keep run configuration in xml.
You cannot run Selenium Grid as a windows service ever since Windows Vista. Microsoft calls it "Session 0 Isolation". You could do it in Windows 2000 or XP but since the time that Vista came out, Microsoft no longer will let Grid interact with the desktop (or any other UI programs for that matter). Regardless of the fact that you still see that "interact with desktop" checkbox, it is a red herring. So, you MUST run Selenium Grid in the foreground on that server in order for it to get access to the session. If it is running Windows Server, you could in theory have multiple sessions and leave Grid running in the foreground on one of the non-zero user sessions.
Right now you can't help it - it used to work fine in session 0 but for the past few days after chrome update only works for interactive sessions.
Related bugs:
https://code.google.com/p/selenium/issues/detail?id=8029
https://code.google.com/p/chromium/issues/detail?id=422218
My preferred solution to this problem (and my default choice for running Selenium Grid as a service) is to use a simple tool called AlwaysUp. It has a free 30 day trial to try it out.
What to do:
Download AlwaysUp
Configure AlwaysUp to start the Selenium Grid node on startup
Configure AlwaysUp to run the Selenium node as a specific user (not the default System user)
This way the the node will run as a service, survive machine restarts and work with the latest version Chrome.
If the user account you use to login to the machine is different from the user account you specify to run the node as a service then you will not see the browsers pop up on the desktop as they are running in a different user session. The end result is that it is almost identical to running as a normal service but gets round the Session 0 issue.
Yeah, you should use NSSM. Important is, that you add your windows account in the "Log on" tab, or any other valid account. If you run your node with the "Local System account" option, you will get the session 0 problem. With a normal user session, the nodes run smoothly invisible in the background :)
we don't use selenium GRID, we were disappointed with its stability. We use a "Jenkins Grid", that is jenkins slaves nodes on various servers.
The slaves are services with the interact with desktop flag. They run as services with NSSM, and the SERVICE_INTERACTIVE_PROCESS flag. Making sure that NoInteractiveProcess is set to 1 (cf https://learn.microsoft.com/en-us/windows/desktop/services/interactive-services).
We don't have the fancy features of the grid (that is balancing according the browser types slots). Instead, we have Jenkins balancing the test jobs using a slave node or another.
Initially we did not use the interact with desktop flag, having browsers to run without "real" display, but the behavior was not very stable (especially with resize commands).
Hope this helps.
As I explained on this thread, I found that using a small paid tool FireDaemon Pro saved me a lot of time from trying to configure NSSM and other free tools.
It works well in the background, and restarts Selenium along with the server, which was my main requirement for running Selenium Standalone Server as a Windows Service.
This free tool would probably do it:
http://yajsw.sourceforge.net/
For that to work, you need a wrapper.conf file and a script to run the YAJSW wrapper. I takes time to read the documentation, but it is a free solution.
I wrote an example shared here, that installs JBoss7 as a Windows service.
Of course, you can simplify my example by a lot.

How to change Security zone setting of IE Edge browser in windows 10 for selenium webdriver automation

I am doing selenium web driver automation on windows 10 IE Edge browser. I can able to launch IE Edge browser but command prompt which is launched for Microsoft driver is running in front and "IE Edge" browser window running backside of that hence some test are failing due to such behavior in IE Edge.
So i want to try with changing primary setting of IE Edge for selenium web driver like changing Security zone setting at same level and all other required setting needed for selenium web driver.
Please any help in IE edge is greatly appreciated.
Note: What i think is the existing test which are running on IE 11 with selenium web driver. Those same tests are not working in IE Edge with selenium web driver. Please help
Microsoft Edge configurations are not 100% same as others. It requires additional installation in order the WebDriver to talk to the browser. I have not personally tested/used it yet. But, read this answer.
According to JimEvans answer, you must upgrade the Selenium bindings to 2.47 since this release has necessary changes.
Note: Of course not all API will work with edge browser. The link above answers most of common questions you may have.

Blocking applications using C#

I am working on a web application which will allow users to take exam online. When the user clicks on take test I need to block the calculator app. Is there a way to do that?
I am using asp.net,c#,visual studio 2008
Absolutely not. Your code is executing on your server, and the calculator is running on their PC. You can send JavaScript, Flash, Silverlight, etc. that is executed, but they run in a sandbox - can't affect anything outside the browser runtime. You wouldn't like it very much if websites could manipulate your PC would you?
This is not possible unless you force the user to install custom software on their computer. And if we go into that, this has nothing to do with the web anymore.
And to be honest, if you don't have any control over the environment the user is in... what's preventing them from opening whatever software you're trying to block on a laptop sitting next to the computer running the exam?
if you are in a Web application, you cant control your client machine. Only you can control your browser by using javascript or silverlight etc.
You have to install some extra windows application to protect that

Heightened privilege selenium browsers on Windows 7 (x64)

I make use of *firefox and *iexplore etc. within my selenium tests to get around the issue of self-signed SSL certificates on my local machine. Unfortunately, now that I've moved from XP over to 7, this seems to have stopped working.
I'm running the selenium RC server process as administrator, since that was necessary to get an IE instance to launch properly.
I've tried adding permanent security exceptions for the certificate in question, and have confirmed that this works when I myself launch a browser session. But when a browser session is instantiated by the Selenium RC, I'm still receiving the security warnings.
I've also tried specifying the 32bit version of IE, in case it was just the 64bit version that wasn't working, but both exhibit the same behaviour.
I've also tried temporarily disabled UAC, in case I was falling foul of a permissions/elevation problem, but that also did not help.
Has anybody managed to get the heightened privilege browsers working properly on Windows 7? Alternatively, does anybody know a way that I can get around this issue? (short of not using https!)
Thanks!
Have you tried adding the certificate to your list of accepted certificates by hand?
As IE doesn't have profiles, and each session uses the user's profile, you can add the certificate by hand the first time the error occurs to Selenium and next time the browser finds an error to warn, it will find the cert in the list of exceptions and proceed with the page without warning.
For Firefox, the best way to get around this is to create a custom profile with all the certificates accepted, then specify that profile when you start your Selenium server. I use this same strategy for setting up browsers in different languages.
*chrome is normally the way to run Firefox with relaxed security.

Code access to external urls

I have code that uses process class to sign code with a verisign signature.
So basically it uses command line cmd. Now this all used to work but recently (maybe due to malware), it fails at the timestamping stage. Pretty sure this is because it is no longer able to access the verisign external url in order to time stamp.
I have tried the same command from command manually and the result is the same. I have a proxy configured in IE which is necessary for external web access but I assume when I'm using cmd for e.g. it's not derived from IE settings?
To me it sounds like your IE proxy settings got messed up. Malware can do that. Go into IE, then Internet Options (it's different depending on version of IE and Windows). Once in there, hunt down proxy settings and turn them off. I'd guess they are currently enabled.
Also, timestamping will fail if the certificate expired. Did it expire?

Categories