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

August 26, 2015

Integrate AutoIT with Selenium Webdriver

August 26, 2015 5
In this post we will discuss about how to Integrate AutoIT with Selenium Webdriver.

Need of AutoIT in Webdirver:

Webdriver can only interact with web applications, it can not interact with desktop components or Browser related popups. 
Here are some of the situations where we need to take help of 3rd Party tools (Auto IT).

  1. File Uploads.
  2. Downloads.
  3. Handling User Authentications etc..

We will see below points:
1. What is AutoIT
2. Features of AutoIT
3. How to Install?
4. How to use?
5. Integrate AutoIT and Webdriver

What is AutoIT and Features :

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!


  • Easy to learn BASIC-like syntax
  • Simulate keystrokes and mouse movements
  • Manipulate windows and processes
  • Interact with all standard windows controls
  • Scripts can be compiled into standalone executables
  • Create Graphical User Interfaces (GUIs)
More details you can find here  --AutoIT Features

Install AutoIT:

To install AutoIt first download the AutoIt exe file from the below location.


1. Click on the topmost download for AutoIT
2. Follow the instructions to install AutoIT.


Record AutoIT script:
AutoIT has record feature. We can record script using AutoIT, for that we need AutoIT script Editor.

Download AutoIT Script Editor:
In Auto IT downloads page we have one more file called "Download Editor". Once you click on that it will navigte to downlaods page, then download "SciTE4AutoIt3.exe" file.

How to Use:

Scenario:
1. Navigate to http://www.dropzonejs.com/
2. Click on Try it Out section --It will open window (upload file window)
3. select a file and click open
4. Verify uploaded file in Try it Out section.



First lets see how to create AutoIT script to upload file.

If you want help about commands you can navigate to Start  > All Program > AutoIt v3  > Autoit Help file.  and search for commands.

In the above scenario i need to upload file. After clicking on try it Out it will open a Upload file window.
Need to identify Locators (text box).  AutoIt has given us Windows Info tool, it is same like Object Spy in QTP and Element Inspector in any Browser. To open it go to Start > All Program > AutoIt v3 > AutoIt Window Info.

Now drag the ‘Finder Tool‘ box to the object in which you are interested.


You can see that Windows Info tool has populated all the information which is required to use the method.

Write Automation script to Upload file:





Save that file with extension .au3 and Convert script to .exe file.



After compilation you will get Upload.exe file.

How to use file in Webdriver:


Runtime.getRuntime().exec("D:\downloads\Uplaod.exe");


Below is the code how to use Auto It in Webdirver:








March 3, 2014

Uploading a file using AutoIt

March 03, 2014 8
Uploading a file using AutoIt
As we all know, Selenium will not support window based elements. To upload/download we need to use some third party tools.

Below post explains how to upload a file from local drive using AutoIt.


(This code is to select a file from window after clicking on browse button from web page, After this we have click on upload button from web page)

WinWaitActive("File Upload")
Send("C:\Temp\Test.txt")
Send("{ENTER}")

Write this code in Notepad and save the file as “Upload.au3”
Right Clicked on the created file “Upload.au3” and click on Compile Script.
You will get “Upload.exe” file

Call this file in Selenium script or in RFT script as below:

Process proc = Runtime.getRuntime().exec("C:\\Temp\\ Upload.exe");

Sample Selenium Code using AutoIt upload:

public class Upload {
public WebDriver driver;

@Before
public void setUp() throws Exception {
driver= new FirefoxDriver();
driver.manage().window().maximize();
}
@Test
public void testTestScenario1() throws Exception
{
driver.get("http://www.2shared.com/");
driver.findElement(By.id("upField")).click();
Thread.sleep(5000);
Process proc = Runtime.getRuntime().exec("C:\\Temp\\Upload.exe");
driver.findElement(By.xpath("//input[@title='Upload file']")).click();

}
@After
public void tearDown() throws Exception {
driver.quit();
}
}