You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Vicente de Rivera III <th...@gmail.com> on 2009/10/14 02:48:49 UTC

JUnit4 + Pivot

This is my first time really writing an actual test, and the Automation
class is way awesome! Got it working within my app's code.Now I'm trying to
make it work with JUnit4

public class LoginTest extends Main implements Application {    public
LoginTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();
        Locale.setDefault(new Locale("en", "PH"));
        DesktopApplicationContext.main(LoginTest.class,
                new String[]{"--width=" + ((int) screenSize.getWidth() -
250), "--height=" +
                    ((int) screenSize.getHeight() - 240), "--center=true"});
    }

    @Test
    public void testLogin() {
        loginController.initPivotAutomationIDs();
        PushButton pb = (PushButton) Automation.get("loginB");
        TextInput usernameTi = (TextInput) Automation.get("usernameTI");
        TextInput passwordTi = (TextInput) Automation.get("passowrdTI");
        usernameTi.setText("user");
        passwordTi.setText("user");
        pb.press();
    }
}

I get a NullPointerException for loginController, seems startup is not being
called, I initialize loginContoller in the startup method.
Oh well, I'll just extend LoginController and name it LoginControllerTest
and also implements Automatable and contain test codes.

I'm excited to make an ArrayList of Automatable then test everything!!! :D

Great morning everyone!
-
thirdy/vicente

Re: JUnit4 + Pivot

Posted by Greg Brown <gk...@mac.com>.
A Spring mailing list is probably a better place to post questions such as this...
 
On Wednesday, October 14, 2009, at 07:36AM, "Vicente de Rivera III" <th...@gmail.com> wrote:
>

Re: JUnit4 + Pivot

Posted by Vicente de Rivera III <th...@gmail.com>.
actually I'd like to ask, what's the difference with
import org.springframework.transaction.annotation.Transactional;
@Transactional
@PersistenceContext(unitName="BIS")

and

import org.springframework.orm.jpa.support.JpaDaoSupport;
public class ClientDAO extends JpaDaoSupport

