1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.plugin.selenium;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import net.sf.jameleon.function.FunctionTag;
25 import net.sf.jameleon.util.JameleonUtility;
26
27 import com.thoughtworks.selenium.Selenium;
28
29 public abstract class SeleniumFunctionTag extends FunctionTag{
30
31 protected SeleniumSessionTag sessionTag;
32 protected Selenium session;
33
34 /***
35 * Gets the references of the session and the test results from the parent TestCase
36 * This method gets called once all attributes are set from the macro language. Any required
37 * setup should go here.
38 */
39 public void setupEnvironment() {
40 super.setupEnvironment();
41 Object obj = findAncestorWithClass(SeleniumSessionTag.class);
42 if (obj instanceof SeleniumSessionTag) {
43 sessionTag = (SeleniumSessionTag) obj;
44 } else {
45 throw new ClassCastException("Can only execute an Selenium function tags under the Selenium session tag ( selenium-session )! " +
46 "Please change the session tag surrounding function point " + getClass().getName());
47 }
48 session = sessionTag.getSession();
49 }
50
51 public void store(String fName, int event) throws IOException{
52 File stateFile = null;
53 if ( session != null ) {
54 String html = session.getHtmlSource();
55 String filename = fName+".html";
56 if ( html != null && html.length() > 0 ) {
57 stateFile = new File(filename);
58 JameleonUtility.recordResultsToFile(stateFile, "<html>"+html+"</html>");
59 getFunctionResults().setErrorFile(stateFile);
60 }
61 }
62 }
63
64 }