1 29 30 package nextapp.echo2.testapp.interactive; 31 32 import java.util.ArrayList ; 33 import java.util.Collection ; 34 import java.util.Collections ; 35 import java.util.HashSet ; 36 import java.util.List ; 37 38 import nextapp.echo2.app.ApplicationInstance; 39 import nextapp.echo2.app.Component; 40 import nextapp.echo2.app.Window; 41 import nextapp.echo2.app.button.AbstractButton; 42 43 46 public class RandomClick { 47 48 52 private static final Collection BUTTON_BLACKLIST; 53 static { 54 Collection blacklist = new HashSet (); 55 56 blacklist.add("Push (Ghost Test)"); 58 59 blacklist.add("Exception"); 61 62 blacklist.add("Random Click"); 64 65 blacklist.add("Delay"); 67 68 blacklist.add("Client Configuration"); 70 71 blacklist.add("Client Exception"); 73 74 blacklist.add("Command"); 76 77 blacklist.add("No Style Sheet"); 79 80 blacklist.add("Image"); 82 83 blacklist.add("Text Sync"); 85 86 blacklist.add("Add Modal Window"); 88 blacklist.add("Add Three Modal Windows"); 89 blacklist.add("Add \"Modal Launching\" Component Sampler to Embedded ContentPane"); 90 91 BUTTON_BLACKLIST = Collections.unmodifiableCollection(blacklist); 92 } 93 94 98 public static void clickRandomButton() { 99 Window window = ApplicationInstance.getActive().getDefaultWindow(); 100 List buttonList = new ArrayList (); 101 findButtons(buttonList, window); 102 AbstractButton button = (AbstractButton) buttonList.get((int) (buttonList.size() * Math.random())); 103 button.doAction(); 104 } 105 106 116 private static void findButtons(Collection foundButtons, Component component) { 117 if (component instanceof AbstractButton && !BUTTON_BLACKLIST.contains(((AbstractButton) component).getText())) { 118 foundButtons.add(component); 119 } 120 Component[] children = component.getComponents(); 121 for (int i = 0; i < children.length; ++i) { 122 findButtons(foundButtons, children[i]); 123 } 124 } 125 126 127 private RandomClick() { } 128 } 129 | Popular Tags |