0

I have the script in AutoIT (to handle upload file window in selenium)

    WinWaitActive("File Upload")
    Send("C:\Users\XXX\Desktop\Folder1\MyFile.xlsx")
    Send("{ENTER}")

Instead of hard-coding pathname, I want to pick-up pathname from a property file.(So that tomorrow we dont to touch AutoIT script to modify pathname).

Is there any way to do so?

Update 1: java code:

Runtime.getRuntime().exec(TestUtility.properties.getProperty("test.all.autoit.testdata"));
Thread.sleep(8000);

AutoIT code:

WinWaitActive("File Upload")
Send($CmdLine[1])
Send("{ENTER}")

Cmd line:

c:>java -jar pathToJar.jar pathToProperties.properties pathToFileUpload.xlsx

Properties file:

test.all.autoit.testdata='C:\\XX\\XX\\XX\\someFolder\\ListUploadScript.exe'
7
  • why you want to handle file uploading using AutoIT instead of Selenium?! Commented Mar 17, 2016 at 5:16
  • @Andersson Since selenium can not handle window pop-up, need to use AutoIT to handle file upload popup. Commented Mar 29, 2016 at 11:02
  • selenium allow to upload file without handling pop-up Commented Mar 29, 2016 at 11:05
  • @Andersson If it is web-based popup. Selenium is not feasible when it comes to window (OS) based pop-up. Commented Mar 29, 2016 at 11:06
  • no, I mean avoid handling OS native pop-up Commented Mar 29, 2016 at 11:10

2 Answers 2

1

What I've done is AutoIt script can accept command line parameter for invoking so my Java test use to read that property from properties file and then when I invoke AutoIt script I invoke it with the property as command line option to the AutoIt script and accept that command line argument in AutoIt script as the path to the file to be uploaded. Let me know if this works for you!!!
Also if your upload button is of type input then no need use AutoIt..directly element.sendKeys(<Path to upload file>) should work
Sample Code:

WinActivate("File Upload")
WinWaitActive("File Upload")
Send($CmdLine[1])
Send("{Enter}")

Here $CmdLine[1] accepts the first command line argument passed. so while calling this script (.exe) call it in this way.

Runtime.getRuntime().exec("src/test/resources/fileupload.exe "+path);

where path is the path to the file which you wish to upload. I assume you would already know when to call your AutoIt script :D
EDIT1 : $CmdLine[0] is reserved to get count of number of command line arguments passed to autoit script..so the actual arguments start with $CmdLine[1] which is the first argument passed on command line.
EDIT2: I am assuming you are running from a main method, if so then your call to execute autoIt script should be like this: Runtime.getRuntime().exec(TestUtility.properties.getProperty("test.all.autoit.testdata")+" "+args[0]); where args[0] is the args array passed as argument to main method whose 0th Index has excel sheet which you wish to pass. Also you need to pass absolute path of the excel spreadsheet.

Sign up to request clarification or add additional context in comments.

13 Comments

Could you please elaborate more.
Mrunal,Thanks for code. AutoIT script: WinWaitActive("File Upload") Send($CmdLine[0]) Send("{ENTER}") my way to call .exe from selenium script is Runtime.getruntime().exec("path-to-property-file"); From cmd-line,I trigger script by: d:>java -jar myjar.jar mypropertyfile.properties path-to-file-to-be-uploaded. Script is executed.But it displays error message ---Line2(File"pathname-to-exe"); error:Array variable has incorrect number of subscripts or subscript dimension range exceeded. Please guide me in resolving the error.
$CmdLine[0] is reserved to get count of number of command line arguments passed to autoit script..so the actual arguments start with $CmdLine[1] which is the first argument passed on command line.
Also, line--- Runtime.getRuntime().exec("src/test/resources/fileupload.exe "+path); is not feasible as I dont want to hard-code path-to-file-to-be-uploaded anywhere in the selenium and autoit script. User should enter the path-to-file-to-be-uploaded as argument in cmd line.
Simple Then use that argument like Runtime.getRuntime().exec(args[0]+" "+args[1]) where args[0] is the autoit script path passed in command line and args[1] is the file upload path specified in command line.
|
0

You can use ini files with IniRead and IniWrite functions

The file look like :

[SectionName]

KeyName1=Value

KeyName2=Value

And you read in the file with :

IniRead('nom_fichier.ini', 'SectionName', 'KeyName1', 'Default Value')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.