Handling Login Windows in Web Applications that Use the Classic Agent

This procedure describes how to handle web applications with different possible startup pages or dialog box objects that use the Classic Agent. For example,

  • A Web application requires the user to login the first time he or she visits the site in a day (a non-persistent cookie). If the user has already logged in for this browser session, the user will not be prompted for user name and password again, as the "cookie" is still available with their authorization. This could be either a login web page or a dialog box.
  • A dialog box that sometimes gives a "tip of the day" or reminds the user to perform some action because it is a certain date.
  • A dialog box might popup asking the user whether it is okay to download a certificate, a Java module, or some other component.

In cases such as these, you can use the sLocation data-member from the wMainWindow object as a property. You can create a property and it will look exactly like a data-member and will be called like a data-member. When trying to retrieve information from a property the Get portion of the property is executed. And you can add code to deal with login Web pages here.

Here are the steps of what will happen when DefaultBaseState runs:

  1. DefaultBaseState will try to retrieve the sLocation data-member and, as such, will execute the Get function.
  2. The Get function that is part of the property will actually load the web page by putting the URL of the page into the Location comboBox that is part of the browser and pressing Enter. It will then wait for the browser to report to Silk Test Classic a ready state.
  3. If the Login page exists rather than the page we were expecting, the user name and password will be entered and the HtmlPushButton OK will be clicked. Again, Silk Test Classic will wait for the browser to return to a ready state.
  4. The Get function returns a NULL even though at the definition of the Get function it was specified that a STRING would be returned. If you were to return the URL, DefaultBaseState would load the page again. Of course, since we have already dealt with login, it would work this time, but would add some more time into the process by loading the page again.
  5. Although DefaultBaseState will not try to load the page, it will find it there and continue with the other steps of closing any open windows and setting the browser and Web page active.

    You can also handle unexpected and occasional dialog boxes in this way, by changing the sLocation data-member to a property and handling different possibilities through a Get function that is part of the property, or you can re-write the Close method. For expected security or login dialog boxes, you can set the sUsername and sPassword for the wMainWindow object.

    Window BrowserChild RealPage
    const PAGE_URL = http://www.somepage.com
    property sLocation
    STRING Get ( )
    
    // actually load the page
    Browser.SetActive ( )
    Browser.Location.SetText (PAGE_URL) 
    Browser.Location.TypeKeys ("<Enter>") 
    
    // wait for the browser to be "ready" Browser.WaitForReady ( )  
    // if the Login page has shown up…
    if Login.Exists ( ) 
    
    // deal with it
    Login.UserName.SetText (USERNAME)
    Login.Password.SetText (PASSWORD)
    Login.OK.Click ( )
    
    // now wait for the browser to be ready
    Browser.WaitForReady ( ) 
    
    //this way DefaultBaseState will not try to load the page again
    return NULL