Tuesday, August 30, 2011

Failed to create WIN32OLE object from AutoItX3.Control


This is a  problem of registering the dll file, and hence it create an object of AutoIt. To register the autoit dll from command prompt, use following command


1.regsvr32 C:\ruby192\lib\ruby\gems\1.9.1\gems\watir-1.8.1\lib\watir\AutoItX3.dll


Although it does call the register code before creating an object, the 
error was in creating an autoit object.


2.You can also try adding line to top of the file


require 'win32ole'


Some more drag drop methods

With reference to my earlier posts on drag and drop, here are few more methods. You will need to have WindowsInput module,posted in earlier posts, along with below.

def drag_drop_on(target, src_offset=0, dst_offset=0)

     assert_target target
     drop_x = target.left_edge_absolute + dst_offset
     drop_y = target.top_edge_absolute + dst_offset
      drag_to(drop_x, drop_y, src_offset)
end

def drag_drop(target, src_offset=1, dst_offset=1)
            drag_x = left_edge_absolute + src_offset
    drag_y = top_edge_absolute + src_offset
           drop_x = target.left_edge_absolute + dst_offset
           drop_y = target.top_edge_absolute + dst_offset
           WindowsInput.move_mouse(drag_x, drag_y)
           WindowsInput.left_down
           WindowsInput.move_mouse(drop_x, drop_y)
          WindowsInput.left_up
end

def drag_drop_distance(distance_x, distance_y, src_offset=0, dst_offset=0)
   drag_x, drag_y = source_x_y(src_offset)
   drop_x = drag_x + distance_x + dst_offset
   drop_y = drag_y + distance_y + dst_offset
   drag_to(drop_x, drop_y, src_offset)
end

def drag_drop_at(drop_x, drop_y, src_offset=0)
   drag_to(drop_x, drop_y, src_offset)
end

def drag_drop_below(target, src_offset=0, dst_offset=0)
   assert_target target
   drop_x = target.left_edge_absolute + dst_offset
   drop_y = target.bottom_edge_absolute + 2 + dst_offset
   drag_to(drop_x, drop_y, src_offset)
end

def drag_drop_above(target, src_offset=0, dst_offset=0)
   assert_target target
   drop_x = target.left_edge_absolute + dst_offset
   drop_y = target.top_edge_absolute - 2 + dst_offset
   drag_to(drop_x, drop_y, src_offset)
end

def drag_to(drop_x, drop_y, src_offset)
   drag_x, drag_y = source_x_y(src_offset)
   WindowsInput.move_mouse(drag_x, drag_y)
   WindowsInput.left_down
   WindowsInput.move_mouse(drop_x, drop_y)
   WindowsInput.left_up
end

Thursday, August 25, 2011

Working with PDF files


In our project, we needed to read check the contents of a 'PDF report'  that comes embedded in a 'IE' window.The process is a little complicated and not so straightforward.


First you will need to download pdftk. Download these files and extract the files only in the C:\windows\system32 folder. http://www.accesspdf.com/article.php/20041130153545577 


Secondly you will need to download and isntall xpdf : http://pdf-toolkit.rubyforge.org/ . Extract those files into the C:\windows\system32 folder.Then you will need the PDF::TOOLKIT gem. This can be found here http://rubyforge.org/projects/pdf-toolkit/ 


Basically this will convert the pdf to a textfile and you can do what 
you like with it. In the following example I have just read a file on
my c:\ and displayed it using the 'puts' command.



require 'rubygems'
require 'pdf/toolkit' 

my_pdf = PDF::Toolkit.open("c:\\file.pdf")
text = my_pdf.to_text.read
puts text



I hope this helps