01: package watij;
02:
03: import static watij.finders.SymbolFactory.title;
04: import static watij.finders.SymbolFactory.url;
05: import watij.runtime.NoMatchingWindowFoundException;
06: import watij.runtime.ie.IE;
07:
08: public class AttachToExistingWindowTest extends WatijTestCase {
09:
10: IE ie;
11:
12: protected void setUp() throws Exception {
13: ie = new IE();
14: ie.start();
15: ie.goTo(HTML_ROOT + "buttons1.html");
16: }
17:
18: protected void tearDown() throws Exception {
19: ie.close();
20: }
21:
22: public void testExistingWindow() throws Exception {
23:
24: IE ie3 = new IE();
25:
26: try {
27: ie3.attach(title, "missing");
28: fail();
29: } catch (NoMatchingWindowFoundException e) {
30: }
31: try {
32: ie3.attach(title, "/missing/");
33: fail();
34: } catch (NoMatchingWindowFoundException e) {
35: }
36: try {
37: ie3.attach(url, "missing");
38: fail();
39: } catch (NoMatchingWindowFoundException e) {
40: }
41: try {
42: ie3.attach(url, "/missing/");
43: fail();
44: } catch (NoMatchingWindowFoundException e) {
45: }
46:
47: ie3.attach(title, "/(?i:buttons)/");
48: assertEquals("Test page for buttons", ie3.title());
49:
50: ie3.close();
51: ie = new IE();
52: ie.start(HTML_ROOT + "buttons1.html");
53: ie3 = new IE();
54:
55: ie3.attach(title, "Test page for buttons");
56: assertEquals("Test page for buttons", ie3.title());
57:
58: ie3.close();
59: ie = new IE();
60: ie.start(HTML_ROOT + "buttons1.html");
61: ie3 = new IE();
62:
63: ie3.attach(url, "/buttons1.html/");
64: assertEquals("Test page for buttons", ie3.title());
65:
66: // #hard to test url with explicit text
67: }
68:
69: }
|