UI tests on MAC (JUnit, Fest) [message #721168] |
Thu, 01 September 2011 05:28 |
shca08-eclipse Messages: 5 Registered: September 2011 |
Junior Member |
|
|
I wrote a test that uses FEST to open a JFrame and then the AWT Robot to perform some actions. It works fine on Windows. On Mac, if I run the same class as a Java App (ie. main()) then it works there too. But if I run it as a JUnit plugin test, the frame is never shown, the mouse is stuck in the middle of the screen, and lots of these errors are generated...
2011-08-23 16:37:37.686 java[87274:10c03] *** -[NSConditionLock
unlock]: lock (<NSConditionLock: 0x1006a5b90> '(null)') unlocked when
not locked
2011-08-23 16:37:37.686 java[87274:10c03] *** Break on _NSLockError() to debug.
I made an even simper test without FEST and when run as either a Java App or a JUnit test, I get the above errors and the button isn't manually clickable during the pause before things end (but it is on Windows) - the mouse pointer changes to the busy cursor over the frame.
Any ideas what's going on here? I tried removing some of the cmd line options that said online caused issues in similar cases but that didn't help. And the only other things I found searching were Eclipse Bugs 106769, 268420, 295670.
Here's my env (with a few things ellipsed out)...
!SESSION 2011-09-01 00:46:12.932 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_26
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments: -version 3 ... -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames ....MacTests -application org.eclipse.pde.junit.runtime.coretestapplication -testpluginname ...
Command-line arguments: -os macosx -ws cocoa -arch x86_64 -consoleLog -version 3 ... -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames ....MacTests -application org.eclipse.pde.junit.runtime.coretestapplication -data /Users/remote/workspace/../junit-workspace -dev file:/Users/remote/workspace/.metadata/.plugins/org.eclipse.pde.core/pde-junit/dev.properties -os macosx -ws cocoa -arch x86_64 -consoleLog -testpluginname ...
Here are my tests...
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import junit.framework.TestCase;
import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.edt.GuiQuery;
import org.fest.swing.fixture.FrameFixture;
public class JavaRobotExample extends TestCase
{
Robot robot = new Robot();
public static void main(String[] args) throws AWTException
{
new JavaRobotExample();
}
public void testRobot() throws AWTException
{
new JavaRobotExample();
}
public JavaRobotExample() throws AWTException
{
showFrame();
robot.setAutoDelay(40);
robot.setAutoWaitForIdle(true);
robot.delay(4000);
robot.mouseMove(40, 130);
robot.delay(500);
System.exit(0);
}
private void showFrame()
{
JFrame frame = GuiActionRunner.execute(new GuiQuery<JFrame>()
{
@Override
protected JFrame executeInEDT()
{
String testName = "Mac Frame Test";
JFrame frame = new JFrame(testName);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton btn = new JButton("Click Me");
btn.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println("Hello World!");
}
});
JTextField field = new JTextField();
frame.add(field);
frame.pack();
return frame;
}
});
FrameFixture win = new FrameFixture(frame);
win.show(new Dimension(1000, 1000));
win.moveToFront();
win.moveTo(new Point(0,0));
}
}
=====
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import junit.framework.TestCase;
public class MacTests extends TestCase
{
public static void main(String[] args)
{
new MacTests().testFrame();
}
public void testFrame()
{
String testName = "Mac Frame Test";
JFrame frame = new JFrame(testName);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton btn = new JButton("Click Me");
btn.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println("Hello World!");
}
});
frame.add(btn);
frame.pack();
frame.setVisible(true);
frame.requestFocus();
frame.setAlwaysOnTop(true);
pause(10); // wait 10 secs
}
}
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02050 seconds