SDET- QA Automation Techie

Software Testing Blog

  • Home
  • Training
    • Online
    • Self-Paced
  • Video Tutorials
  • Interview Skills
    • HR Interview Questions Videos
    • Domain Knowledge
  • Career Guidance
  • Home
  • Software Testing
    • Manual Testing Tutorials
    • Manual Testing Project
    • Manaul Testing FAQS
    • ISTQB
    • AGILE
  • Web Automation Testing
    • Java Programmng
    • Python Programmng
    • Selenium with Java
    • Selenium with Python
    • Robot Framework(Selenium with Python)
    • selenium with Cucumber
    • TestNG+IntelliJ
    • Mobile App Testing(Appium)
    • JMeter
  • API Automation Testing
    • Rest Assured API Testing (BDD)
    • Rest Assured API Testing (Java+ TestNG)
    • Robot Framework(Rest API Testing with Python)
    • Postman
    • SoapUI
    • API Testing(FAQ's)
  • SDET|DevOps
    • Continuos Integration
    • SDET Essentials
    • AWS For Testers
    • Docker
  • SQL
    • Oracle(SQL)
    • MySQL for Testers
    • NoSQL
  • Unix/Linux
    • UNIX TUTORIALS
    • Linux Shell Scripting
  • ETL Testing
    • ETL Data warehouse Tutorial
    • ETL Concepts Tools and Templates
    • ETL Testing FAQ's
    • ETL Testing Videos
  • Big Data Hadoop
  • Video Tutorials
  • ApachePOI Video Tutorials
  • Downloads
    • E-Books for Professionals
    • Resumes
  • Automation Essencials
    • Cloud Technologies
      • Docker For Testers
      • AWS For Testers
      • Sub Child Category 3
    • Java Collections
    • Selenium Locators
    • Frequently Asked Java Programs
    • Frequently Asked Python Programs
    • Protractor
    • Cypress Web Automation

How To Upload Files Using AutoIT in Selenium

 How To Upload Files Using AutoIT in Selenium   


Selenium can not handle file downloading because browsers use native dialogs for downloading files. Sometime we need to download file from AUT(Application Under Test). There are several ways to automate download file in Selenium but here we see download file using AutoIT in Selenium WebDriver.





AutoIt Introduction:

AutoIt Tool is an open source tool. It 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!
Now the question is how we do download file using AutoIT Tool in Selenium WebDriver.
Steps to integrate autoit with selenium webdriver

1) Write AutoIT script for file uploading( AutoIT Editor)


ControlFocus() --> focus on the text box

ControlSetText() --> providing path of a file
ControlClick() --> clicking on open button

2) Compile AutoIT script and generate .exe file


Tools-->Compile-->Select x64--> Compile --> generated .exe file


3) use and integrate .exe file in selenium webdriver script


Ex: 


Runtime.getRuntime().exec("C://autoitfiles/fileupload.exe"+" "+"C:\\SeleniumPractice\\Fruites\\apple.jpg");
Uploading Single File

AutoIT script

ControlFocus("File Upload","","Edit1")
Sleep(3000)
ControlSetText("File Upload","","Edit1","C:\SeleniumPractice\Fruites\apple.jpg")
Sleep(3000)
ControlClick("File Upload","","Button1")
Sleep(3000)

Note: We need to compile AutoIT script and generate .exe file (SingleFileUpload.exe)


Selenium Test case


import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class UploadSingleFile {


public static void main(String[] args) throws IOException, InterruptedException {


System.setProperty("webdriver.gecko.driver","C://Drivers/geckodriver-v0.19.1-win64/geckodriver.exe");
WebDriver driver=new FirefoxDriver();

driver.get("http://demo.automationtesting.in/Register.html");

WebElement button=driver.findElement(By.xpath("//*[@id='imagesrc']"));

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", button);

Runtime.getRuntime().exec("C://SeleniumPractice/SingleFileUpload.exe"); // execute .exe file

//driver.quit();
}

}


Uploading Multiple Files

AutoIT script

Sleep(500)
ControlFocus("File Upload","","Edit1")
Sleep(500)
ControlSetText("File Upload","","Edit1",$CmdLine[1])
Sleep(500)
ControlClick("File Upload","","Button1")
Sleep(500)

Selenium Test case

import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class UploadMultipleFiles {

public static void main(String[] args) throws IOException, InterruptedException {
System.setProperty("webdriver.gecko.driver","C://Drivers/geckodriver-v0.19.1-win64/geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://demo.automationtesting.in/Register.html");
WebElement button=driver.findElement(By.xpath("//*[@id='imagesrc']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
Thread.sleep(3000);
//round1- first file
executor.executeScript("arguments[0].click();", button);
Runtime.getRuntime().exec("C://SeleniumPractice/MultipleFilesUpload.exe"+" "+ "C:\\SeleniumPractice\\Fruites\\apple.jpg");
Thread.sleep(5000);
//round2-  second file
executor.executeScript("arguments[0].click();", button);
Runtime.getRuntime().exec("C://SeleniumPractice/MultipleFilesUpload.exe"+" "+ "C:\\SeleniumPractice\\Fruites\\Mangoes.jpg");
Thread.sleep(5000);
//round3-  third file file
executor.executeScript("arguments[0].click();", button);
Runtime.getRuntime().exec("C://SeleniumPractice/MultipleFilesUpload.exe"+" "+ "C:\\SeleniumPractice\\Fruites\\PineApple.jpg");
Thread.sleep(5000);
driver.quit();
}

}




  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home
popup

Popular Posts

  • How To Explain Project In Interview Freshers and Experienced
    “ Describe an important project you’ve worked on ” is one of the most common questions you can expect in an interview. The purpose of a...
  • MANUAL TESTING REAL TIME INTERVIEW QUESTIONS & ANSWERS
    1. How will you receive the project requirements? A. The finalized SRS will be placed in a project repository; we will access it fr...
  • API/Webservices Testing using RestAssured (Part 1)
    Rest Assured : Is an API designed for automating REST services/Rest API's Pre-Requisites Java Free videos: https://www.you...

Facebook Page

Pages

  • Home
  • Resumes
  • Job Websites India/UK/US
  • ISTQB
  • Selenium with Java
  • E-Books for Professionals
  • Manual Testing Tutorials
  • Agile Methodology
  • Manual Testing Projects

Live Traffic

YouTube


Blog Visitors

Copyright © SDET- QA Automation Techie | Powered by Blogger
Design by SDET | Blogger Theme by | Distributed By Gooyaabi Templates