Hi. I am new to Abbot though hav edone quite some work in JUnit. I am able to run all examples like MyCode, FontChooser, CelsiusConverter, etc. that come in the sourceforge site successfully. But I am critically stuck with this problem while trying to do my own code using Abbot, to get a hang of it so that I can actually apply it to my current project. I am already behing schedule for this assignment, so will be grateful to anyone who can give me some hints. Here it seems like Classpath problem, but I have double-checked this possiblity..seems to be Ok.
I am having this class as as GUI class:
package example;
/* FrameDemo.java requires no other files. */
public class GreetingFrameDemo {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//JLabel emptyLabel = new JLabel("");
JButton btnGreeting = new JButton("Greet");
final JTextField txtGreeting = new JTextField(20);
// emptyLabel.setPreferredSize(new Dimension(175, 100));
/*
* Abbot must validate to accept only greetings
* that contain words "hello" and/or "good".
*
* This ensures that the output does not change
* drastically when the code gets changed repeatedly
* by developers.
*/
btnGreeting.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
// txtGreeting.setText("Hello, good morning!");
txtGreeting.setText("hello");
}
});
//Display the window.
frame.setSize(500, 100);
frame.setVisible(true);
frame.setTitle("GreetingFrame");
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
public class GreetingFrameDemoTest extends ComponentTestFixture
{
private JButton btnGreet;
private JTextField txtGreet;
private JButtonTester buttonTester;
private JTextComponentTester textTester;
public GreetingFrameDemoTest(String name)
{
super(name);
}
protected void setUp() throws Exception
{
// display the frame whose components are to be tested
GreetingFrameDemo.createAndShowGUI();
btnGreet = (JButton) getFinder().find(new ClassMatcher(JButton.class) {
public boolean matches(Component c) {
// Add as much information as needed to distinguish the component
return c instanceof JButton && ((JButton)c).getText().equals("Greet");
//return true;
}
});
...(It says "New Script created" on the Costello status-bar)and then trying to launch the Test, it gives an error as "Script file Untitled is empty" in the Eclipse console. In Costello status bar, it gives "Error: ui.GreetingDemo" in the Costello Status bar. When I double click on this, it gives me this stacktrace
(PLEASE DO NOT SAY THAT IT IS A CLASSPATH PROBLEM AS MY CLASS FILES FOR GreetingFrameDemoTest AND GreetingFrameDemo ARE INDEED IN D:\Interstage\APW\eclipse\workspace\UITest\ui):
Hi. I am new to Abbot though hav edone quite some work in JUnit. I am able to run all examples like MyCode, FontChooser, CelsiusConverter, etc. that come in the sourceforge site successfully. But I am critically stuck with this problem while trying to do my own code using Abbot, to get a hang of it so that I can actually apply it to my current project. I am already behing schedule for this assignment, so will be grateful to anyone who can give me some hints. Here it seems like Classpath problem, but I have double-checked this possiblity..seems to be Ok.
I am having this class as as GUI class:
package example;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/* FrameDemo.java requires no other files. */
public class GreetingFrameDemo {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//JLabel emptyLabel = new JLabel("");
JButton btnGreeting = new JButton("Greet");
final JTextField txtGreeting = new JTextField(20);
// emptyLabel.setPreferredSize(new Dimension(175, 100));
/*
* Abbot must validate to accept only greetings
* that contain words "hello" and/or "good".
*
* This ensures that the output does not change
* drastically when the code gets changed repeatedly
* by developers.
*/
btnGreeting.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
// txtGreeting.setText("Hello, good morning!");
txtGreeting.setText("hello");
}
});
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(btnGreeting);
frame.getContentPane().add(txtGreeting);
//Display the window.
frame.setSize(500, 100);
frame.setVisible(true);
frame.setTitle("GreetingFrame");
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
And this class is my Test class:
package example;
import java.awt.Component;
import javax.swing.JButton;
import javax.swing.JTextField;
import abbot.finder.matchers.ClassMatcher;
import abbot.tester.JButtonTester;
import abbot.tester.JTextComponentTester;
import junit.extensions.abbot.ComponentTestFixture;
import junit.extensions.abbot.TestHelper;
public class GreetingFrameDemoTest extends ComponentTestFixture
{
private JButton btnGreet;
private JTextField txtGreet;
private JButtonTester buttonTester;
private JTextComponentTester textTester;
public GreetingFrameDemoTest(String name)
{
super(name);
}
protected void setUp() throws Exception
{
// display the frame whose components are to be tested
GreetingFrameDemo.createAndShowGUI();
btnGreet = (JButton) getFinder().find(new ClassMatcher(JButton.class) {
public boolean matches(Component c) {
// Add as much information as needed to distinguish the component
return c instanceof JButton && ((JButton)c).getText().equals("Greet");
//return true;
}
});
txtGreet = (JTextField) getFinder().find(new ClassMatcher(javax.swing.JTextField.class));
// outputLabel = (JLabel)getFinder().find
// (new ClassMatcher(javax.swing.JLabel.class)
// { public boolean matches(Component c)
// {
// String text = CelsiusConverter.lookupString("output.label.text");
// return super.matches(c) && ((JLabel)c).getText().equals(text);
// }
// }
// );
buttonTester = new JButtonTester();
textTester = new JTextComponentTester();
}
public void testGreeting() throws Exception
{
buttonTester.actionClick(btnGreet);
//tt.actionEnterText(tempCelsius, "-45");
assertEquals("hello", txtGreet.getText());
}
public static void main(String args[])
{
TestHelper.runTests(args, ui.GreetingFrameDemoTest.class);
}
}
Now on creating script using the following details...
target classname: ui.greetingDemo.
classpath: D:\Interstage\APW\eclipse\workspace\UITest\ui
...(It says "New Script created" on the Costello status-bar)and then trying to launch the Test, it gives an error as "Script file Untitled is empty" in the Eclipse console. In Costello status bar, it gives "Error: ui.GreetingDemo" in the Costello Status bar. When I double click on this, it gives me this stacktrace
(PLEASE DO NOT SAY THAT IT IS A CLASSPATH PROBLEM AS MY CLASS FILES FOR GreetingFrameDemoTest AND GreetingFrameDemo ARE INDEED IN D:\Interstage\APW\eclipse\workspace\UITest\ui):
Error: ui.GreetingDemo
java.lang.ClassNotFoundException: ui.GreetingDemo
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at abbot.util.NonDelegatingClassLoader.findClass(NonDelegatingClassLoader.java:32)
at abbot.script.AppClassLoader.findClass(AppClassLoader.java:140)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at abbot.util.PathClassLoader.loadClass(PathClassLoader.java:44)
at abbot.util.NonDelegatingClassLoader.loadClass(NonDelegatingClassLoader.java:42)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at abbot.script.Launch.resolveClass(Launch.java:213)
at abbot.script.Launch.getTargetClass(Launch.java:231)
at abbot.script.Call.getMethods(Call.java:218)
at abbot.script.Call.invoke(Call.java:162)
at abbot.script.Call.runStep(Call.java:129)
at abbot.script.Launch.synchronizedRunStep(Launch.java:138)
at abbot.script.Launch.runStep(Launch.java:203)
at abbot.script.Step.run(Step.java:92)
at abbot.script.StepRunner.runStep(StepRunner.java:277)
at abbot.script.StepRunner.run(StepRunner.java:194)
at abbot.script.Launch.launch(Launch.java:164)
at abbot.editor.ScriptEditor$LaunchAction.run(ScriptEditor.java:2608)
at java.lang.Thread.run(Thread.java:534)....