Pages

AutoIt Tool Usage


                                 AutoIt


Ø  Mouse Over on AUTOIT menu


Ø  Click on Downloads menu option

Ø  Click on Download AutoIt button


Ø  Mouse Over on AUTOIT EDITOR Menu

Ø  Click on Editor Downloads option
Ø  Click on Below Exe file

After downloading the AutoIt and AutoIt Editor
Click on each setup files & Complete the installation

Click on Next button

Keep the default installation location & Click on Install button


Click on Second SciTEAutoIt exe file and complete the installation process

GO to Help Section & Click on Index


We are going to use three commands
1)ControlFocus():


2)ControlSetText():

3)ControlClick():


Launch the AutoIt Editor & Identifier Tool From c:/program files (x.86)/AutoIt


Launch by clicking on AutoItInfo to open Identifier Tool

GO to C:/program files x 86/AutoIt/SciTE àClick on SciTE àEditor will lanuch


SCITE editor will launch



Click on Upload/browse icons in your application àThen window will open



Identify the File name field with Finder Toolàit will give title, class and instance values of the file name editbox





Identify the Open button


Script is ready now


Save the above file  --Go to File MenuàSave As


Save in one Folder AutoIt in Desired location


Right Click on FileàCompile the Script


After Compilation we will get one more application file


Write the selenium code and give the autoit script path using RunTime class getRuntime().exec(“path of the AutoItScript”)

 RunTime.getRunTime().exe("C:\\AutoItScript\\FileUploadFirefox.exe");

if you want to run on chrome generate new AutoItScript and compile then give that exe file path
 Runtime.getRuntime().exec("C:\\AutoItScript\\FileUploadchrome.exe");

-----------------------------------------------------------------------------------------------------------------
Step1)
AutoItScript for Chrome
copy and past below code in notepad
save filename:: AutoitScriptForChrome.au3
Select Save As option: All Types
----------------------------------------------------------------------------------------------------------------
WinWait("Open","",1000);
ControlFocus("Open","","Edit1");
ControlSetText("Open","","Edit1","C:\Users\rames\Downloads\Ramesh-stateID.pdf");
WinWait("Open","",1000);
ControlClick("Open","","Button1");

-----------------------------------------------------------------------------------------------------------------------
AutoItScript for Firefox
Copy and paste the below code in notepad
and save the filename:: AutoitScriptForFirefox.au3
Select Save As an option: All Types
------------------------------------------------------------------------------------------------------
WinWait("File Upload","",1000);
ControlFocus("File Upload","","Edit1");
ControlSetText("File Upload","","Edit1","C:\Users\rames\Downloads\Ramesh-stateID.pdf");
WinWait("File Upload","",1000);
ControlClick("File Upload","","Button1");
-------------------------------------------------------------------------------------------------------------
Step2:
Convert the filename.au3 as a .exe file 
right click on the filename.au3 -->select compile Script(x64)-->this will generate the AutoitScriptForFirefox.exe/AutoitScriptForChrome.exe
===================================================================
Step3: write an Automation script for uploading files

AutoIt Upload Files Programs:
package testngprograms;

package testngprograms;

import org.testng.annotations.Test;

import basicprograms.WebDriverUtils;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;

import java.io.IOException;
import java.time.Duration;
import java.util.LinkedList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.Reporter;


