Reputation: 1500
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'
Upvotes: 0
Views: 1075
Reputation: 4683
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.
Upvotes: 1
Reputation: 1677
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')
Upvotes: 0