Friday, March 14, 2008

VisualTest - MS XML Parser

In my first test automation project, I thought to include XML Parser. At that time, XML concept was new and used in many applications. Visual test supports COM DLL calls. I used Microsoft DOM XML parser. XML is a best choice to have the test data.

XML Development Center
XML FAQ

Below I have given the code snippets to parse the XML files.

Code1: To Parse an XML file.



'-----------------------
' Method : XMLParserLoadXML
' Author : T.Palani Selvam
' Purpose : Creates XML Parsing object according to the given XML formatted String, Element .
' Parameters: sXML - String, contains data in XML Format.
' sTag - String, contains element name from which Tag or element based object to be returned.
' Returns : Returns a variant data, which contains XML Parsing object.
' Caller : - Nil
' Calls : - Nil -
'--------------------------------
Function XMLParserLoadXML(sXML As String, sTag As String) As Variant
Dim objXML As Variant, objNode As Variant, objRoot As Variant, objTemp As Variant
Dim iIndex As Integer, iTemp As Integer

XMLParserLoadXML = NULL
sTag = Trim (sTag)
objXML = OleCreateObject ("Microsoft.XMLDOM") 'Declare a Object
OleSetProperty (objXML,"async","False")
OleDispatch (objXML, "loadXML", sXML) 'Load xmlformat String

'OleSetProperty(objXML,"preserveWhiteSpace") = False

If (OleGetProperty(OleDispatch(objXML, "parseError"), "errorCode") <> 0) Then
LogWrite ("Parsing Error in the String :" + sXML, 1)
Exit Function
End If
'Top Node of given file
objRoot = OleDispatch (objXML,"documentElement")


IF ((sTag = "") OR (sTag = OleGetProperty(objRoot, "nodeName"))) Then
XMLParserLoadXML = objRoot
Exit Function
End IF

If OleDispatch (objRoot ,"hasChildNodes") <> 0 Then
objTemp = OleDispatch (objRoot, "ChildNodes")
iTemp = OleGetProperty(objTemp, "Length")

For iIndex = 0 To iTemp -1
objNode= OleDispatch(objTemp, "item",iIndex)
If (Ucase(trim(OleGetProperty(objNode,"nodeName"))) = UCase(sTag)) Then
XMLParserLoadXML = objNode
Exit Function
Else
OleReleaseObject (objNode)
End If

Next iIndex
End IF

objTemp = OleDispatch(objXML,"getElementsByTagName",sTag) 'For test.xml
iTemp=OleGetProperty(objTemp,"Length")
If (iTemp > 0 ) Then
objNode = OleDispatch (objTemp, "item", 0)
XMLParserLoadXML = objNode
End IF

End Function



Code2: It parses the given tag and returns the content.


'-------------------------------------
' Method : XMLParser
' Author : T.Palani Selvam
' Purpose : Creates XML Parsing object according to the given XML Format File and Element,
' which gives starting or root element of that object.
' Parameters: sXMLFile - String, contains a file name, which is in XML Format.
' sTag - String, contains element name from which Tag or element based object to be returned.
' Returns : Returns a variant data, which contains XML Parsing object.
' Caller : RunTestCase()
' Calls : - Nil -
'------------------------------------
Function XMLParser(sXMLFile As String, sTag As String) As Variant
Dim objXML As Variant, objNode As Variant, objRoot As Variant, objTemp As Variant
Dim iIndex As Integer, iTemp As Integer

XMLParser = NULL
sTag = Trim (sTag)
objXML = OleCreateObject ("Microsoft.XMLDOM") 'Declare a Object
OleSetProperty (objXML,"async","False")
OleDispatch (objXML, "load", sXMLFile) 'Load xmlformat file

'OleSetProperty(objXML,"preserveWhiteSpace") = False

If (OleGetProperty(OleDispatch(objXML, "parseError"), "errorCode") <> 0) Then
LogWrite ("Parsing Error in the File : " + sXMLFile, 1)
Exit Function
End If
'Top Node of given file
objRoot = OleDispatch (objXML,"documentElement")

Print OleGetProperty(objRoot, "nodeName") + " Name of the node.."

IF ((sTag = "") OR (sTag = OleGetProperty(objRoot, "nodeName"))) Then
XMLParser = objRoot
Exit Function
End IF

If OleDispatch (objRoot ,"hasChildNodes") <> 0 Then
objTemp = OleDispatch (objRoot, "ChildNodes")
iTemp = OleGetProperty(objTemp, "Length")

For iIndex = 0 To iTemp -1
objNode= OleDispatch(objTemp, "item",iIndex)
If (Ucase(trim(OleGetProperty(objNode,"nodeName"))) = UCase(sTag)) Then
XMLParser = objNode
Exit Function
Else
OleReleaseObject (objNode)
End If

Next iIndex
End IF

objTemp = OleDispatch(objXML,"getElementsByTagName",sTag) 'For xml Format
iTemp=OleGetProperty(objTemp,"Length")
If (iTemp > 0 ) Then
objNode = OleDispatch (objTemp, "item", 0)
XMLParser = objNode
End IF

End Function

