ScreenCapture in UI Automation

Aug 27 2009 03:31:26 AM Posted By : rajasankar
Comments (0)

ScreenCapture in UI Automation

In UI automation, how to know if the script played correctly?

One way is check the log messages and the check the output. That will be an cumbersome process to do. The better way is to see screenshots of the page. QEngine has a function to do this.

Code:
saveScreenShot(outFileName,waittime)


You can call this way using the python function, if you need to generate filename automatically,

Code:

import time

def screenshot():
filename=time.strftime("%Y_%m_%d_%H_%M_%S")
saveScreenShot(filename,"1")


There is an one limitation. This saves the file as a JPEG format and save the files in dataset folder in the projects.

You can write an Java class to save the images in the PNG format which will occupy less space than JPEG file.

Here is the code
Code:

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.util.Calendar;

public class SaveScreen {

public static void main (String args[])
{
}


public void saveScreen() throws Exception
{

Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH);
int day = now.get(Calendar.DAY_OF_MONTH);
int hour = now.get(Calendar.HOUR_OF_DAY);
int min = now.get(Calendar.MINUTE);
int sec = now.get(Calendar.SECOND);
String fileNameone = "Screenshot_" year "_" month "_" day "_" hour "_" min "_" sec ".png";

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "png", new File(fileNameone));
}

}

You can also change the
Code:

String fileNameone = "Screenshot_" year "_" month "_" day "_" hour "_" min "_" sec ".png";

into
Code:

String fileNameone = foldername "Screenshot_" year "_" month "_" day "_" hour "_" min "_" sec ".png";

if you need to save the files in the required folder.

Refer to the previous blog entry for how to import your own code in the QEngine.

Rajasankar
rajasankar at zohocorp dot com

How to write your own Java code in QEngine.

Aug 26 2009 02:55:27 AM Posted By : rajasankar
Comments (0)

As you know QEngine based on Jython(Java implementation of Python), you can write Java code and import that in QEngine.

Code:

public class test
{
public static void main(String args[])
{
}
public void work()
{

}
}


you can import that like this

Code:

import test as te

t=te();

use the method mentioned there

def makework():
t.work()


If you need to use this method across multiple scripts, you need to create and python file under /QEngine/jars folder and import that in the scripts file

Code:

workfile.py contains

import test as te
t=te();

def makework():
t.work()


Use
Code:

from workfile import *

or
Code:

from workfile import makework


Finally add the class in the classpath. Add this class entry to //bin/StartWebTestServer.bat in "set CLASS_PATH=" line. You need to restart the server after this change.

Rajasankar
rajasankar at zohocorp dot com

Performance Testing Evaluation Guide

Aug 24 2009 12:04:13 AM Posted By : Raghavan
Comments (0)

Hi All,

We have published Performance Testing Evaluation Guide in the QEngine website in the below link,

http://www.manageengine.com/products/qengine/web-performance-evaluation-guide.html

or You can download it as PDF from the below link,

http://www.manageengine.com/products/qengine/web-performance-evaluation-guide.pdf

Raghavan

If you encounter the dynamic windows in the UI automation, you can easily handle them.

Here are the functions available

Code:
setDynamicWindow(parenttitle,parentindex=1,framepropertyname="NONE",framepropertyvalue="NONE",frameindex=1)
closeDynamicWindow(parenttitle,parentindex=1)


If more than one window is present you can use parentindex and frameindex to choose which window.

However, consider this situation. You don't want to enter the title of the window or title keeps changing. What to do in this case?

We need to use the following functions to handle such cases.

Code:
getLastWindowTitle()
getWindowTitle()
getWindowURL()
getLastWindowURL()


I hope the function names are self explanatory. However, we need to use setLastWindow function once we changed the focus.

Example 1.

If the dynamic window doesn't have any inner frames.
Code:


setDynamicWindow("Test page",1,"NONE","NONE",1)

closeDynamicWindow("Test page",1)


Example 2.

If the dynamic window has any inner frames.

Code:


setDynamicWindow("Test page",1,"title","mypage",1)

closeDynamicWindow("Test page",1)


Now consider this case. Windows title is not known or can't be predicted.

Example 3.

Code:

gwt=getWindowTitle()

gwtn=getWindowTitle()
if gwt!=gwtn:
setDynamicWindow(gwtn,1,"NONE","NONE",1)

closeDynamicWindow(gwtn,1)

or

Code:


gwt=getLastWindowTitle()
gwtn=getWindowTitle()
if gwt!=gwtn:
setDynamicWindow(gwtn,1,"NONE","NONE",1)

closeDynamicWindow(gwtn,1)


You can add more conditions if needed

Example 4.

Code:


gwt=getLastWindowTitle()
gwtn=getWindowTitle()
if gwt!=gwtn and gwt!= and gwtn!=:
setDynamicWindow(gwtn,1,"NONE","NONE",1)

closeDynamicWindow(gwtn,1)


This will ensure that dynamic windows are taken care without knowing the window title.

Rajasankar
rajasankar at zohocorp dot com

Why to Parameterize in Load Testing ?

Aug 17 2009 11:17:28 PM Posted By : Raghavan
Comments (0)

Hi All,

We received a good question from one of our customer. The question is

Why should i parameterize the transactions in Load Testing ?

It is indeed a nice question. Actually his question is, i am not configuring those parameters while recording. Then how do i know what are the parameters it takes and its value.

Here is the solution. Yes the user don't know what are all the parameters it takes while submitting a page. Hence in QEngine we introduced a feature called Auto parameterization.

