- 论坛徽章:
- 0
|
package abbot.swingeasytest;
import java.awt.Button;import java.awt.Component;import java.awt.Frame;import java.lang.reflect.Method;
import javax.swing.JButton;
import abbot.finder.matchers.ClassMatcher;import abbot.tester.ButtonTester;
import junit.extensions.abbot.ComponentTestFixture;
public class SwingEasyTest extends ComponentTestFixture{
public void init(Class frameclass,String methodName)throws Exception{ if(methodName==null){ frameclass.newInstance(); }else{ Method method=frameclass.getMethod(methodName); method.invoke(frameclass.newInstance()); } } public Component getComponent(Class component,final String componentName) throws Exception{ return getFinder(). find(new ClassMatcher(component) { public boolean matches(Component c) { return super.matches(c) && ((Button)c).getName().equals(componentName); } }); } public void pressButton(Component component,final String buttonName) throws Exception{ if(component instanceof JButton){ JButton jbutton=(JButton)getComponent(JButton.class,buttonName); ButtonTester buttonTester=new ButtonTester(); buttonTester.actionClick(jbutton); }else if(component instanceof Button){ Button button=(Button)getComponent(Button.class,buttonName); ButtonTester buttonTester=new ButtonTester(); buttonTester.actionClick(button); } } public void enterText(String textName,String text){ }}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/76927/showart_2045106.html |
|