Thursday, March 13, 2008

Writing a Problem Report

Many testers are not concentrating the details, while entering a defect. I have seen few guys entering just one line as bug description. Also they are not ready to put the details of the environment. For few scenarios, they can improve it by attaching proper snapshots. As a tester, we should give the right steps to reproduce the issue. Managers should not encourage informal ways like oral communication, email notes, etc.

Cem Kaner has written few articles about Bug Advocacy.
Bug Advocacy: PDF
Bug Advocacy: Video

Also I would like to give two quotes from his famous book.
Book: Testing Computer Software By Cem Kaner, Jack Falk, Hung Quoc Nguyen
ISBN: 0471358460

Quote1:

If your reports are not clear and understandable, bugs won't get fixed. You should spend minimum time needed to describe a problem in a way that maximizes the probability that it will be fixed. The content and tone of your reports affect that probability. The point of writing problem reports is to get bugs fixed.


Quote2:
Nobody likes being told that what did wrong, wrong, wrong. As a tester, that's what you tell people everyday. You can ensure your unpopular by describing problems in a way that tells the programmer you think (s)he is sloppy, stupid or unprofessional.

Wednesday, March 12, 2008

4test - Search and Replace

One project required to replace certain tags at every build. I written this function SearchAndReplaceInFile. This code snippet to search and replace strings in a file.

Code:



[+] public void SearchAndReplaceInFile (STRING sFileInput, STRING sFileOutput, STRING sSearch, STRING sReplace )
HFILE hInFile, hOutFile
STRING sTemp, sLine, sValue
INTEGER iPos1, iPos2

hInFile = FileOpen (sFileInput,FM_READ)
hOutFile = FileOpen (sFileOutput, FM_WRITE)

[-] while (FileReadLine (hInFile, sLine))
sTemp = sLine
[-] if !(Trim(sSearch) == Trim (sReplace))
ReadLine:
iPos1 = StrPos (sSearch,sTemp)
//Print ("Position {sTemp} - {sSearch} : {iPos1}")
[-] if (iPos1 > 0)
sValue = StrTran (sTemp, sSearch, sReplace)
//Print ("got value: {sValue}")
sTemp = sValue
goto ReadLine
FileWriteLine(hOutFile,sTemp)
FileClose (hInFile)
FileClose (hOutFile)

Documenting automated Scripts

Recently a colleague (new to our team) asked me the documentation for our suite. I do not have any document or HELP files. Earlier My team thought about it and one member came with a silktest script to do that. We have to add more features like search, organizing by attributes. That utility did not give the most needed feature. To ease the documentation job, we need to use set of tags and detailed info for them. We are unable to follow this more than a week.

Most of the automated testing tools are not having documenting facility. I am expecting similar to PerlDoc (for Perl scripts) or JavaDoc (for Java). It is the duty of script developer to ensure the adequate comments for particular function or code block. I used to put two or three line comments, While writing the functions.

Generally these kind of tools or utilities, have a parser. It can parse the source code and get the details by the pre-defined tags or keywords. Then It creates the HELP files for each code block or script. The usage will be meaningful if documentation is regularly updated. Now most utilities are creating HTML files and it is easy to navigate and share the information. I was going through J2Se doc comments. JavaDoc is having the flexibility of including HTML tags.

Friday, March 7, 2008

Recursive technique

I am very much interested to include the recursive technique. It is simplifying the code and reduce the number of lines. You can get the definition on Wiki. Below I have given the sample 4test code. This code snippet will get child objects from the given container object.



[+] public LIST OF WINDOW GetChildObjects(Window wContainer, DATACLASS dcObject)
// To get All child objects.
// Used recursive method.
LIST OF WINDOW lwndObjects, lwTemp1, lwTemp2
LIST OF WINDOW lwndChildren = {...}
WINDOW wParent, wChild, wTemp

[+] do
[+] if (wContainer.Exists (10))
lwndChildren = wContainer.GetChildren (TRUE, FALSE)

[+] for each wChild in lwndChildren
[+] if wChild.IsOfClass(dcObject)
ListAppend (lwndObjects,wChild)
[+] else
lwTemp1 = wChild.GetChildren(TRUE, FALSE)
[+] if (ListCount(lwTemp1) > 1)
lwTemp2 = GetChildObjects(wChild,dcObject) //To get particular objects
[+] if (ListCount(lwTemp2) > 0)
ListMerge (lwndObjects, lwTemp2)
[+] else
Print ("Container {[STRING]wContainer} window is not available.")
[+] except
ExceptLog ()

return lwndChildren

Thursday, March 6, 2008

Silktest - Mouse Coordinates Off

Every Silktest automation engineer should have faced this problem. Generally this error is raised if the object co-ordinates are bit higher than total size of the monitor. Sometimes, silktest is not able to scroll down to click particular objects. This problem may occur due to Resolution Change or dual monitor setup.

In this situation, You can do following things and use the better one.

1. Clear the following options from Options->Agent Options.


  • Verify that windows are exposed

  • Verify that coordinates passed to a method are inside the window


