Automated testing without automated testing tools


How many automated testing tools exist in the world?

Hm... I think, hundreds - SeleniumQuickTest ProfessionalSilkTestJmeterLoadRunnerSTAFWatirCanoo WebTest, and so on...


Is is possible to perform an automated testing without automated testing tools? Sure!



I will show how to perform automated testing of web applications on Internet Explorer (IE) browser.
The main advantage is that these tests can be run on any Windows computer without any additional sofware required.

Let's see steps of sample test:

  1. Open IE and navigate to google.com:

         2. Set value of edit box to 'Easy way to automate testing':


        3. Click 'Google Search' button


4. If a search results page contains a link to this blog (http://www.testinganswers.com) then click this link:


5. The last step is to close the IE window

I've automated this test with an instance of the InternetExplorer object.

Details info about an InternetExplorer object is located here.


I hope, the source code of my test is clean and understandable. Here it is:

Option Explicit
Dim objIE, objLink
Set objIE = OpenBrowser("http://google.com")

' View the HTML source on Google's page to see the 'q' and 'btnG' values
objIE.Document.All("q").Value = "Easy way to automate testing"
objIE.Document.All("btnG").Click
WaitForLoad(objIE)

' Find a link to http://www.testinganswers.com
Set objLink = GetLinkByHref(objIE, "testinganswers.com")

' If found, then click it
If (False = IsNull(objLink)) Then
    objLink.Click
    WaitForLoad(objIE)
End If

' Close IE window
objIE.Quit
WScript.StdOut.Write("Script completed successfully...")


''''''''''''''''''''''''''''''''''''''''''''''
' Functions 

' Opens IE and navigates to specified URL
Private Function OpenBrowser(URL)
    Dim ie
    Set ie = CreateObject("InternetExplorer.Application")

    ie.Visible = True
    ie.Navigate2 URL
    WaitForLoad(ie)
    
    Set OpenBrowser = ie
End Function

' Waits for page fully loaded
Private Sub WaitForLoad(ie)
    Const WAIT_TIMEOUT = 100

    While (ie.Busy) or (ie.ReadyState <> 4' READYSTATE_COMPLETE = 4
        WScript.Sleep(WAIT_TIMEOUT)
    Wend
End Sub

' Gets Link by 'href' attribute.
' Note: If your need, you can write another function - GetLinkByText
Private Function GetLinkByHref(ie, href)
    Dim Link
    
    For Each Link In ie.Document.Links
        If Instr(LCase(Link.href), LCase(href)) > 0 Then
            Set GetLinkByHref = Link
            Exit Function
        End If
    Next

    Set GetLinkByHref = Null
End Function



How to run this file?
  1. Save this code to file, for example to ieauto.vbs.
  2. To execute this file, run from command line: cscript ieauto.vbs
    or paste this command to bat-file:
    and run the bat-file from command line.


The result of execution is:





Test runs and performs all steps correctly (it opens IE, fills values, clicks button, clicks link, closes IE).


Conclusion:

You can create and use instances of the InternetExplorer object to perform and to test all actions, which you run manually.

Or to do some routine operations in a browser, for example - filling forms, creating test users, and so on.

1 comment:

devo said...

Very interesting blog which helps me to get the in depth knowledge about the technology, Thanks for sharing such a nice blog.. Best IEEE Project Center in Chennai | IEEE Project Center in Velachery.