What is Auto Parameterization ?

Auto parameterization facilitates to automatically extract the parameters from the associated reference page and use it while submitting the particular page to the server.
This is what happens while submitting the page while browsing in the browser.

This feature will work perfectly for most cases.

But for some cases the server may require unique value for each virtual user. In those cases, you may be required to parameterize value for the username, password and those parameters which you input during recording in the browser.

For this QEngine easy to use user interface namely Parameterization screen. It will list all the parameters for each URL separately, thus user can easily configure the value for the parameters. QEngine provides various options to parameterize such as Dataset / Cookie / Java script / Previous Response Content / HTML Element / Random values etc.

To know more on parameterization look at the below URL:
http://www.manageengine.com/products/qengine/performance-testing.html

There are still more improvements can be done in parameterization. This will happen in future QEngine releases.

Raghavan


[/b]

There is an endless debate going on in the testing world regarding the strategy for automation testing. What to use, scripting or record/paly back tool?

Before commenting which one is best, we need to understand what are the pros and cons these two.

Let us see pros and cons of scripting

pros
1. Standard scripting language and standard library
2. No vendor scripting
3. Version Control
4. Running with own testsuite or with standard library

cons
1. Need to build from scratch
2. Time consuming process
3. Suited for individual need. May not be applicable to other software
4. Need to identify the elements from source manually.

For record/playback tool,

pros
1. Easy identification of elements
2. Maintenance will be taken care by vendor
3. Will come with utilities to run the test suite
4. Easy setup and running

cons
1. Maintaining the scripts is difficult.
2. Version control may not be available.
3. Vendor scripting may have a deep learning curve

Both the options offer some advantageous. If we can combine both, we can reduce time and do the things in a hassle free manner. That will offer best of both worlds, then it is easier to do automation, Isn't?

So the ideal tool should have the version control, minimal vendor scripting, options for one or more standard scripting languages. Next time when you evaluate an tool, check these options in it.

Rajasankar
rajasankar at zohocorp dot com

Vendor Script Functions in QEngine

Aug 17 2009 01:56:47 AM Posted By : rajasankar
Comments (0)

Vendor Script Functions in QEngine.

Before seeing what are the vendor functions, we need to understand what is Vendor Scripting?

Vendor Scripting defined as script/functions specific to the program or application. In other words, such functions available only in that application and won't be used anywhere else.

Vendor scripts can be a deciding factor in the learning curve of the automation tool. The more vendor scripting, more time needed to learn.

Here is the separation of vendor scirpt and common functions

1. Window Functions or Dynamic Functions
2. HTML Special Functions
3. HTML Check Functions or HTML Get Functions
4. AJAX Functions
5. Invoke Script Functions
6. General Functions (optional)
7. Default Recorded Functions(optional)

Common functions
1. XML Validation Functions
2. String Manipulation Functions
3. File Manipulation Functions
4. E-Mail Functions
5. Date Functions
6. Database Functions

Check this page for all functions available in the QEngine.

Rajasankar
rajasankar at zohocorp dot com

How to follow web links in Dynamic web page

Aug 13 2009 09:00:38 PM Posted By : rajasankar
Comments (0)

In this article, I am going to show, how to follow the web links in the Dynamic web page is easy with QEngine.

Here are the two function used in that.

You can get the DOM element property with the following function,

Code:
getElementProperty(tagName,propertyName,propertyValue,index,propertyNeeded,regExpRequired='false')

You can click on the element using the following function,
Code:
fireEventOnElement(tagName,propertyName,propertyValue,index,actionName,actionValue='',regExpRequired='false')

Here
tagName = DOM tag name such as TD,IMG,SPAN
propertyName= Property of the tag which is used such as Name,ID
propertValue= Value of the property.

First find the values in the page using getElementProperty,

Code:
getElementProperty("A","href",propertyValue,index,"href",regExpRequired='false')


Here the propertyValue is the one we don't know and that one we need. How to get this? Simple, use regex to get any value in href property.

Code:
getElementProperty("A","href",".*",index,"href","true")


Now this will match everything in that property and entire string. Let call this in a loop and get the values as an array.

Code:

i=1
while i>0:
values=[]
setLastWindow()
property=getElementProperty("A","href",".*",i,"href","true")
if property is not None and property!='':
values.append(property)
i=i 1
else:
i=0
return values


Now use the values in the fireEventOnElement function


Code:

for i in range(0,len(values)):
setLastWindow()
fireEventOnElement("A","href",values[i],i,"click","NONE","false")


You can also concatenate the web url if the value is relative.



Code:

for i in range(0,len(values)):
setLastWindow()
url="" values[i]
fireEventOnElement("A","href",url,i,"click","NONE","false")


Bingo!



You can use the same idea for any tag in the web page.

Let me know, how this works.

Rajasankar
rajasankar at zohocorp dot com

In Notepad you can add function complete for custom languages. Existing Auto Completion files can be edited too which means I can add QEngine functions too.

I've spent an hour to add the QEngine functions into python.xml file. Now, I don't have check the Framework.py for the syntax of the functions.

The QEngine script file has extension of .wcs, associate that to the python language and see the difference. Those files will be located in the /QE home/projects//webscripts/< script name>/.

Here is the file, change the extension into .xml and replace that under /Notepad home/plugis/APIs/.

This feature also available in the QEngine inbuilt editor. If you need this one for any other text editor, let me know.

Rajasankar
rajasankar at zohocorp dot com