public class FileUploadUsingAutoIt {
WebDriver driver = null;
WebDriverWait wait = null;
WebDriverUtils wutils = null;
//String fpath = "C:\\Users\\rames\\Downloads\\How to access Workday.pdf";
@Parameters({ "browser" })
@Test
public void fileUploadByAutoItTest(String browser) throws InterruptedException, IOException {
Reporter.log("open the url:https://easyupload.io/", true);
driver.get("https://easyupload.io/");
Reporter.log("verify the page title Easyupload.io - Upload files for free and transfer big files easily.", true);
wait.until(ExpectedConditions.titleContains("Easyupload.io - Upload files for free and transfer big files easily."));
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("body > main > div > div.upload > h1")));
String headerTxt = driver.findElement(By.cssSelector("body > main > div > div.upload > h1")).getText();
Assert.assertEquals("Upload and share files for free", headerTxt);
Reporter.log("click on cclick here or drop files to upload button", true);
driver.findElement(By.xpath("//*[@id='dropzone']/div[2]/button")).click();
Reporter.log("call the robotclass method to handle uplaod file", true);
//
if(browser.equalsIgnoreCase("chrome")) {
Runtime.getRuntime().exec("C:\\Users\\rames\\OneDrive\\Documents\\AutoitScript\\AutoItScriptForChrome.exe");
}else if(browser.equalsIgnoreCase("firefox")) {
Runtime.getRuntime().exec("C:\\Users\\rames\\OneDrive\\Documents\\AutoitScript\\AutoItScriptForFirefox.exe");
}
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("upload")));
Thread.sleep(1000);
Reporter.log("click on Upload button", true);
driver.findElement(By.id("upload")).click();
Reporter.log("File uploaded message assertions", true);
wait.until(ExpectedConditions.presenceOfElementLocated(By.className("upload-success")));
Assert.assertTrue(driver.findElement(By.xpath("//div[@class='upload-success']/h5")).isDisplayed(), "file is not uploaded");
Assert.assertEquals("Your file has been uploaded successfully.",driver.findElement(By.xpath("//div[@class='upload-success']/h5")).getText());
Thread.sleep(2000);
}
@Parameters({ "browser" })
@BeforeClass(alwaysRun = true)
public void beforeClass(String browser) {
if (browser.equalsIgnoreCase("chrome")) {
ChromeOptions opt = new ChromeOptions();
opt.setAcceptInsecureCerts(true);
driver = new ChromeDriver(opt);
Reporter.log("chromebrowser is launched", true);
} else if (browser.equalsIgnoreCase("firefox")) {

FirefoxOptions opt = new FirefoxOptions();
opt.setAcceptInsecureCerts(true);
// opt.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
// interface refvar=new implementedclass();
driver = new FirefoxDriver(opt);
Reporter.log("firefox browser is launched", true);
} else if (browser.equalsIgnoreCase("edge")) {
EdgeOptions opt = new EdgeOptions();
opt.setAcceptInsecureCerts(true);
driver = new EdgeDriver(opt);
Reporter.log("edge browser is launched", true);
}
Reporter.log("maximize the window", true);
driver.manage().window().maximize();
Reporter.log("add implicitwait", true);
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(10000));
Reporter.log("add explicitwait object", true);
wait = new WebDriverWait(driver, Duration.ofSeconds(30));
Reporter.log("creating Object for WebDriverUtils class", true);
wutils = new WebDriverUtils(driver);
}

@AfterClass
public void afterClass() {
System.out.println("I am in AfterClass block");
// close the browser
driver.close();
}

}
--------------------------------------------------------------------
ActionsTestNG.xml file format
---------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="ActionsSuite">
  <test thread-count="5" name="ActionsTest">
  <parameter name="browser" value="firefox"></parameter>
    <classes>
      <!-- class name="testngprograms.DragAndDropTest"/ -->
      <!-- class name="testngprograms.DragAndDropByTest"></class -->
      <!-- class name="testngprograms.FlipKartMenuHandlingTest"></class -->
      <!-- class name="testngprograms.ActionsMethodsDemo"></class -->
      <!-- class name="testngprograms.OpenLinkNewTabAndNewWindowTest"></class -->
      <!-- class name="testngprograms.HandlingWebTableTest"></class -->
      <!-- class name="testngprograms.JqueryDatePickerTest"></class -->
      <!-- class name="testngprograms.FileUploadUsingRobot"></class -->
      <class name="testngprograms.FileUploadUsingAutoIt"></class>
    </classes>
  </test> <!-- ActionsTest -->
</suite> <!-- ActionsSuite -->
-----------------------------------------------------




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.