Wednesday, 7 October 2015

Integrating Autoit and Selenium: Uploading a file using autoit

While automating a web application I faced a challenge. The challenge is integrate autoit and selenium. So I am going to share the problem domain and the coded solution below so that others can find it out helpful

Problem domain: I have a file located in my own machine which I need to upload in one of my web application project

Used tool:
1. Selenium for automating web application
2. Autoit for interacting with windows/ uploading a file from own local machine

Step 1: Autoit code
Write the Autoit code:

ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload","","Edit1","D:\Test\Shp\Vegetation.zip")
ControlClick("File Upload", "", "Button1")

First write this autoit code and then save it using the extension, Example: fileupload.au3

Step 2: Compile script(Convert into .exe format)

Right click on the fileupload.au3 file and hit compile script, If you are using a 32 bit OS then choose x86 option and if you are using a 64 bit os then choose x64 option

Step 3: Integrating with selenium

Write only the following line in your selenium code where you need to upload you file

Runtime.getRuntime().exec("C:\\Users\\example\\Desktop\\fileupload.exe")

(It is the file path of the .exe file)

Then run your selenium code and observe the expected result

This code works fine for me hope you will find this helpfull



Thursday, 1 October 2015

Draw in canvas using selenium web driver and java

Drawing 3 points which will create a polygon


WebElement element = driver.findElement(By.xpath("html/body/div[3]/div[2]/div[2]/div[2]/div/canvas"));

Actions builder = new Actions(driver);
    Action drawAction = builder.moveToElement(element,135,15)  // start point in the canvas
    //signatureWebElement is the element that holds the signature element you have in the DOM
              .click()
              .moveByOffset(200, 60) // second point
              .click()
              .moveByOffset(100, 70) // third point
              .doubleClick()
              .build();
    drawAction.perform();