got a 'trauma' using plain JPA, so I'm thinking that extending JpaDaoSupport
( so I won't touch an EntityManager ) would make everything safe and sound
:D

Re: JUnit4 + Pivot

Posted by Sandro Martini <sa...@gmail.com>.
Hi,

> ApplicationContext.recordActions( "addEmployeeTestCase1Script.txt" );
>
> And Pivot would automatically record all actions made by every Component and
> simulate it by
>
> ApplicationContext.startActions( "addEmployeeTestCase1Script.txt" );
>
> this way almost nothing would invalidate the "screen based test" (I'd like
> to call it "actual usage test" :D).

And so why not think at a new, dedicated subclass of
ApplicationContext, specific for Tests (started by JUnit or maybe
standard executions) ...

Comments / ideas ?


> Right now I'm trying to use Spring in my app, any advice? (my app is just a simple data-centric/crud w/ pivot ui-app)
I used Spring (but not too much :-( ), and without JPA, sorry ...

For some webapps in last months I'm rethinking all the infrastructure,
so instead of plain java (and classic frameworks) I'm starting to
evaluating Groovy and Scala (and Jython for some things), with great
web frameworks like Grails (it uses Spring and Hibernate, but hiding
them as much as possible !!) ... maybe there you can find some
inspiration ...

In any case I'd suggest you to avoid direct usage from Clients of
Server Objects (if not only for Domain Objects), and rely only of JSON
or XML data exchange, and have that data converted to Domain Objects
(shared between server and client code ... in ejb terms this is part
of ejb client).

Uh, sorry in your application the data is on server, right ?
Because if you have direct access to data (the data is on the client)
probably my previous point could not apply (too much) ...

Bye,
Sandro

Re: JUnit4 + Pivot

Posted by Vicente de Rivera III <th...@gmail.com>.
>
>
> your code seem very interesting, the Automation part was made to
>
>
whoa, thanks! haha

Better if we could just call

ApplicationContext.recordActions( "addEmployeeTestCase1Script.txt" );

And Pivot would automatically record all actions made by every Component and
simulate it by

ApplicationContext.startActions( "addEmployeeTestCase1Script.txt" );


this way almost nothing would invalidate the "screen based test" (I'd like
to call it "actual usage test" :D).

Right now I'm trying to use Spring in my app, any advice? (my app is just a
simple data-centric/crud w/ pivot ui-app)

Re: JUnit4 + Pivot

Posted by Sandro Martini <sa...@gmail.com>.
Hi Vicente,
your code seem very interesting, the Automation part was made to
handle automated tests, but your loginController that generates an NPE
is a thing that needs some investigation, I think this is a field that
we should be able to make it run. To accelerate test execution maybe a
flag or other that disable completely effects (transitions, etc) could
help.
Probably Greg or Todd can tell you something more on this.

On the robot usage, I don't like the hardcoded coordinates way,
because changing scale factor, or fonts or other invalidates
completely the test ... but all screen based test approach works this
way so for this I think the only thing we can do is being able to ask
a component for its bounding box coordinates (start and end, or start
and width and height), and maybe knowing the current scale factor
could help so test code could make necessary multiplications ...
Again, Greg or Todd can tell you something more on this.


Comments / ideas ?


Good work.

Bye,
Sandro

Re: JUnit4 + Pivot

Posted by Vicente de Rivera III <th...@gmail.com>.
Got my robot code working,

    public void startSimulation(String finalName) throws Exception {
        Robot robot = new Robot();

        FileReader fr = new FileReader(finalName);
        BufferedReader br = new BufferedReader(fr);
        System.out.println("START SIMULATION");
        while (br.ready()) {
            Thread.sleep(delay);
            String action = br.readLine();
            if (action.equals("click")) {
                System.out.println("CLICK:" + action);
                robot.mousePress(InputEvent.BUTTON1_MASK);
                robot.mouseRelease(InputEvent.BUTTON1_MASK);
            } else if (action.indexOf(',') != -1) {
                System.out.println("MOVE:" + action);
                StringTokenizer st = new StringTokenizer(action, ",");
                int titleBarSize = 20;
                int frameBorderSize = 3;
                int x = new Integer(st.nextToken()) + frameBorderSize;
                int y = new Integer(st.nextToken()) + titleBarSize;
                robot.mouseMove(x, y);
            } else {
                System.out.println("PRESS:" + action);
                int keycode = new Integer(action);
                robot.keyPress(keycode);
                robot.keyRelease(keycode);
            }
        }

    }

        private  PrintWriter pw;
        private int delay = 0;

    public void startRecord(String fileName) throws Exception{
        pw = new PrintWriter(fileName);
        System.out.println("START RECORDING");
        window.getComponentMouseListeners().add(new
ComponentMouseListener.Adapter() {

            @Override
            public boolean mouseMove(Component component, int x, int y) {
                System.out.println("x: " + x + " y: " + y);
                pw.println(x + "," + y);
                return false;
            }
        });

        window.getComponentMouseButtonListeners().add(new
ComponentMouseButtonListener.Adapter() {

            @Override
            public boolean mouseClick(Component component, Button button,
int x, int y, int count) {
                System.out.println("click");
                pw.println("click");
                return false;
            }
        });

        window.getComponentKeyListeners().add(new
ComponentKeyListener.Adapter() {

            @Override
            public boolean keyPressed(Component component, int keyCode,
KeyLocation keyLocation) {
                System.out.println(keyCode + "");
                pw.println(keyCode + "");
                return false;
            }
        });

    }

Works only if x and y or the host frame is both 0. The tile bar
height border width of the HostFrame is also estimated.
How about making this a utility in pivot?

On Wed, Oct 14, 2009 at 11:13 AM, Vicente de Rivera III <
thirdy.derivera@gmail.com> wrote:

> On third thought, I'll just have to do manual testing. The animation
> effects make it complicated to test my pivot app ( I need to test CRUD
> functionally w/ a tableViewRowEditor ).
> I think I'll just code for a Java Robot that can replicate an actual usage
> case of my app. Any open source library that already does this?
>
> On Wed, Oct 14, 2009 at 9:05 AM, Vicente de Rivera III <
> thirdy.derivera@gmail.com> wrote:
>
>> On second thought, i really need to run my pivot app many times for each
>> test
>
>
>

Re: JUnit4 + Pivot

Posted by Vicente de Rivera III <th...@gmail.com>.
On third thought, I'll just have to do manual testing. The animation effects
make it complicated to test my pivot app ( I need to test CRUD functionally
w/ a tableViewRowEditor ).
I think I'll just code for a Java Robot that can replicate an actual usage
case of my app. Any open source library that already does this?

On Wed, Oct 14, 2009 at 9:05 AM, Vicente de Rivera III <
thirdy.derivera@gmail.com> wrote:

> On second thought, i really need to run my pivot app many times for each
> test

Re: JUnit4 + Pivot

Posted by Vicente de Rivera III <th...@gmail.com>.
On second thought, i really need to run my pivot app many times for each
test