module Win32 |
module Win32Screenshot |
USER32 = DL.dlopen("user32") EnumWindows = USER32['EnumWindows', 'IPL'] GetWindowTextLength = USER32['GetWindowTextLengthA' ,'LI' ] GetWindowText = USER32['GetWindowTextA', 'iLsL' ] |
ShowWindow= USER32['ShowWindow', 'LIL' ] BringWindowToTop=USER32['BringWindowToTop','LI'] |
SRCCOPY = 0xCC0020 GMEM_FIXED = 0 DIB_RGB_COLORS = 0 |
SW_SHOWMAXIMIZED = 3 |
def capture_hwnd(hwnd) hScreenDC = getDC(hwnd) |
ShowWindow.call(hwnd,SW_SHOWMAXIMIZED) setForegroundWindow(hwnd) BringWindowToTop.call(hwnd) |
require 'win32screenshot' require 'rubygems' require 'RMagick' |
def captureGif(file) width, height, bmp =Win32Screenshot::Screenshot.capture_hwnd(@ie.hwnd) img = Magick::Image.from_blob(bmp) png = img[0].to_blob do self.format = 'gif' end File.open(file, "wb") {|io| io.write(png)} unless file.nil? end |
require 'watir' # the watir controller # open the IE browser ie = Watir::IE.new ie.maximize # Step 1: go to the test site: http://www.google.com ie.goto("http://www.google.com") ie.captureGif('c:/google1.gif') # Step 2: enter 'pickaxe' in the search text field ie.text_field(:name, "q").set("什么") # q is the name of the search field ie.captureGif('c:/google2.gif') # Step 3: click the 'Google Search' button ie.button(:name, "btnG").click # "btnG" is the name of the Search button ie.captureGif('c:/google3.gif') # Actual Result: Check that the 'Programming Ruby' link appears on the results page if ie.contains_text("什么是-什么是什么,搜搜就知道!") puts "Test Passed. Found the test string: '什么是-什么是什么,搜搜就知道!'. Actual Results match Expected Results." else puts "Test Failed! Could not find: '什么是-什么是什么,搜搜就知道!'" end # End of test: Google search |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |