Revision: 243e8d9d4d18
Branch: default
Author: Pekka Klärck
Date: Wed Sep 12 15:51:18 2012
Log: Screenshot: Support for taking screenshots with IronPython
Update issue 1225
Labels: ackn
Thanks for the patch Martti! I applied it with minor formatting changes.
I leave this issue still open because I want to test this manually but don't
have IronPython available. Will start CI run so we'll see do screenshot
tests
pass there.
http://code.google.com/p/robotframework/source/detail?r=243e8d9d4d18
Modified:
/src/robot/libraries/Screenshot.py
=======================================
--- /src/robot/libraries/Screenshot.py Wed Sep 12 07:08:08 2012
+++ /src/robot/libraries/Screenshot.py Wed Sep 12 15:51:18 2012
@@ -19,7 +19,11 @@
from javax.imageio import ImageIO
from java.io import File
elif sys.platform == 'cli':
- pass # IronPython imports here
+ import clr
+ clr.AddReference('System.Windows.Forms')
+ clr.AddReference('System.Drawing')
+ from System.Drawing import Bitmap, Graphics, Imaging
+ from System.Windows.Forms import Screen
else:
try:
import wx
@@ -288,7 +292,12 @@
ImageIO.write(image, 'jpg', File(path))
def _cli_screenshot(self, path):
- raise NotImplementedError
+ bmp = Bitmap(Screen.PrimaryScreen.Bounds.Width,
+ Screen.PrimaryScreen.Bounds.Height)
+ g = Graphics.FromImage(bmp)
+ g.CopyFromScreen(0, 0, 0, 0, bmp.Size)
+ g.Dispose()
+ bmp.Save(path, Imaging.ImageFormat.Jpeg)
def _wx_screenshot(self, path):
context = wx.ScreenDC()