Handle HTTP Authentication on iOS Safari

Hey guys,

Is there a way of inputing the username/password of an http authentication using Appium on Safari iOS? The pattern http://username:[email protected] doesn’t work, and I can’t find a way of inputing user/pass on the pop up dialog. Please help me!

Thanks,

1 Like

Can you explain what “doesn’t work” means? Please give us details so we can identify your problem.

When you access a website that has a http authentication (example: integration.westelm.com ), it pops up a dialog asking for username and password, but Appium doesn’t provide a way of filling this automatically, so we’re not able to perform tests on this website.

Thanks for the help

@Ricardonacif

Do you use Selenium Proxy or Browser mob proxy?

Unfortunately I have no answer to the question how Appium works with this features. :frowning:

I want to know it too.
There is the similar topic. So it is possible that there are some problems.

Thanks for the answer @SergeyTichomirov . Actually I don’t use proxies yet, but I’ll take a look. Anyway, it would be great if Appium could fill the authentication pop up on iOS. I believe that isn’t a hard thing to do anyway.

Do you have any solution for handle the authentication on IOS Safari, I am also facing the same issue

I am using Browser Mob Proxy (version 2.1.0 beta-1), Appium (1.3.6) with Appium provided Java client (ver: 2.1) library. But Appium failed to set Proxy when start AppiumDriver and returning ‘Original error: Instruments never checked in’ exception. I tested on iphone-simulator on iOS 8.1.
Setting Proxy using below code
Proxy proxy = BMP_Proxy_Controller.Server.seleniumProxy();
objCapabilities.setCapability(MobileCapabilityType.PROXY,proxy);
objCapabilities.setCapability(MobileCapabilityType.ACCEPT_SSL_CERTS, true);

Log captured from Appium server:
{“desiredCapabilities”:{“orientation”:“Portrait”,“acceptSslCerts”:true,“browserName”:“Safari”,“autoLaunch”:true,“locale”:“US”,“safariAllowPopups”:true,“locationServicesAuthorized”:true,“newCommandTimeout”:“600000”,“autoAcceptAlerts”:true,“safariIgnoreFraudWarning”:true,“platformVersion”:“8.1”,“fullReset”:false,“deviceName”:“iPhone 5”,“platformName”:“iOS”,“proxy”:{“noProxy”:null,“socksUsername”:null,“httpProxy”:“NDI-LAP-371.3pillar.corp:8019”,“ftpProxy”:null,“socksPassword”:null,“sslProxy”:“NDI-LAP-371.3pillar.corp:8019”,“proxyAutoconfigUrl”:null,“proxyType”:“MANUAL”,“class”:“org.openqa.selenium.Proxy”,“autodetect”:false,“hCode”:1056099159,“socksProxy”:null},“bundleId”:“com.apple.mobilesafari.app”,“deviceReadyTimeout”:“450”,“locationServicesEnabled”:false}}
info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : acceptSslCerts, proxy,

Hey guys, I found the solution to access http authentication websites. It’s actually kind of weird but it works:

Before accessing the http authentication protected website, ask selenium to go to page ‘a’, and then send the goto to users/[email protected], like this:

  browser.goto('a') #appium workaround for the http authentication to work
  browser.goto("http://username:[email protected]")

Hi,

Please help me any one on the below issue, Thanks in advance.

Issue: once hit url on the mobile(Real Device) safari browser,it pops up a dialog asking for username and password.

I am unable to communicate with popup and also I tried below ways but not working.

1.driver.get(“a”)
driver.get(“https://username:[email protected]”)
2. driver.get(“https://username:[email protected]”);

    Alert aa = driver.switchTo().alert();
    aa.sendKeys("username");   
    
    Robot a = new Robot();
    a.keyPress(KeyEvent.VK_ENTER);
    a.keyPress(KeyEvent.VK_ENTER);
    
    Thread.sleep(5000);
    
    Alert bb = driver.switchTo().alert();
    bb.sendKeys("password");

    a.keyPress(KeyEvent.VK_ENTER);
    a.keyPress(KeyEvent.VK_ENTER);

Please tell me, is it possible to auto fill the data into the text fields using appium.

Hey,

I decided to try this out now that XCUITest is in use. I found a good demo page and the results were great:

driver.get("https://auth-demo.aerobatic.io");
driver.get("https://auth-demo.aerobatic.io/protected-standard");
driver.context("NATIVE_APP");
driver.findElement(By.xpath("//XCUIElementTypeTextField[contains(@value,'user')]")).sendKeys("aerobatic");
driver.findElement(By.xpath("//XCUIElementTypeSecureTextField[@value='password']")).sendKeys("aerobatic");
driver.findElement(By.id("Log In")).click();

and

driver.get("https://auth-demo.aerobatic.io");
driver.get("https://aerobatic:[email protected]/protected-standard");
driver.findElement(By.id("ignoreWarning")).click();

both worked well. Just remember to go back to WEBVIEW context, if you decide to go through the first way of doing this.

1 Like

Do you have now any solution for handle the authentication for chrome mobile browser, I am not able to handle please help.

Hi @SumitSharma, Fir chrome mobile browser, simply use http://username:[email protected] and it will work without any issue

thanks man!
This was extremely helpfull!
unfortunatelly the solution with login and passwort in URL did not work for the iOS Safari.

alert did not work too

working with elements started to work when I have changed to the native!
driver.get(“https://www.example.com”);
driver.context(“NATIVE_APP”);
driver.findElement(By.xpath("//*[@type=‘XCUIElementTypeTextField’][@value=‘Login’]")).sendKeys(“Test”);