Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Test and Performance Tools Platform (TPTP) » How to obtain a component of the screen.(To capture Texts, Buttons, Labels inside a Wizard/Shell using AGR)
How to obtain a component of the screen. [message #512306] Thu, 04 February 2010 16:08 Go to next message
Caio Bulgarelli is currently offline Caio Bulgarelli
Messages: 16
Registered: February 2010
Junior Member
During the MACRO, I need to call "hooks" in order to do some Java verifications (JUnit).

For example: If a Button is enabled or if the Text is correct...



I found out this diagram "Googling" on the Web:

http://www.developer.com/img/articles/2004/03/25/figure_01.gif
Figure 1. An SWT application from different perspectives.

OK, Now I need a help.

I need to get a String in TextBox inside a Shell.

http://i752.photobucket.com/albums/xx163/caiob3/shell1.jpg

I got success, but my code was a little confused. =/
Look:
A part of MACRO (XML):
...
<command descriptive="Android" type="item-expand" referenceId="21" value="true">
<item referenceId="22"/>
</command>
<command descriptive="Launch" type="item-select" referenceId="21">
<item referenceId="23"/>
</command>
<command type="verification" contextId=" shell/org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDia log " location="/PluginProject/src" resource="pluginproject.VerificationHookClass003" hook="checkSettings:Qorg.eclipse.swt.widgets.Shell;"/>
<command descriptive="OK" type="select" referenceId="25"/>
</shell>
...


A part of JUnit (JAVA):
public void checkSettings(org.eclipse.swt.widgets.Shell arg0)
throws Exception
{
...

Point p1 = new Point (130, 0); //The 1º TextBox
Point p2 = new Point (130, 24); // The 2º TextBox

Control[] c = arg0.getChildren(); //in oder to get all Components of Shell


//Call function to get the Text inside in the 1º TextBox
recursiveFunction(c, p1);
assertEquals(s, "-no-window");
System.out.println("" + s);

//Call function to get the Text inside in the 2º TextBox
recursiveFunction(c, p2);
assertEquals(s, "android.process.acore");
System.out.println("" + s);

}



/**
* This function collects all components inside a Wizard.
* @param c
* @param p
*/

private void recursiveFunction(Control[] c, Point p) {

for (int k=0 ; k<c.length ; k++)
{
if( ( c[k]) instanceof Text && p.equals(c[k].getLocation())){
s = ((Text) c[k]).getText();
}


else if( ( c[k]) instanceof Composite )
recursiveFunction( ((Composite) c[k]).getChildren(), p );
}

}



The Result is:
http://i752.photobucket.com/albums/xx163/caiob3/result1.jpg


OK, I did... However, Can someone resolve in a better way? Without using "points"?

Thanks a lot!


--
Caio Bulgarelli
R&D - CM - MOTODEV
MOTOROLA BRAZIL
Re: How to obtain a component of the screen. [message #512528 is a reply to message #512306] Fri, 05 February 2010 11:25 Go to previous message
Paul Slauenwhite is currently offline Paul Slauenwhite
Messages: 970
Registered: July 2009
Senior Member
Unfortunately, there is no other cleaner way other than to iterate the
component hierarchy looking for the widget of interest.

We use a utility class in our AGR tests that may be of help:

http://dev.eclipse.org/viewcvs/index.cgi/test-results/platfo rm/org.eclipse.hyades.use.cases/src/org/eclipse/hyades/use/c ases/auto/common/VerifyHookUtil.java?root=TPTP_Project&v iew=log

Paul
"Caio Bulgarelli" <qbxt43@motorola.com> wrote in message
news:hkerd8$os2$1@build.eclipse.org...
> During the MACRO, I need to call "hooks" in order to do some Java
> verifications (JUnit).
>
> For example: If a Button is enabled or if the Text is correct...
>
>
>
> I found out this diagram "Googling" on the Web:
>
>
> Figure 1. An SWT application from different perspectives.
>
> OK, Now I need a help.
>
> I need to get a String in TextBox inside a Shell.
>
>
>
> I got success, but my code was a little confused. =/
> Look:
> A part of MACRO (XML):
> ..
> <command descriptive="Android" type="item-expand" referenceId="21"
> value="true">
> <item referenceId="22"/>
> </command>
> <command descriptive="Launch" type="item-select" referenceId="21">
> <item referenceId="23"/>
> </command>
> <command type="verification" contextId="
> shell/org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDia log "
> location="/PluginProject/src"
> resource="pluginproject.VerificationHookClass003"
> hook="checkSettings:Qorg.eclipse.swt.widgets.Shell;"/>
> <command descriptive="OK" type="select" referenceId="25"/>
> </shell>
> ..
>
> A part of JUnit (JAVA):
> public void checkSettings(org.eclipse.swt.widgets.Shell arg0)
> throws Exception {
> ...
>
> Point p1 = new Point (130, 0); //The 1
Previous Topic:How to use AGR to capture interactions in other environment.
Next Topic:Where is TPTP Manual Test in TPTP-4.6.1?
Goto Forum:
  


Current Time: Thu Oct 23 18:37:38 GMT 2014

Powered by FUDForum. Page generated in 0.01638 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software