Showing posts with label selenium-AutoIT. Show all posts
Showing posts with label selenium-AutoIT. Show all posts

Thursday, January 13, 2011

AutoIT Script Generator-AU3Recorder

To write autoit scipt,we need not learn the autoit scripting language.Instead ,we can download SciTE4AutoIt3from http://www.autoitscript.com/autoit3/scite/downloads.shtml and install.Of course you need to have downloaded AutoIt from http://www.autoitscript.com/autoit3/downloads.shtml  and installed, before installing SciTE.
  
What can AU3Record do for you:
  1. It will record Mouseclicks and Keyboardstrokes for you and translate those into AutoIt3 commands.
  2. There is a AU3Record included which will store the recorded information into the currently edit file.

    After installing ,goto start->programs->autoitv3->Scite Script Editor.

    A window opens->go to tools and select AU3Recorder.
        Also you can Start AU3Record by  hitting Alt+F6:

Optionally Select the program you want to run before starting to recording and click on REC.
Now do all pointing, clicking and typing and when finished click on
Something like this will be inserted into you active script:



 Save the file by clicking save as-> new.au3 . and then double click on saved file to execute the recorded action.

Solution to possible problem: When you click new file,it doesn't show au3recorder under tools until you save the file as autoITscript

Monday, November 29, 2010

How to upload a file in selenium

How to upload a file in selenium with the help of AutoIT

Recently, I had the challenge of writing some automation for a workflow which included uploading a file because uloading a file works on windows component.
selenium is unable to access windows components and it will be handled through AutoIT.
Once you are able to click on browse button and a dialog box is open to choose the file then you just run a AutoIT script which will help to select the file from your local or remote drive and control will come to your web page to proceed with selenium.

Step to choose a file from your local or remote drive

Step 1.

Download the AutoIT and intall it.

Download AutoIT from its homepage

step 2.

write a AutoIT script to choose a file from your local or remote drive.


#include
; Internet Explorer is partly integrated in shell.application
$oShell = ObjCreate("shell.application") ; Get the Windows Shell Object
$oShellWindows=$oShell.windows ; Get the collection of open shell Windows
$MyIExplorer=""
for $Window in $oShellWindows ; Count all existing shell windows
; Note: Internet Explorer appends a slash to the URL in it's window name
if StringInStr($Window.LocationURL,"http://") then
$MyIExplorer=$Window
exitloop
endif
next
$oForm = _IEGetObjByName ($MyIExplorer, "UploadedFile")
_IEAction($oForm, "click")
WinActivate("Choose file");
Local $file = "C:\Documents and Settings\intelizen\Desktop\selenium.txt"
ControlSetText("Choose file", "", "Edit1", $file )
ControlClick("Choose file", "", "Button2")

setp 3.

Complie AutoIT script and make exe of that script.

Right click on that saved script file and click on "Compile script" from context menu. This will make an exe file of that script.


setp 4.

Call that exe in selenium.

Process proc = Runtime.getRuntime().exec("C:\\farheen\\FileUpload.exe");

If you want to test this script then just download the script exe file and click on browse button on web page and run this exe file. Just make sure you have your file in correct path by changing this line of script in the second step
Local $file = "c:\yourpath\howtoupload.doc"
in above line of script change your file path then make exe of your script then click on browse button on your web page then run this exe . I am sure this would work.

Above script work for Firefox.Below for IE.

#include
; Internet Explorer is partly integrated in shell.application
$oShell = ObjCreate("shell.application") ; Get the Windows Shell Object
$oShellWindows=$oShell.windows ; Get the collection of open shell Windows
$MyIExplorer=""
for $Window in $oShellWindows ; Count all existing shell windows
; Note: Internet Explorer appends a slash to the URL in it's window name
if StringInStr($Window.LocationURL,"http://") then
$MyIExplorer=$Window
exitloop
endif
next
$oForm = _IEGetObjByName ($MyIExplorer, "UploadedFile")
_IEAction($oForm, "click")

WinActivate("File Upload");
Local $file = "c:\yourpath\howtoupload.doc"
ControlSetText("File Upload", "", "Edit1", $file )
ControlClick("File Upload", "", "Button2")

In above script you might need to change your file path and browse button name and the title of you dialog box.