~ubuntu-branches/ubuntu/utopic/sikuli/utopic

« back to all changes in this revision

Viewing changes to extensions/guide/src/test/java/org/sikuli/guide/test/SikuliGuideTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Gilles Filippini
  • Date: 2011-04-16 00:23:53 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110416002353-cn79cto3c03z5jx1
Tags: 1.0~x~rc2-dfsg1-1
* New upstream release:
  + Redesigned user interface for Sikuli-IDE
  + Support for extensions for Sikuli Script

* debian/control, debian/copyright:
  The package is now maintained by the Debian Java maintainers Team

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.sikuli.script.guide.test;
 
2
 
 
3
import java.awt.AWTException;
 
4
import java.awt.Robot;
 
5
 
 
6
import org.junit.Test;
 
7
import org.sikuli.guide.SikuliGuide;
 
8
import org.sikuli.script.App;
 
9
import org.sikuli.script.Debug;
 
10
import org.sikuli.script.FindFailed;
 
11
import org.sikuli.script.FindFailedResponse;
 
12
import org.sikuli.script.Location;
 
13
import org.sikuli.script.Pattern;
 
14
import org.sikuli.script.Region;
 
15
import org.sikuli.script.Screen;
 
16
import org.sikuli.script.Settings;
 
17
 
 
18
 
 
19
public class SikuliGuideTest {
 
20
   @Test
 
21
   public void testFirefox() throws FindFailed {
 
22
 
 
23
      App a = new App("Firefox");
 
24
 
 
25
      // a.focus();
 
26
      Debug.log("t");
 
27
      //
 
28
      //      a.focus();
 
29
      //      Debug.log("t");
 
30
      //
 
31
      //      Region s = a.window(0);
 
32
 
 
33
      Screen s = new Screen();
 
34
 
 
35
      Debug.log("s=" + s);
 
36
      //      s.getCenter();
 
37
      //      s.setFindFailedResponse(FindFailedResponse.PROMPT);
 
38
      //
 
39
      //
 
40
      //      Settings.ShowActions = true;
 
41
 
 
42
      Region r = null;
 
43
 
 
44
      //      s.click("tools.png",0);
 
45
 
 
46
      SikuliGuide sa = new SikuliGuide();
 
47
 
 
48
      r = s.find("tools.png");
 
49
      //sa.addHighlight(r);
 
50
      sa.addCircle(r);
 
51
      sa.showNow();
 
52
      // sa.showWaitForButtonClick("Continue", "Tools");
 
53
 
 
54
   }
 
55
 
 
56
   @Test
 
57
   public void testICDLSimpleSearch() throws FindFailed{
 
58
      App a = new App("Firefox");
 
59
      //a.focus();
 
60
 
 
61
      Screen s = new Screen();
 
62
      Region r;
 
63
      SikuliGuide sa = new SikuliGuide();
 
64
 
 
65
      Location o = s.getTopLeft();
 
66
      o.translate(10,10);
 
67
      sa.addText(o,"1. All the different categories we see in the " +
 
68
            "Simple Search are like the shelves in a regular library. Today, " +
 
69
            "we are looking for Fairy Tales, so, we are going to look for " +
 
70
      "them by clicking on the Fairy Tales button!");
 
71
 
 
72
 
 
73
      r = s.find(new Pattern("fairy.png").similar(0.95f));
 
74
      sa.addClickTarget(r,"");
 
75
      sa.addCircle(r);
 
76
      sa.showNow();
 
77
 
 
78
 
 
79
      sa.addText(o,"2. If we want to refine our search further, we can select other categories as well. " +
 
80
            "If we only want Fairy Tales that are for ages three to five, we can select " +
 
81
            "the Three to Five button as well. To remove a category from the search," +
 
82
      " click it again to unselect it.");
 
83
      r = s.find(new Pattern("three2five.png").similar(0.95f));
 
84
      sa.addClickTarget(r,"");
 
85
      sa.addCircle(r);
 
86
      sa.showNow();
 
87
 
 
88
      Robot robot=null;
 
89
      try {
 
90
         robot = new Robot();
 
91
      } catch (AWTException e) {
 
92
         e.printStackTrace();
 
93
      }
 
94
      robot.delay(2000);
 
95
 
 
96
      sa.addDialog("Next","3. Now we can see all the Fairy Tale books for age Three to Five in the library. " +
 
97
            "We can use the arrows in the results section to page through " +
 
98
      "all the different books. ");
 
99
      r = s.find(new Pattern("right.png").similar(0.95f));
 
100
      sa.addCircle(r);
 
101
      r = s.find(new Pattern("left.png").similar(0.95f));
 
102
      sa.addCircle(r);
 
103
      sa.showNow();
 
104
 
 
105
 
 
106
      sa.addDialog("Finish", "4. To start over with and do a new search, " +
 
107
            "we can click the Trash Can button. To learn how to read a book" +
 
108
      " go to the reading books section.");
 
109
      r = s.find(new Pattern("trashcan.png").similar(0.95f));
 
110
      sa.addCircle(r);
 
111
      sa.showNow();
 
112
   }
 
113
 
 
114
   @Test
 
115
   public void testMute() throws FindFailed{
 
116
      //App a = new App("System Preferences");
 
117
      //a.focus();
 
118
 
 
119
      Region s = new Screen(0);
 
120
 
 
121
      Debug.log("s=" + s);
 
122
      s.getCenter();
 
123
 
 
124
      s.setFindFailedResponse(FindFailedResponse.PROMPT);
 
125
 
 
126
 
 
127
      Region r = null;
 
128
 
 
129
      SikuliGuide sa = new SikuliGuide(s);
 
130
      r = s.find("sound.png");
 
131
      sa.addText(r.getBottomLeft().below(5),"Click this");
 
132
      sa.addRectangle(r);
 
133
      sa.addClickTarget(r, "");
 
134
      //sa.addDialog("Next", "Hello");
 
135
      sa.showNow();
 
136
 
 
137
      sa.addDialog("Next", "Another step");
 
138
      sa.showNow();
 
139
 
 
140
      sa.addDialog("Next", "Yet another step");
 
141
      sa.showNow();
 
142
 
 
143
 
 
144
   }
 
145
   
 
146
   @Test
 
147
   public void testICDL() throws FindFailed{
 
148
 
 
149
      //App a = new App("Firefox");
 
150
      //a.focus();
 
151
      
 
152
      Region r = null;
 
153
      Screen s = new Screen();
 
154
      SikuliGuide sa = new SikuliGuide(s);
 
155
 
 
156
      sa.addDialog("Next","Welcome!");  
 
157
      sa.showNow();
 
158
 
 
159
      r = s.find("tiger.png");
 
160
 
 
161
      Location o = r.getTopLeft().above(100);
 
162
 
 
163
      sa.addText(o,"Click on the Tiger or the Unicorn");
 
164
      sa.addClickTarget(r,"Tiger");
 
165
 
 
166
      sa.addClickTarget(s.find("unicorn.png"),"Unicorn");
 
167
      sa.showNow();
 
168
 
 
169
 
 
170
      sa.addText(o, "You just clicked on the " + sa.getLastClickedTarget().getName());
 
171
      sa.showNow();
 
172
      
 
173
   }
 
174
 
 
175
 
 
176
 
 
177
 
 
178
 
 
179
}
 
180
 
 
181