Wednesday, May 30, 2012
QTP sync on cursor
in the world of SOA, it may take a while for data to get back from the server so the client can display it. In the mean while, the client application maybe hanging waiting for data with special type of cursor. We want QTP to wait for this waiting-cursor to going away before we continue to the next instruction, so below is the code for doing this.
you may want to enhance this to make it wait for a certain amount of time (or after a certain number of try) then throwing error if the waiting-cursor still exist because you don't want to wait forever for the waiting-cursor to go away.
extern.Declare micLong,"GetForegroundWindow","user32.dll","GetForegroundWindow"
extern.Declare micLong,"AttachThreadInput","user32.dll","AttachThreadInput", micLong, micLong,micLong
extern.Declare micLong,"GetWindowThreadProcessId","user32.dll","GetWindowThreadProcessId", micLong, micLong
extern.Declare micLong,"GetCurrentThreadId","kernel32.dll","GetCurrentThreadId"
extern.Declare micLong,"GetCursor","user32.dll","GetCursor"
Public Function get_Cursor(hWnd)
pid = extern.GetWindowThreadProcessId(hWnd, NULL)
thread_id=extern.GetCurrentThreadId()
extern.AttachThreadInput pid,thread_id,True
get_Cursor=extern.GetCursor()
extern.AttachThreadInput pid,thread_id,False
End Function
Function SynOnCursor
Set currentBrowser = GUI_MAP.Item("Browser")
cursor = Util.get_Cursor(currentBrowser.Object.hWnd)
'FREE_CURSOR_IDS = new String[]{/*hand*/"65581", /*arrow*/"65553", /*edit*/"65555", "65557"};
if(cursor = 65581 or cursor = 65553 or cursor = 65555 or cursor = 65557) then
Component.logInfo("SynOnCursor[" & cursor & "] done !")
else
Component.logInfo("SynOnCursor[" & cursor & "]")
wait(1)
SynOnCursor
end if
End Function
Thursday, July 15, 2010
Run QTP testcase with multiple set of data from JUnit
Last time I show you how to run a QTP script with one set of data from JUnit. Today let see how can we run multiple iteration of QTP script with multiple set of data from JUnit.
Thursday, July 8, 2010
Passing data from JUnit to QTP test case
Last time I show you how to invoke a QTP test case from JUnit. Today I want to show you how to pass dynamic data to our QTP test from JUnit so that we can run the same test case with multiple set of data without the need to modify our QTP script. Because JUnit4QTP built on top of Java QTP Communication Channel so from our QTP script we can call back to our java by using JavaObject.invoke function. In Junit we'll implement a getParameter method that will pass the data to our QTP script.
package junit4qtp;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import qtpcommandserver.client.QTP;
public class FlexStoreTest_DynamicData extends TestCase
{
Map dataMap = new HashMap();
public FlexStoreTest_DynamicData()
{
dataMap.put("phonePart1", "917");
dataMap.put("phonePart2", "123");
dataMap.put("phonePart3", "4567");
dataMap.put("password", "secretPass");
}
public String getParameter(String name)
{
return dataMap.get(name);
}
public void testHome() throws Exception
{
QTP.runTest(true, "resources/QTP/FlexStoreHomeTest-DynamicData", this);
}
}