OR Set by coding . Set agent option like this -> Agent.SetOption (OPT_VERIFY_COORD, FALSE)

2. Try to use ScrollIntoView() or setFocus().

3. DoClick () method if that particular object has support.

4. Write a function to click particular object, which is outside of the monitor co-ordinates.

Wednesday, March 5, 2008

Getting Link count in Winrunner

I used to write hardcore code for Automation. I had a situation like, the script has to find searched items and it has to click on particular search item. Also I need to test pagination. The search results are dynamic and I need to select the items as well as need to verify the pagination links.

The following TSL snippet finds the number of links and number of rows in a given table.



public aRowCount, aColCount;
public aCell;
public aRow, aCol;
public aTemp;
public aItem, ar, ac;

public alinkcount, alinkrow;
public aout, atext;
public areturn;

# Browser Main Window
win_activate ("Browser Main Window");

# Search Items
set_window ("Search Items", 2);
wait(5);

tbl_get_rows_count("Link No", aRowCount);
tbl_get_cols_count("Link No", aColCount);

report_msg (aRowCount & " is row count");
report_msg (aColCount & " is col count");

alinkrow = 0;
alinkcount =0;
for (arow=1;arow<= aRowCount; arow++) {
web_obj_get_child_item( "Link No", arow, 1, "html_text_link", 0, aout);

report_msg (aout & " -link description");
if (length(aout) !=0 ) {
alinkcount = alinkcount + 1;
#web_tbl_get_cell_data("Link No",arow,aColCount,0,atext,areturn);
web_obj_get_child_item( "Link No", arow, aColCount, "",0 , atext);
report_msg(atext & " text in the cells");
if (length(atext) !=0 ) {
alinkrow = alinkrow + 1;
}
report_msg(alinkcount & " - total no of links in the table.");
report_msg(alinkrow & " - total no of links having full rows.");
}
}

pause(alinkcount & " - total no of links in the table.");
pause(alinkrow & " - total no of links having full rows.");

Tuesday, March 4, 2008

Web Testing & Client server testing

Server process:

 Server programs generally receive requests from client programs, execute database retrieval
and updates, manage data integrity
and dispatch responses to client requests. The serverprocess acts as a software engine
that manages shared resources such as databases, printers, communication links, or high
powered-processors.It is the backend process of the application.

Client process:

Client programs usually manage the user-interface portion of theapplication, validate data
entered by the user, dispatch requests toserver programs, and sometimes execute business logic.
The client-based process is the front-end of the application.It is the interaction between the user and the rest of the application
system.



In client server testing test engineer are conduct the following testings:-

1.Behaviour testing(GUI TESTING)

2.Input domain testing

3.Error Handling testing

4.Backend testing

In Web testing test engineer are condut the following testings:-

1.Behaviour Testing

2.Static web testing

3.Input domain testing

4.Backend testing

5.Error handling testing

5.Frame Level testing


Difference between Application server and Web server:

Application server

Web server

Developers can create, test, and execute application components

It is designed to create and deploy Web site, serving up content more so than applications.

These are typically J2EE-based, running EJBs or other Java components.

It supports JSP,servlets and ASP

Application servers are designed to create true applications with complex business logic,

Web servers are technology designed to create and deploy Web site serving
up content more so than applications, serving

Application Server supports HTTP,TCP/IP and many more protocols.

A Web Server understands and supports only HTTP protocol


Capturing failures

In the previous post, we have seen the importance of Test Results Reporting. Capturing failures is helpful to debug the failure. Script will try to capture the error message in case of failure. If it is unable to capture the expected message or details, then it will capture the screen shot of particular object or screen. Usually these snapshots are bitmap files. Later I used an utility to convert a bitmap image to GIF image. It helps me to reduce the storage space.

Most of the load testing tools are capturing the objects as images or HTML files. Now Functional tools also providing this feature. Silktest provides the same feature through TrueLog Explorer. It is available from Silktest8.0 I hope that QTP also has same feature in different name.

Monday, March 3, 2008

Test Results Reporting

Results Reporting is very much important as automating functionalities. It will be better, if results are logged with screen shots for failed cases. Most of us, not concentrating much on Results Reporting. It will improve your automation level higher.

Automation Engineers are developing lot of test scripts. How will you check all scripts results? We can't check each testcase by testcase. Summary of test results is so important. Also the compiled results for all results is good to have.

Long back, I studied one article related with Automatic Results processing. That document discussed about extracting some keywords from particular log files and store the results in different format. I have implemented using Excel sheet and it will give result for each testcase(function) as well as compiled result for each scripts. If summary and results are stored into HTML files, we can easily get to know the results.

I agree, however one person need to look the results. Some of the tools are giving summary details after execution. I want to go one step ahead. I need to see all automation results of particular project from one file (HTML or Flat file or XL sheet). It is like maintaining history.

But Results processing is very common for test automation as well as general applications. You can follow like any standard log files format. You can maintain 2-3 log files for single script. One for all the activities of your suite and another one for Just giving Pass or Fail result for each testcase. It will be better, if all the log files are HTML files. At last prepare a single file to show the compiled results for the whole execution. You can publish the results easily.