3

I'm using Selenium and Appium to run my java project in Android mobile. I'm trying to execute on Chrome browser and every time 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:[email protected]
  • Settings HTTP proxy 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();

Alex Kulinkovich
6272 gold badges8 silver badges18 bronze badges
asked Mar 10, 2018 at 1:00

2 Answers 2

2

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

  • Passing credentials through the url: http://username:[email protected] 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.

answered Mar 13, 2018 at 16:13
2
  • This does not answer OP's question. Commented Mar 13, 2018 at 16:42
  • The second part provides different solution options. Commented Mar 14, 2018 at 5:41
0

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
answered May 14, 2018 at 8:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.