1.watir-webdriver self-bringing function
Browser.driver.save_screenshot ' Screenshot.png '
This method can be used to capture images of the entire Web page. Powerful, but the downside is that the truncated images are blurry and the resolution is not high. Especially in Excel, the effect is poor.
2.win32 screenshot function
You need to install the gem install Win32screenshot first
When executing:
Require ' win32/screenshot '
#Take a screenshot of the foreground, and writing over previous image if it exists
Win32::screenshot::take.of (: foreground). write! ("C:\\image.png")
Or the following methods:
# Take a screenshot of the windows with the specified title
#Win32:: Screenshot::take.of (: Window, title: "Windows Internet Explorer"). Write ("Image.bmp")
The image resolution captured by this method is higher than the first method. It is recommended that such a method be used.
3. Put it in Excel
@excel = Win32ole::new ("Excel. Application ")
@excel. Visible=false
@WorkBookopen = @excel. Workbooks.Open ("Excel file Path")
@objSheet = @excel. Sheets (1)
@excel. Sheets (1). Select
@objSheet. Range ("A1"). Select
#此方法 add a picture to Excel
#一般只需要更改后四位参数, 0: With the left margin, 0: With the top margin, 570: Picture width, 324: picture height. You can try to combine more.
@objSheet. Shapes.addpicture "C:\\image.png", False, True, 0, 0, 570, 324
@excel. DisplayAlerts = False
@WorkBookopen. Save
@WorkBookopen. Close
This can be put into Excel.
Can be further strengthened on this method, made into functions, to provide automated testing for use.
Execute a case where you want to intercept multiple pictures and put them in the Excel file in order. Perfect tracking of the test execution process.
A little bit here.
Watir-webdriver Save to Excel feature