Forum Discussion

KyleMit's avatar
KyleMit
New Contributor
11 years ago

BrowserInfo.Run takes a long time when prompted for credentials with HTTP 401 Challenge

The website we're testing requires a login on first access, so any unauthenticated users are immediately presented with an HTTP 401 Challange, instead of a HTTP 200 Success Page.



However, when calling the Run Function:



browser.Run("url")



the script pauses for a very long time because it is waiting for the full page to be returned.  Once the navigation action times out, then the rest of the script executes and is able to provide the credentials using Aliases.browser.dlgWindowsSecurity.Windows_Security like normal.



This technically works, but at a very high cost for script execution time.



Is there a way to continue running the script as soon as any response is sent from the webpage?
  • Hi Kyle,



    How can I resume execution of a script when the server successfully sends any response requesting credentials?


    Possible solutions depend on your tested website and your test case.



    If your application uses Basic authentication, you can pass the login and password in the URL - this avoids the login prompt:

    Browsers.Item(btIExplorer).Run("http://username:password@www.example.com/path");
    Note: For this to work in Internet Explorer 7+, create the iexplore.exe DWORD value in one of the following registry keys, and set it to 0:

    * For all users:

       HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE

    * For the current user only:

       HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE

    (Source: Microsoft KB article 834489)



    If your test case requires entering the login information manually, you can navigate to your website in a way other than .Run(url). For example, you can pass the URL as a command-line argument to the browser:



    var browserInfo = Browsers.Item(btIExplorer);

    browserInfo.RunOptions = "http://example.com";

    browserInfo.Run();

    In this case, the test run continues without waiting for the page to load.
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Kyle,



    How can I resume execution of a script when the server successfully sends any response requesting credentials?


    Possible solutions depend on your tested website and your test case.



    If your application uses Basic authentication, you can pass the login and password in the URL - this avoids the login prompt:

    Browsers.Item(btIExplorer).Run("http://username:password@www.example.com/path");
    Note: For this to work in Internet Explorer 7+, create the iexplore.exe DWORD value in one of the following registry keys, and set it to 0:

    * For all users:

       HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE

    * For the current user only:

       HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE

    (Source: Microsoft KB article 834489)



    If your test case requires entering the login information manually, you can navigate to your website in a way other than .Run(url). For example, you can pass the URL as a command-line argument to the browser:



    var browserInfo = Browsers.Item(btIExplorer);

    browserInfo.RunOptions = "http://example.com";

    browserInfo.Run();

    In this case, the test run continues without waiting for the page to load.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Kyle,

     


    Let me quote a reply from the Stackoverflow forum that works for you. It might help other community members:


    In VBScript, when you enclose a procedure's argument list in parentheses, you must use the Call keyword:


     




    Call browser.Run("localhost", 2)




    If you omit the Call keyword, you must also drop the parentheses:


     




    browser.Run "localhost", 2



  • KyleMit's avatar
    KyleMit
    New Contributor
    Hi Tanya,

    I appreciate the sentiment, but this doesn't really answer this question.



    It does contain the workaround that I was composing on Stack Overflow, and I agree that providing it here would be better than nothing in case other community members run into this problem, but is still not ideal for a lot of reasons:



    If the server is responding rather slowly one day, it might take longer than the 2 second wait time to get to the HTTP 401 challenge.  On the other hand, most of the time it should take way less than 2 seconds, so the test isn't running nearly as quickly as possible.



    Thus the different question with a sligthly different focus:



    How can I resume execution of a script when the server successfully sends any response requesting credentials?



    Surely other users must be using TestComplete to enter login information.



    The full write up to the workaround, which includes relevant portions of the question text from StackOverflow is that you can pass in the PageLoadWaitTime parameter to the Run or Navigate Methods on the BrowserInfo object in order to set a hard time limit on the amount of time the script will wait for a response of any variety.  



    You can do so like this:









    Also, as technical community manager, you should be aware and help enforce the fact that Stackoverflow operates off a Creative Commons licence. This means if you copy work directly from Stack Overflow, you must cite your sources.



    To do so, here is the aforementioned Stack Overflow question:

    Run method in TestComplete VBScript won't parse Integer Parameter