How to obtain a component of the screen. [message #512306] |
Thu, 04 February 2010 11:08  |
Eclipse User |
|
|
|
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º 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:

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 06:25  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.05514 seconds