Showing posts with label AutoIt Scripts. Show all posts
Showing posts with label AutoIt Scripts. Show all posts

Wednesday 27 November 2013

Window (File Upload/Download) in Selenium webdriver


File Upload/Download using Autoit
I would like to explain the Autoit tool on the file upload functionality. Download the tool from http://www.autoitscript.com/site/autoit/downloads/ , create the appropriate Autoit .au3 script, compile into exe file, test the exe file to verify whether the functionality is working as expected and integrate with selenium. Read the help file for better understanding.
Scenario:
I have web button on the page, when selected; browser opens the following window (attaching screen shot below). Selenium works fine till Browse button selection, now it is the responsibility of the Autoit script to upload the file so that selenium can continue with the remaining GUI activity.



Steps:
1. Select the File Upload window. Drag and drop the finder tool icon on the windows objects to get its corresponding properties following screen shot demonstrates how to open and capture the windows controls.











2. Open Script Editor (program files), write the code for ex.



AutoIt Script
WinWaitActive("File Upload")
Send("D:\demo.txt")
ControlClick("", "&Open", "Button1")



3. Save the file as demo.au3
4. Right click on this file and click ‘Compile Script’. This will create a demo.exe file at the same location.
5. Select open button, so that all the selection details are transferred into web page control and selenium can take control of the next activity.

Autoitdemo.java

public class Autoitdemo {
         
          public static void main(String[] args)  {
                   try{            
                  
                   WebDriver driver = new FirefoxDriver();
                   driver.get("http://www.sendspace.com/");
System.out.println(" Page Opened is: "+driver.getCurrentUrl()+"\n"+driver.getTitle() );
                   driver.findElement(By.xpath("//*[@id='upload_file']")).click();
                   System.out.println(" Browse button clicked");
                   Runtime.getRuntime().exec("D:\\demo1.exe"); //call Autoit script
                   System.out.println(" Execution Finished ");
                   driver.close();
                    }catch(Exception e)
                    {       
e.printStackTrace();
                   System.out.println(e.getMessage());    
                  
          }
          }
}

Java Code to call Autoit Script
Runtime.getRuntime().exec("D:\\demo1.exe");

For more help go to:




Friday 22 November 2013

Handling Alert Boxes Using AutoIT in Selenium

Handling alert box using AutoIT

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying “runtimes” required!.

Here we are going to use AutoIT for handling authentication boxes like below,



Step 1: 

Download the latest version of AutoIT from http://www.autoitscript.com/site/autoit/downloads/
 

Step 2: 

Write the code and Save it as 'Authentication.au3' 
(au3 is the AutoIT format)



Use the below code
WinWaitActive("Authentication Required")
Send("Username")
Send("{TAB}")
Send("Password")
Send("{ENTER}")

Step 3:

After that, right click on your Authentication.au3 file and click 'Compile Script'
This will covert your AutoIT script into an executable file

Step 4:

Now go to your Selenium code, and add the below line.

Runtime.getRuntime().exec("C://Path//Authentication.exe");