import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import junit.framework.TestCase;
public class SimpleScreenshotTest extends TestCase {
private Selenium selenium;
public void setUp() throws Exception {
String url = "http://www.google.com";
// browsers:
//selenium = new DefaultSelenium("wintest", 4444, "*iexplore", url);
selenium = new DefaultSelenium("wintest", 4444, "*firefox", url);
selenium.start();
}
protected void tearDown() throws Exception {
selenium.stop();
}
/**
* The normal google test, just with a screenshot twist.
*/
public void testGoogle() throws Throwable {
selenium.open("http://www.google.com/webhp?hl=en");
assertEquals("Google", selenium.getTitle());
/* use maximize window to be able to get as much of the viewport as possible. */
selenium.windowMaximize();
selenium.waitForPageToLoad("5000");
// note: getScreenshot does not validate the inputparameters.
RenderedImage rendImage = selenium.getScreenshot("png");
if (rendImage == null) {
fail("Rendered image null!");
}
File file = new File("/tmp/newimage-.png");
ImageIO.write(rendImage, "png", file);
}
The next thing now will be to look into creating shots of the whole page.
If someone needs help building Selenium with the patch, post to the comments and I'll do a quick writeup of how to compile selenium-rc.
Ingen kommentarer:
Legg inn en kommentar