From QTP script we calling back into our JUnit to get the data.
Function getParameter(name)
getParameter = JavaObject.invoke("getParameter", Array(name))
End Function
SystemUtil.Run "C:/Program Files/Internet Explorer/IExplore.exe", "http://examples.adobe.com/flex2/inproduct/lcds/flexstore/flexstore.html"
Browser("FlexStore").Sync
Window("hWnd:=" & Browser("FlexStore").Object.hWnd).Activate
Window("hWnd:=" & Browser("FlexStore").Object.hWnd).Maximize
Window("hWnd:=" & Browser("FlexStore").Object.hWnd).Resize 715, 720
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexTextArea("index:31").Input(getParameter("phonePart1"))
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexTextArea("index:33").Input(getParameter("phonePart2"))
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexTextArea("index:35").Input(getParameter("phonePart3"))
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexTextArea("index:37").Input(getParameter("password"))
if(Browser("FlexStore").FlexApplication("id:=flexstore").FlexCanvas("automationname:=Home").FlexCheckBox("automationname:=Remember my phone number").GetRoProperty("selected") = "True") Then
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexCheckBox("Remember my phone number").Click
end if
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexButton("Login").Click
Browser("FlexStore").FlexApplication("flexstore").FlexAlert("Login").FlexButton("OK").Click
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexButton("Login").Click
if("This feature is not implemented in this sample" <> Browser("FlexStore").FlexApplication("id:=flexstore").FlexAlert("automationname:=Locate").GetRoProperty("text")) then
msgbox("error")
end if
Browser("FlexStore").FlexApplication("flexstore").FlexAlert("Login").FlexButton("OK").Click
Window("hWnd:=" & Browser("FlexStore").Object.hWnd).Close
package junit4qtp;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import qtpcommandserver.client.QTP;
public class FlexStoreTest_DynamicData extends TestCase
{
Map
public FlexStoreTest_DynamicData()
{
dataMap.put("phonePart1", "917");
dataMap.put("phonePart2", "123");
dataMap.put("phonePart3", "4567");
dataMap.put("password", "secretPass");
}
public String getParameter(String name)
{
return dataMap.get(name);
}
public void testHome() throws Exception
{
QTP.runTest(true, "resources/QTP/FlexStoreHomeTest-DynamicData", this);
}
}

From QTP script we calling back into our JUnit to get the data.
Function getParameter(name)
getParameter = JavaObject.invoke("getParameter", Array(name))
End Function
SystemUtil.Run "C:/Program Files/Internet Explorer/IExplore.exe", "http://examples.adobe.com/flex2/inproduct/lcds/flexstore/flexstore.html"
Browser("FlexStore").Sync
Window("hWnd:=" & Browser("FlexStore").Object.hWnd).Activate
Window("hWnd:=" & Browser("FlexStore").Object.hWnd).Maximize
Window("hWnd:=" & Browser("FlexStore").Object.hWnd).Resize 715, 720
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexTextArea("index:31").Input(getParameter("phonePart1"))
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexTextArea("index:33").Input(getParameter("phonePart2"))
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexTextArea("index:35").Input(getParameter("phonePart3"))
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexTextArea("index:37").Input(getParameter("password"))
if(Browser("FlexStore").FlexApplication("id:=flexstore").FlexCanvas("automationname:=Home").FlexCheckBox("automationname:=Remember my phone number").GetRoProperty("selected") = "True") Then
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexCheckBox("Remember my phone number").Click
end if
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexButton("Login").Click
Browser("FlexStore").FlexApplication("flexstore").FlexAlert("Login").FlexButton("OK").Click
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Home").FlexButton("Login").Click
if("This feature is not implemented in this sample" <> Browser("FlexStore").FlexApplication("id:=flexstore").FlexAlert("automationname:=Locate").GetRoProperty("text")) then
msgbox("error")
end if
Browser("FlexStore").FlexApplication("flexstore").FlexAlert("Login").FlexButton("OK").Click
Window("hWnd:=" & Browser("FlexStore").Object.hWnd).Close
Run QTP from JUnit
Run QTP from JUnit is very straight forward. We just need to pass the path to the QTP script to the QTP.run method, and indicate whether we want QTP to be visible or not.
For example
QTP.runTest(false, "resources/QTP/FlexStoreHomeTest");
This statement will run QTP test case from "resources/QTP/FlexStoreHomeTest" with QTP not visible.

Below is the screenshot of my QTP test case
For example
QTP.runTest(false, "resources/QTP/FlexStoreHomeTest");
This statement will run QTP test case from "resources/QTP/FlexStoreHomeTest" with QTP not visible.

Below is the screenshot of my QTP test case
Subscribe to:
Posts (Atom)