Watir-webdriver screenshot save to Excel feature

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.