C# selenium/phantomjs set global proxy - c#

I need to setup phantomjs to use a proxy. I have found many examples for java, javascript/node.js, etc. But none for c# using selenium. I need to set a global proxy and be able to change it without restarting the driver. I believe it would be under driver.ExecutePhantomJS() but I also cant find what phantomjs script I would run to change the global proxy.

When creating the service:
OpenQA.Selnium.Proxy myproxy = new Proxy();
myproxy.httpProxy = ip +":"+port;
driverservice.AddAdditionalCapability(CapabilityType.Proxy, myproxy);
After driver is running to change the proxy:
driver.ExecutePhantomJS("phantom.setProxy('"+ip+"', "+port+", 'http', '', '');")

Related

How can I setup proxy settings in c# for Google Cloud Txt-To-Speech API

How to setup a proxy in c# code for Google Text-To-Speech API.
Does somebody knows where to put in the proxy settings for the Google TTS API in c#. Our project runs locally but not on the server behind a firewall, so it has to go via the proxy.
Hope you have a starting point for me ;-)
Thanks!
The intention is that if you've set the system proxy, or the HTTPS_PROXY environment variable, that should just work by default.
However, at the moment there's a bug in Grpc.Net.Client that causes that to fail. (Once it's been fixed and released, we'll obviously update our dependencies for the next release of Google.Cloud.TextToSpeech.V1 and other Cloud libraries.)
The simplest workaround is probably to still use the Grpc.Net.Client implementation of gRPC, but with an additional option:
var client = new TextToSpeechClientBuilder
{
GrpcAdapter = GrpcNetClientAdapter.Default.WithAdditionalOptions(
options => options.HttpHandler = new HttpClientHandler
{
Proxy = new WebProxy("your proxy here"),
UseProxy = true
})
}.Build();

(C#) How can I hide the Selenium Webdriver console application while also providing a custom path to the drivers?

I have a requirement to both hide the console that comes up when using Selenium-Webdriver and also being able to provide a custom path to the exact location and version of the driver I'm using. There doesn't appear to be a constructor that accepts both the string for the directory, and the DriverService for hiding the console. How can I accomplish both these tasks? I will eventually need to implement this for all browsers, so an example with any of them would be amazing.
I actually got lucky and figured it out. DriverService is able to take the driver path as an argument! Here's a chrome example:
ChromeDriverService service = ChromeDriverService.CreateDefaultService(driverPath);
service.HideCommandPromptWindow = true;
ChromeDriver chromeDriver = new ChromeDriver(service);

Confusing proxy issue using PhantomJS C#

So basically I am trying to automate the web. I'm doing this by using Selenium and PhantomJS driver.
In addition to this I am doing it using a proxy. This is where the problems start.
Without the proxy it's working just fine. Using it doesn't. I'm having big trouble trying to debug this.
This is what I am using now to set the proxy:
PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
service.ProxyType = "http";
service.AddArgument(string.Format("--proxy=", proxyL));
I feel like I have tried every single Google result regarding this and none of the different variants have worked so far. If there is anyone who's got experience with using the PhantomJS diver with a proxy I would love some help.
EDIT:
I am now using this code to set the proxy:
options.AddAdditionalCapability(CapabilityType.Proxy, new Dictionary<string, string>
{
{"proxyType", "none"},
{"httpProxy", proxyL}
});
The console window dows show that I'm using the proxy. But it still isn't.

NTLM authentication in Selenium RemoteWebDriver

I am trying to use the Selenium HtmlUnit driver in C# tests. As far as I know, the only way to use the HtmlUnit driver in C# is through Selenium server and the RemoteWebDriver:
var driver = new OpenQA.Selenium.Remote.RemoteWebDriver(
OpenQA.Selenium.Remote.DesiredCapabilities.HtmlUnitWithJavaScript());
However, I also need to use NTLM authentication. Using the non-remote driver in Java, it can apparently be configured like this:
WebDriver driver = new HtmlUnitDriver() {
protected WebClient modifyWebClient(WebClient client) {
// Does nothing here to be overridden.
DefaultCredentialsProvider creds = new DefaultCredentialsProvider();
creds.addNTLMCredentials("userName", "password", null, -1, "myComputerName", "myDomain");
client.setCredentialsProvider(creds);
return client;
}
}
(Source: https://groups.google.com/forum/#!topic/webdriver/ktIWIs5m0mQ)
But this obviously does not solve my problem since I am using C#. How can I do that ? (I can use Chrome successfully, but I would like to use HtmlUnit for speed).
Thanks !
In order to pass credentials you need to overload the modifyWebClient of the HtmlUnitDriver, as you saw in the discussion link1.
For the .NET developer the only way to use the HtmlUnitDriver is via the RemoteWebDriver, and based on the discussion HtmlUnit wrapper for .NET2 the developers chose not to expose all of the HtmlUnit driver classes:
I'm loathe to take any more dependencies in the .NET
bindings... If you're dead-set on using HtmlUnit as your headless browser of choice, you can always use it via the RemoteWebDriver
Therefore you cannot use NTLM, or any other credential method, with the RemoteWebDriver.
If you were willing to do and maintain the work you could convert all the HtmlUnit code as detailed in the second link of #JasonPlutext's answer3.
The original sample appears to be from the selenium FAQ.
Linked to from Is there an HtmlUnitDriver for .NET? here on SO.

Connecting to Office365 via a Proxy server

I need to connect to Office365 portal using powershell via a proxy server. I read an article here which says calling:
New-PSSessionOption -ProxyAccessType IEConfig
with IEConfig should do the trick.
But, is there a way that I can give proxy server without having to rely on IEConfig. i.e is there any other way to generate a -ProxyAccessType ? Something on the lines
$proxyserver = New-Object ProxyAccessType(server ip ...)
and then use the proxyserver in New-PSSessionOption -ProxyAccessType $proxyserver
From http://technet.microsoft.com/en-us/library/hh849703.aspx the supported values are
IEConfig, WinHttpConfig, AutoDetect, NoProxyServer and None. The default value is None.
WinHTTPConfig can be set using netsh http://technet.microsoft.com/en-us/library/cc731131%28v=ws.10%29.aspx
AutoDetect will use the wpad protocol to determine proxy settings http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol which can be kludged with a wpad file
Good Luck!

Categories

Resources