how can i do logging and screenshot each iteration the test is executed? with current code below, result html file only show 1 entry thx!
=== AllTests.java === import java.lang.Thread; import java.util.regex.Pattern; import com.thoughtworks.selenium.*; import junit.framework.Test; import junit.framework.TestSuite; import junit.textui.TestRunner;
public class AllTests extends TestSuite {
public AllTests(String name) { super(name);
} public static void main(String[] argv) { int number = 0; int x = 0; int y = 0; int z = 0;
if (argv.length == 0) { System.err.println("usage: AllTests <start number> <end number> <pause time>"); System.exit(1); } else if (argv.length == 3) {
for (int i = 0; i < argv.length; i++) { try { number = Integer.parseInt(argv[i]); x = Integer.parseInt(argv[0]); y = Integer.parseInt(argv[1]); z = Integer.parseInt(argv[2]); } catch(NumberFormatException e) { System.err.println("Number " + argv[i] + " invalid (" + e.getMessage() + ")."); System.exit(1); } System.out.println("OK, number is " + number); } } else { System.err.println("usage: AllTests <start number> <end number> <pause time>"); System.exit(1); } while (x <= y) { System.out.print("Test number: "); System.out.print(x); TestRunner.run(suite());
try { System.out.println("Pausing for: " + z "); Thread.sleep (z); } catch ( InterruptedException e ) { } x = x + 1; }
}
public static Test suite() { TestSuite suite = new AllTests("Testing..."); suite.addTestSuite(mytest1.class); return suite;
=== mytest1.java ===
import com.thoughtworks.selenium.*;
import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.text.ParseException;
import org.junit.After; import org.junit.Before; import org.junit.Test;
import com.thoughtworks.selenium.HttpCommandProcessor; import com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter; import com.unitedinternet.portal.selenium.utils.logging.LoggingCommandProcessor; import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium; import com.unitedinternet.portal.selenium.utils.logging.LoggingResultsFormatter; import com.unitedinternet.portal.selenium.utils.logging.LoggingSelenium; import com.unitedinternet.portal.selenium.utils.logging.LoggingUtils;
public class mytest1 extends SeleneseTestCase { protected LoggingSelenium selenium; private BufferedWriter loggingWriter; private static final String RESULT_FILE_ENCODING = "UTF-8"; private static final String DEFAULT_TIMEOUT = "30000"; private static final String TEST_URL = "http://www.google.com"; private static final String SCREENSHOT_PATH = "screenshots"; private final String RESULTS_BASE_PATH = "target" + File.separator + "loggingResults"; private String resultsPath = new File(RESULTS_BASE_PATH).getAbsolutePath(); private String screenshotsResultsPath = new File(RESULTS_BASE_PATH + File.separator + SCREENSHOT_PATH).getAbsolutePath();
@Before public void setUp() throws Exception { if (!new File(screenshotsResultsPath).exists()) { new File(screenshotsResultsPath).mkdirs(); }
final String resultHtmlFileName = resultsPath + File.separator + "ResultSuccess.html"; System.err.println("resultHtmlFileName=" + resultHtmlFileName);
loggingWriter = LoggingUtils.createWriter(resultHtmlFileName, mytest1.RESULT_FILE_ENCODING, true);
LoggingResultsFormatter htmlFormatter = new HtmlResultFormatter(loggingWriter, mytest1.RESULT_FILE_ENCODING); htmlFormatter.setScreenShotBaseUri(mytest1.SCREENSHOT_PATH + "/"); htmlFormatter.setAutomaticScreenshotPath(screenshotsResultsPath); LoggingCommandProcessor myProcessor = new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", TEST_URL), htmlFormatter); myProcessor.setExcludedCommands(new String[] {}); selenium = new LoggingDefaultSelenium(myProcessor); selenium.start(); }
@After public void tearDown() { selenium.stop(); try { if (null != loggingWriter) { loggingWriter.close(); } } catch (IOException e) { // do nothing //e.printStackTrace(); } }
@Test public void testNew() throws Exception { int i = 2000; int j = 2000; String k = "300000"; selenium.open("/www.google.com/"); selenium.waitForPageToLoad(k);
selenium.captureScreenshot(screenshotsResultsPath + File.separator + "g.home_" + LoggingUtils.timeStampForFileName() + ".png"); }
Log in to post a comment.
how can i do logging and screenshot each iteration the test is executed?
with current code below, result html file only show 1 entry
thx!
=== AllTests.java ===
import java.lang.Thread;
import java.util.regex.Pattern;
import com.thoughtworks.selenium.*;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
public class AllTests extends TestSuite {
public AllTests(String name) {
super(name);
}
public static void main(String[] argv) {
int number = 0;
int x = 0;
int y = 0;
int z = 0;
if (argv.length == 0) {
System.err.println("usage: AllTests <start number> <end number> <pause time>");
System.exit(1);
} else if (argv.length == 3) {
for (int i = 0; i < argv.length; i++) {
try {
number = Integer.parseInt(argv[i]);
x = Integer.parseInt(argv[0]);
y = Integer.parseInt(argv[1]);
z = Integer.parseInt(argv[2]);
} catch(NumberFormatException e) {
System.err.println("Number " + argv[i] + " invalid (" + e.getMessage() + ").");
System.exit(1);
}
System.out.println("OK, number is " + number);
}
} else {
System.err.println("usage: AllTests <start number> <end number> <pause time>");
System.exit(1);
}
while (x <= y) {
System.out.print("Test number: ");
System.out.print(x);
TestRunner.run(suite());
try {
System.out.println("Pausing for: " + z ");
Thread.sleep (z);
}
catch ( InterruptedException e ) {
}
x = x + 1;
}
}
public static Test suite() {
TestSuite suite = new AllTests("Testing...");
suite.addTestSuite(mytest1.class);
return suite;
}
}
=== mytest1.java ===
import com.thoughtworks.selenium.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.HttpCommandProcessor;
import com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter;
import com.unitedinternet.portal.selenium.utils.logging.LoggingCommandProcessor;
import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium;
import com.unitedinternet.portal.selenium.utils.logging.LoggingResultsFormatter;
import com.unitedinternet.portal.selenium.utils.logging.LoggingSelenium;
import com.unitedinternet.portal.selenium.utils.logging.LoggingUtils;
public class mytest1 extends SeleneseTestCase {
protected LoggingSelenium selenium;
private BufferedWriter loggingWriter;
private static final String RESULT_FILE_ENCODING = "UTF-8";
private static final String DEFAULT_TIMEOUT = "30000";
private static final String TEST_URL = "http://www.google.com";
private static final String SCREENSHOT_PATH = "screenshots";
private final String RESULTS_BASE_PATH = "target" + File.separator + "loggingResults";
private String resultsPath = new File(RESULTS_BASE_PATH).getAbsolutePath();
private String screenshotsResultsPath = new File(RESULTS_BASE_PATH + File.separator + SCREENSHOT_PATH).getAbsolutePath();
@Before
public void setUp() throws Exception {
if (!new File(screenshotsResultsPath).exists()) {
new File(screenshotsResultsPath).mkdirs();
}
final String resultHtmlFileName = resultsPath + File.separator + "ResultSuccess.html";
System.err.println("resultHtmlFileName=" + resultHtmlFileName);
loggingWriter = LoggingUtils.createWriter(resultHtmlFileName, mytest1.RESULT_FILE_ENCODING, true);
LoggingResultsFormatter htmlFormatter = new HtmlResultFormatter(loggingWriter, mytest1.RESULT_FILE_ENCODING);
htmlFormatter.setScreenShotBaseUri(mytest1.SCREENSHOT_PATH + "/");
htmlFormatter.setAutomaticScreenshotPath(screenshotsResultsPath);
LoggingCommandProcessor myProcessor = new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox", TEST_URL), htmlFormatter);
myProcessor.setExcludedCommands(new String[] {});
selenium = new LoggingDefaultSelenium(myProcessor);
selenium.start();
}
@After
public void tearDown() {
selenium.stop();
try {
if (null != loggingWriter) {
loggingWriter.close();
}
} catch (IOException e) {
// do nothing
//e.printStackTrace();
}
}
@Test
public void testNew() throws Exception {
int i = 2000;
int j = 2000;
String k = "300000";
selenium.open("/www.google.com/");
selenium.waitForPageToLoad(k);
selenium.captureScreenshot(screenshotsResultsPath
+ File.separator
+ "g.home_"
+ LoggingUtils.timeStampForFileName()
+ ".png");
}
}