I'm using Selenium and Appium to run my java project in Android mobile. I'm trying to execute on Chrome browser and everytime it runs, it asks for proxy credentials (username and password), this is because I'm connected to a network with proxy.

I've tried several methods without success:

  • Passing credentials through the url: http://username:password@url.com
  • Settings httpproxy through capabilities.

    DesiredCapabilities capabilities = DesiredCapabilities.android(); Proxy proxy = new Proxy(); proxy.setHttpProxy(proxy+":"+port); proxy.setSocksUsername(user); proxy.setSocksPassword(pw); capabilities.setCapability("proxy", proxy);

  • Filling the popup fields changing the context to NATIVE_APP

    driver.switchTo().window("NATIVE_APP"); driver.findElement(By.id("username")).sendKeys(user); driver.findElement(By.id("password")).sendKeys(pw); driver.findElement(By.id("button1")).click();

Thank you in advance.

This is a trouble area currently. I will go thru your approaches one by one.

  • Passing credentials through the url: http://username:password@url.com This works only when the authentication model is HTTP basic. Moreover use of this kind of url is deprecated and not advisable.
  • Setting proxy thru capability will also not work as authentication is an argument to the New Session command not the user agent’s capabilities. Therefore, the authentication should be passed as a top-level parameter and not embedded in capabilities.

Coming to solution,

  • While navigating to the URL, create a uri with authentication included with that, so you dont have to perform authenticate fron UI side.
  • Use Alert.authenticateUsing(credentials...) from webdriver v3.1; now it is removed because of compliance. This might require you to down-grade the selenium version.

  • Or, Implement a similar api like mentioned above in the current version.

  • Or, this will be lil tricky; Extend the webdriver to override the creation of NewSession passing the credentials like below:

{ "user": "username", "password": "password", "capabilities": {…} }

I will comeback if i find an elegant solution.

  • This does not answer OP's question. – demouser123 Mar 13 at 16:42
  • The second part provides different solution options. – Kshetra Mohan Prusty Mar 14 at 5:41

I had to define the domain and username (which required an encoded backslash), password, address and port within the command when installing the Watir gem for Ruby...

Not sure how you'd run this with Appium, but hopefully it'll point you in the right direction.

gem install --http-proxy http://{domain}%5C{username}:{password}@{proxy.address}:{port}/ watir

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.