1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.unitedinternet.portal.selenium.utils.logging.integrationtest;
18
19 import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals;
20 import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue;
21
22 import java.io.BufferedWriter;
23 import java.io.File;
24 import java.io.IOException;
25 import java.text.ParseException;
26
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 import com.thoughtworks.selenium.HttpCommandProcessor;
32 import com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter;
33 import com.unitedinternet.portal.selenium.utils.logging.LoggingCommandProcessor;
34 import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium;
35 import com.unitedinternet.portal.selenium.utils.logging.LoggingResultsFormatter;
36 import com.unitedinternet.portal.selenium.utils.logging.LoggingSelenium;
37 import com.unitedinternet.portal.selenium.utils.logging.LoggingUtils;
38
39 public class LoggingSeleniumSuccessSample {
40 protected LoggingSelenium selenium;
41
42 private BufferedWriter loggingWriter;
43
44 private static final String RESULT_FILE_ENCODING = "UTF-8";
45
46 private static final String DEFAULT_TIMEOUT = "30000";
47
48 private static final String OPENQA_URL = "http://openqa.org";
49
50 private static final String SCREENSHOT_PATH = "screenshots";
51
52 private final String RESULTS_BASE_PATH = "target" + File.separator + "loggingResults";
53
54 private String resultsPath = new File(RESULTS_BASE_PATH).getAbsolutePath();
55
56 private String screenshotsResultsPath = new File(RESULTS_BASE_PATH + File.separator + SCREENSHOT_PATH).getAbsolutePath();
57
58 @Before
59 public void setUp() {
60 if (!new File(screenshotsResultsPath).exists()) {
61 new File(screenshotsResultsPath).mkdirs();
62 }
63
64
65
66
67
68
69 final String resultHtmlFileName = resultsPath + File.separator + "sampleResultSuccess.html";
70 System.err.println("resultHtmlFileName=" + resultHtmlFileName);
71
72 loggingWriter = LoggingUtils.createWriter(resultHtmlFileName, LoggingSeleniumSuccessSample.RESULT_FILE_ENCODING, true);
73
74 LoggingResultsFormatter htmlFormatter = new HtmlResultFormatter(loggingWriter,
75 LoggingSeleniumSuccessSample.RESULT_FILE_ENCODING);
76 htmlFormatter.setScreenShotBaseUri(LoggingSeleniumSuccessSample.SCREENSHOT_PATH + "/");
77 htmlFormatter.setAutomaticScreenshotPath(screenshotsResultsPath);
78 LoggingCommandProcessor myProcessor = new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*chrome",
79 OPENQA_URL), htmlFormatter);
80 myProcessor.setExcludedCommands(new String[] {});
81 selenium = new LoggingDefaultSelenium(myProcessor);
82 selenium.start();
83 }
84
85 @After
86 public void tearDown() {
87 selenium.stop();
88 try {
89 if (null != loggingWriter) {
90 loggingWriter.close();
91 }
92 } catch (IOException e) {
93
94 }
95 }
96
97 @Test
98 public void loggingSeleniumSuccessSample() throws InterruptedException, ParseException {
99 selenium.setContext("loggingSeleniumSuccessSample()");
100
101 selenium.open(OPENQA_URL);
102
103 selenium.captureScreenshot(screenshotsResultsPath
104 + File.separator
105 + "openQaHomePage_"
106 + LoggingUtils.timeStampForFileName()
107 + ".png");
108
109
110
111
112
113 assertEquals("Expected page title not found", "OpenQA: Home", selenium.getTitle(), selenium);
114
115 selenium.click("link=Selenium RC");
116 selenium.waitForPageToLoad(DEFAULT_TIMEOUT);
117
118 assertEquals("Expected page title not found", "Selenium RC: About", selenium.getTitle(), selenium);
119 assertTrue("Expected text 'Supported Platforms' not found", selenium.isTextPresent("Supported Platforms"), selenium);
120
121 selenium.click("link=Tutorial");
122 selenium.waitForPageToLoad(DEFAULT_TIMEOUT);
123 assertEquals("Expected page title not found", "Selenium RC: Tutorial", selenium.getTitle(), selenium);
124
125 selenium.captureScreenshot(screenshotsResultsPath
126 + File.separator
127 + "openQaTutorialPage_"
128 + LoggingUtils.timeStampForFileName()
129 + ".png");
130 }
131 }