1 package com.atlassian.selenium;
2
3 import junit.framework.TestCase;
4
5 import java.io.InputStream;
6 import java.io.BufferedReader;
7 import java.io.InputStreamReader;
8 import java.io.IOException;
9
10
11
12
13
14
15 public abstract class SeleniumTest extends TestCase
16 {
17 protected SeleniumAssertions assertThat;
18 protected SeleniumClient client;
19 protected SeleniumConfiguration config;
20
21 public abstract SeleniumConfiguration getSeleniumConfiguration();
22
23
24
25
26
27
28 public final void setUp() throws Exception
29 {
30 super.setUp();
31 config = getSeleniumConfiguration();
32
33 if (SeleniumStarter.getInstance().isManual())
34 {
35 SeleniumStarter.getInstance().start(config);
36 }
37
38 client = getSeleniumClient();
39
40 assertThat = new SeleniumAssertions(client, config);
41
42 String js = "var win = this.browserbot.getCurrentWindow();\n" +
43 "(function() { " +
44 " if (win.opera) { return 'opera'; } \n" +
45 " if (document.all) { return 'ie'; } \n" +
46 " if (win.navigator.userAgent.indexOf('Firefox') != -1) { return 'firefox'; } \n" +
47 " if (win.navigator.vendor.indexOf('Apple') != -1) { return 'safari'; } \n" +
48 " return 'unknown' \n" +
49 "})()";
50
51 SeleniumStarter.getInstance().setUserAgent(client.getEval(js));
52
53 onSetUp();
54 }
55
56
57
58
59
60
61 protected SeleniumClient getSeleniumClient()
62 {
63 return SeleniumStarter.getInstance().getSeleniumClient(getSeleniumConfiguration());
64 }
65
66
67
68
69 protected void onSetUp() throws Exception
70 {
71 }
72
73
74
75
76
77 public final void tearDown() throws Exception
78 {
79 super.tearDown();
80 onTearDown();
81 if (SeleniumStarter.getInstance().isManual())
82 {
83 SeleniumStarter.getInstance().stop();
84 }
85 }
86
87
88
89
90 protected void onTearDown() throws Exception
91 {
92 }
93 }