Automated testing without automated testing tools

Automated testing without automated testing tools

How many automated testing tools exist in the world?
Hm... I think, hundreds - Selenium, QuickTest Professional, SilkTest, Jmeter, LoadRunner, STAF, Watir, Canoo 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:
    Navigation bar
  2. Set value of edit box to 'Easy way to automate testing':
    Filled edit box
  3. Click 'Google Search' button:
    Click 'Google Search' button
  4. If a search results page contains a link to this blog (http://motevich.blogspot.com) then click this link:
  5. Last step is to close the IE window
I've automated this test with an instance of the InternetExplorer object.
Details info about 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://motevich.blogspot.com
Set objLink = GetLinkByHref(objIE, "motevich.blogspot.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.
    Note: You can download archived sample files from here.

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.

--
Dmitry Motevich

21 comments:

Anonymous said...

Great and thanks for sharing, could you please tell me how did you got the code generated please.

Unknown said...

In your list of automation tools you forgot to mention InCisif.net.

InCisif.net is an automation tool designed to implement functional web testing
under Internet Explorer, using languages VB.Net, C# within Visual Studio 2005, 2008 or Express.

You VBScript is actually pretty good.
But InCisif.net comes with a record mode integrated with Visual Studio, and a smart API to look up html controls.
WatiN API is also interesting.

So using an automation tool is worth it.

Anonymous said...

Hi Dmitry,

Amazing, Your postings are subjective. Good going.

Dmitry Motevich said...

2Anonymous:
Google + MSDN :)

Anonymous said...

Dude you are using VB Scripting to do few steps. Its not really testing. Seems like you don't understand the concept of testing...

Dmitry Motevich said...

2Anonymous:
I never said, that I understand the concept of testing.
I would be grateful if you could help me. Thank you in advance, Mr. Anonymous.

Unknown said...

This is neat! Can you do the same thing with Firefox?

Anonymous said...

Hi Dimitry,

Its good to see the tremendous benefits of vbscript to automate the testing w/o tool. However, its easy to automate only those programs, if the "Object Model" for such program is available. Can you guide how to automate "PDF"? For eg. how to get total number of pages in the pdf document. I wouldn't prefer any PAID products like "QTP" to 'spy' the pdf and then find the object model tree. Any other free tool to obtain such object model tree is ok but not a free functional testing tool.

Thanks in advance for your reply.

Dmitry Motevich said...

2Ozmar,
Yes, we can use FF too.
Please, check this link.
I hope, I will be able to prepare tutorial on FireFox XPCOM object in a future.

Dmitry Motevich said...

2Anonymous,
You are lucky :)
I created such tutorial on working with PDF files:
QTP - How to get number of pages in PDF file?

Dmitry Motevich said...

About PDF file...
Code, provided here can work without QTP.

Onsoft Technologies said...

HI Dmitry,

The explaination is pretty good.Could you please tell me how to see the code of vbs for the same
2. is it possible to parameterise the form filling with this method.

Thanks in advance,
Onsoftinc

Dmitry Motevich said...

Freelance Tester (Onsoftinc), (from September 4),

What do you mean with "to see the code of vbs for the same"? Please, explain.

Yes, It is possible to parameterise the form filling with VBScript.

Anonymous said...

Hi,

It's a great effort indeed. Thanks for sharing this information.

Is it possible to automate web pages having Css/or javascript content and not the HTML content as in the case of google?

Kindly let me know. Thanks in advance.

Dmitry Motevich said...

@ Anonymous,
I didn't get you.
What are "web pages having Css/or javascript content and not the HTML content"?
Please provide several links to see such pages.

Anonymous said...

hI

I was referring to some pages having Css/Javascript content embebed in html pages.

Please let me know if the snippet below helps you to explain.
like below (intranet site):

(i cannot post the snippet here as you editor is not letting me to put it up)

Dmitry Motevich said...

@ Anonymous,
Since you couldn't show me sites you mentioned, I'm afraid I cannot help you.

Anonymous said...

hi,

please let me know your email id, i would send the attachments.

thanks a bunch....

Dmitry Motevich said...

@Anonymous.
You can find my email on several posts on my blog.
Apply the efforts to find it.

And please answer the simple question - why should I spend my time to resolve your issue? How I am motivated in this?

Anonymous said...

Hi, its very useful everyone who does testing.Continue adding some concepts like this.....

srinivas said...

Hi Dimtry,
This is really good one. I have learned a lot from this IE Object.
I have a question for you. I want to write an excel macro to up load my test case results into Qualtiy Center. I have successfully uploaded test cases using Add-in but now i want to upload with the results into Quality Center. I searched Google for this but i didn't get proper responce. Please help me to write the code for uploading test case results to (Pass/fail/blocked/No run) quality Center.
Thanks in Advance,
Srinivasachary.