Skip to content

Instantly share code, notes, and snippets.

@lyhcode
Created December 30, 2012 14:35
Show Gist options
  • Save lyhcode/4413064 to your computer and use it in GitHub Desktop.
Save lyhcode/4413064 to your computer and use it in GitHub Desktop.
Groovy + Selenium for Web ScreenShot Capturing
@Grapes([
@Grab('org.seleniumhq.selenium.client-drivers:selenium-java-client-driver:1.0.2'),
@Grab('org.seleniumhq.selenium:selenium-server:2.25.0'),
@GrabConfig(systemClassLoader=false, initContextClassLoader=true)
])
import com.thoughtworks.selenium.*
import org.openqa.selenium.server.*
seleniumServer = new SeleniumServer()
seleniumServer.start()
selenium = new DefaultSelenium('localhost', 4444, '*firefox', "http://blog.lyhdev.com/")
selenium.start()
selenium.windowMaximize()
//selenium.getEval("window.resizeTo(X, Y);window.moveTo(0,0);")
try {
selenium.open "http://blog.lyhdev.com/p/by-lyhcode.html"
selenium.waitForPageToLoad '15000'
//selenium.captureScreenshot('/Users/lyhcode/test/screenshot.png')
selenium.captureEntirePageScreenshot '/Users/lyhcode/test/screenshot.png', 'background=#fff'
}
catch(e) {
println e.message
}
selenium.stop()
seleniumServer.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment