Add proxy to PhantomJSDriver (Selenium C#) - selenium

I'd like to listen to traffic generated by phantomjs selenium driver in c#. The below code does not work unfortunately!
PhantomJSOptions phoptions = new PhantomJSOptions();
phoptions.AddAdditionalCapability("proxy", "http://localhost:9999");
driver = new PhantomJSDriver(phoptions);
can anyone help me what's wrong with it!
Thanks in advance

Proxy proxy = new Proxy();
proxy.HttpProxy = string.Format("127.0.0.1:9999");
var service = PhantomJSDriverService.CreateDefaultService();
service.ProxyType = "http";
service.Proxy = proxy.HttpProxy;
IWebDriver driver = new PhantomJSDriver(service);
Some quick testing showed this work for me.

You can use the CapabilityType class to set the proxy capability. Here is a modified version of your code above:
PhantomJSOptions phoptions = new PhantomJSOptions();
phoptions.AddAdditionalCapability(CapabilityType.Proxy, "http://localhost:9999");
driver = new PhantomJSDriver(phoptions);
This worked for me. Arran's answer did not work for me. For some reason, my PhantomJSDriverService class did not have a ProxyType or Proxy member.

Related

Cadence Java client - Worker.Factory cannot be resolved

I am following the samples given in the java client sdk. Specifically
https://github.com/uber/cadence-java-samples/blob/master/src/main/java/com/uber/cadence/samples/hello/HelloWorkerSetup.java
Compiler is not able to resolve
Worker.Factory
I have tried to look in the client SDK code but I cannot seem to get past this error.
Has something changed in how workflows have to be registered?
Thanks
Sanjay
ClientOptions tOptions = ClientOptions.newBuilder().setHost(serverHostName).setPort(serverPort).build() ;
WorkflowServiceTChannel tChannel = new WorkflowServiceTChannel(tOptions);
WorkflowClientOptions clientOptions = WorkflowClientOptions.newBuilder().setDomain(serverDomain).build();
WorkflowClient wfClient = WorkflowClient.newInstance(tChannel,clientOptions);
WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().build();
WorkerFactory factory = WorkerFactory.newInstance(wfClient,factoryOptions);

Selenium C# InPrivate Mode Internet Explorer IE 11 throws exception

I have a requirement to open IE11 in private-mode on Winodws10. Tried by following code but it is throwing exception "Unexpected error launching Internet Explorer. Unable to use CreateProcess() API. To use CreateProcess() with Internet Explorer 8 or higher, the value of registry setting in HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\TabProcGrowth must be '0'."
Code:
int val = Convert.ToInt32(Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\TabProcGrowth", "", -1));
InternetExplorerOptions ops = new InternetExplorerOptions();
ops.ForceCreateProcessApi = true;
ops.BrowserCommandLineArguments = "-private";
IWebDriver driver = new InternetExplorerDriver(url, ops);
There is key in RegEdit and i can read successfully.
Removing ops.ForceCreateProcessApi = true; helps to start the browser, but NOT in private mode. You need the combination of
ops.ForceCreateProcessApi = true;
ops.BrowserCommandLineArguments = "-private";
I had a problem just like yours. I searched a lot and found no solution until I tried to delete the following line:
ops.ForceCreateProcessApi = true;
And thank God, the problem was solved. I'd love to know if it helped you solve the problem

ConnRoutePNames.LOCAL_ADDRESS on selenium phantomjs

Hi with this code i can say to DefaultHttpClient, hey use this interfaceip for connection. So how can i say like this to phantomjsdriver.
note: sorry for my english. not my native language
Example:
DefaultHttpClient httpClient;
try {
HttpParams params = new BasicHttpParams();
params.setParameter(ConnRoutePNames.LOCAL_ADDRESS, InetAddress.getByName(interfaceIp));
httpClient = new DefaultHttpClient(params);
Solution:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(ConnRoutePNames.LOCAL_ADDRESS, InetAddress.getByName(interfaceIp));
this.driver = new PhantomJSDriver(caps);

org.apache.commons.httpclient.HttpClient multithreading calls crash

Hi all I use apache's httpclient to make restcalls, everything is working fine, When multiple thread are using this method my app crashes.
What is the implementation for this class that is MultithreadSafe.
Here is my code.
httpClient = new HttpClient();
HttpMethod method = null;
method = new GetMethod();
... method creation...
httpClient.executeMethod(method);
method.releaseConnection();
Thanks in advance. Juan
Have you looked at the HttpClient threading documentation ?
To get started one must create an instance of the
MultiThreadedHttpConnectionManager and give it to an HttpClient. This
looks something like:
MultiThreadedHttpConnectionManager connectionManager =
new MultiThreadedHttpConnectionManager();
HttpClient client = new HttpClient(connectionManager);
The issue you're having is quite common when using HttpClient out-of-the -box

selenium proxy configuration multiple times in same browser

I opened a browser(any) with selenium tool and applying proxy to that browser by this below posted code, below is for Firefox
//LINE 1 FirefoxProfile profile = new FirefoxProfile();
//LINE 2 profile.setPreference("network.proxy.http", configuration
.getProxyConfiguration().getHostname());
//LINE 3 profile.setPreference("network.proxy.http_port", configuration
.getProxyConfiguration().getPort());
//LINE 4 profile.setPreference("network.proxy.type", configuration
.getProxyConfiguration().getType().toInt());
//LINE 5 return new FirefoxDriver(profile);
Now, I want to apply another proxy configuration for the same browser(Because, If I use another browser, session will be get change, So.... I want to apply my changes to that browser itself). How to apply my proxy configuration to the same browser. When I use same code I've to return driver which uses "NEW". I showed in my code(//LINE 5). Please help me to solve this issue.
Thanks:
Ramakrishna K.C
You can create Proxy with Kind = ProxyKind.System
new Proxy { Kind = ProxyKind.System};
Then update the internet settings in the registry
var proxyServer = string.Format("http={0};https={0}", ipAddressAndPort);
var proxyEnable = enableProxy ? 1 : 0;
const string subKeyPath = #"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
using (var subKey = Registry.CurrentUser.CreateSubKey(subKeyPath))
{
if (subKey == null)
{
throw new Exception(string.Format("Failed to create or open subKey. SubKeyPath: {0} ", subKeyPath));
}
subKey.SetValue("ProxyServer", proxyServer, RegistryValueKind.String);
subKey.SetValue("ProxyEnable", proxyEnable, RegistryValueKind.DWord);
}
otherwise use PAC file in firefox profile.
http://findproxyforurl.com/