Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Basic Authentication with Chrome and Firefox

Basic Authentication with Chrome and Firefox

Missing basic authentication test support is a general issue and depends on how the browser vendors are supporting it.  As an example there is an open Chrome bug report here that states that the webdriver is at fault:

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1917
 
However, for both Chrome and Firefox, Silk Test can be used to overcome the authentication URL problem when a test starts.
 

Workaround for Chrome:
---------------------------
 
The following .NET script is using 'http://the-internet.herokuapp.com/basic_auth' as the authentication example. Ensure that the starting page of the script is 'about:blank' or another non-basic-authentication URL.
 
Imports SilkTest.Ntf.XBrowser
Imports SilkTest.Ntf.Win32
Imports System.Threading
Imports System.Console
 
Public Module Main
    Dim _desktop As Desktop = Agent.Desktop
 
    Public Sub Main()
        ' calculate encrypted password token that can be used in password fields instead of plain password
        Console.WriteLine("Password token: " + Agent.Encrypt("admin"))
        
        ' enter URL and navigate using accessibility
        With _desktop.AccessibleControl("//BrowserApplication//AccessibleControl[@caption='Address and search bar']")
            .Click()
            .TypeKeys("<Ctrl+A>")
            .TypeKeys("http://the-internet.herokuapp.com/basic_auth")
            .TypeKeys("<Enter>")
        End With
        
        ' wait a moment until document is loaded
        Thread.Sleep(2000)            
 
        ' enter credentials using Win32 type keys
        With _desktop
            .TypeKeys("admin<Tab>")
            .TypePasswordKeys("5ERzHMbN") ' password token for "admin"
            .TypeKeys("<Enter>")
        End With
 
        ' verify basic authentication succeeded
        With _desktop.BrowserWindow()            
            Workbench.Verify("Basic Auth", .DomElement("//H3").Text)
        End With        
    End Sub
End Module

 
Workaround for Firefox:
-------------------------

A similar script works for Firefox using the Alert API. This has been tested against Firefox 58:
 
 
Imports SilkTest.Ntf.XBrowser
 
Public Module Main
    Dim _desktop As Desktop = Agent.Desktop
 
    Public Sub Main()
        _desktop.BrowserApplication.Navigate("http://the-internet.herokuapp.com/basic_auth")
        
        ' enter credentials using Alert API backed by Selenium
        Dim seleniumTabKey = Convert.ToChar(&HE004)  
        Dim myUserName As String = "admin"
        Dim myPassword As String = "admin"
        _desktop.BrowserWindow().AcceptAlert(myUserName & seleniumTabKey & myPassword)  
        
        ' verify basic authentication succeeded
        With _desktop.BrowserWindow()            
            Workbench.Verify("Basic Auth", .DomElement("//H3").Text)
        End With
    End Sub
End Module
 
There is an alternative and that is to install browser extensions that support auto-login. However, this may fall foul of company security requirements.

Chrome: https://chrome.google.com/webstore/detail/multipass-for-http-basic/enhldmjbphoeibbpdhmjkchohnidgnah?hl=en
Firefox: https://addons.mozilla.org/en-US/firefox/addon/autoauth/

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2018-04-24 21:57
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.