What need to figure out?
1.Pass Download URL from Robot Framework to AutoIt.
2.Return File Save Path from AutoIt to Robot Framework.
Step 1: Write AutoIt Script in Notepad++, save as downloadFileFromURL.au3
#include
#include
#include
; Download a file in the background.
; Wait for the download to complete.
Local $FileDownloadURL = $CmdLine[1]
;Local $FileDownloadURL = "https://test.com/installer.exe"
Local $FileSavePath = @TempDir & "\awsinstaller.exe"
; Download the file by waiting for it to complete. The option of 'get the file from the local cache' has been selected.
Local $iBytesSize = InetGet($FileDownloadURL, $FileSavePath, $INET_FORCERELOAD)
; Retrieve the filesize.
Local $iFileSize = FileGetSize($FileSavePath)
; Return with file save path
ConsoleWrite($FileSavePath)
Step 2: Right Click downloadFileFromURL.au3 , select Compile Script in the list.
downloadFileFromURL.au3 will be compiled to an exe.
Step 3: Call downloadFileFromURL.exe in Robot Framework.
${fileURL} Set Variable https://test.com/installer.exe
${exePath} Set Variable D:\\Tool\\downloadFileFromURL.exe
${result} Run Process ${exePath} ${fileURL}
log ${result.stdout}
Pass parameter from Robot Framework to AutoIt.
Use CmdLine provided by AutoIt
$CmdLine[0] ; Contains the total number of items in the array. $CmdLine[1] ; The first parameter. $CmdLine[2] ; The second parameter. ... $CmdLine[nth] ; The nth parameter e.g. 10 if the array contains 10 items.
Return Value from AutoIt to Robot Framework.
1.Use AutoIt's ConsoleWrite ,write value to stdout
2.Use ${result.stdout} returned by Robot Framework's Run Process , read value from stdout
Compile AutoIt Script to exe
Run exe in Robot Framework
为了增加稳定性,做了一下改进。
之前是通过IE浏览器打开安装的URL,很不稳定,改成使用AutoIt进行下载并启动安装.
附上完整的AutoIt脚本和Robot Framework脚本。
downloadFileFromURL.au3
#include#include #include ; Download a file in the background. ; Wait for the download to complete. ;Local $FileDownloadURL = "https://test.com/installer.exe" Local $FileDownloadURL = $CmdLine[1] Local $FileName = $CmdLine[2] Local $FileSavePath = @TempDir & "\" & $FileName ; Download the file by waiting for it to complete. The option of 'get the file from the local cache' has been selected. Local $iBytesSize = InetGet($FileDownloadURL, $FileSavePath, $INET_FORCERELOAD) ; Retrieve the filesize. Local $iFileSize = FileGetSize($FileSavePath) ; Return with file save path ConsoleWrite($FileSavePath)
UninstallAndInstallOfficeUS.txt in Robot Framework
*** Settings *** Test Timeout 5 minutes Resource ../../../04.BasicReferenceSet/businessReferenceSet.html Resource ../../../04.BasicReferenceSet/publicReference.html *** Test Cases *** InstallOfficeUS [Tags] InstallOfficeUS [Setup] Clean And Close Current App ${processName} [Timeout] 10 minutes Delete File From Directory ${TEMPDIR}/prerequisite.exe Delete File From Directory ${TEMPDIR}/awsinstaller.exe Delete File From Directory ${TEMPDIR}/setup.exe Clean Process chrome Clean Process OUTLOOK Clean Process Teams ${fileDownloadURL} Get Installation Link ${installFileName} Fetch From Right ${fileDownloadURL} / ${exePath} Join Path ${EXECDIR} 06.The_Attachment Tool downloadFileFromURL.exe ${result} Run Process ${exePath} ${fileDownloadURL} ${installFileName} ${officeUSExePath} Set Variable ${result.stdout} Run Process ${officeUSExePath} timeout=10 Win Wait Morningstar Office Prerequisite 3.19 - InstallShield Wizard TimeOut=120 AutoItLibrary.Send !N Win Wait Morningstar Office Prerequisite 3.19 - InstallShield Wizard InstallShield Wizard Completed TimeOut=10 AutoItLibrary.Send !C Run Process ${officeUSExePath} timeout=120 Win Wait Morningstar Office - InstallShield Wizard TimeOut=10 Sleep 1 AutoItLibrary.Send !N Sleep 1 AutoItLibrary.Send !N Sleep 1 AutoItLibrary.Send !N Sleep 1 AutoItLibrary.Send !I Win Wait Morningstar Office - InstallShield Wizard Installing Morningstar Office TimeOut=10 Win Wait Close Morningstar Office - InstallShield Wizard Installing Morningstar Office TimeOut=180 Win Wait Morningstar Office - InstallShield Wizard InstallShield Wizard Completed TimeOut=10 AutoItLibrary.Control Click strTitle=Morningstar Office - InstallShield Wizard strText=InstallShield Wizard Completed strControl=[CLASSNN:Button5] AutoItLibrary.Send !F File Should Exist C:\\Program Files (x86)\\Morningstar\\Office\\MStarAWD.exe Install Failed! [Teardown] Clean Process SavUI UninstallOfficeUS [Tags] UninstallOfficeUS [Setup] Clean And Close Current App ${processName} Clean Process msiexec AutoItLibrary.Run C:\\Windows\\System32\\control.exe \ appwiz.cpl AutoItLibrary.Win Wait Programs and Features TimeOut=5 AutoItLibrary.Win Activate Programs and Features AutoItLibrary.Send Morningstar Office AutoItLibrary.Send {ENTER} Sleep 1 AutoItLibrary.Send !Y Win Wait Morningstar Office Please wait while Windows configures Morningstar Office TimeOut=5 Win Wait Close Morningstar Office Please wait while Windows configures Morningstar Office TimeOut=180 Sleep 2 [Teardown] Run Keywords Win Close Programs and Features ... AND Clean Process Un_A UninstallOfficePrerequisite [Tags] UninstallOfficePrerequisite [Setup] Clean And Close Current App ${processName} Clean Process msiexec AutoItLibrary.Run C:\\Windows\\System32\\control.exe \ appwiz.cpl AutoItLibrary.Win Wait Programs and Features AutoItLibrary.Win Activate Programs and Features AutoItLibrary.Send Morningstar Office Prerequisite 3.19 AutoItLibrary.Send {ENTER} Sleep 1 AutoItLibrary.Send !Y Sleep 3 [Teardown] Run Keywords Win Close Programs and Features ... AND Clean Process Un_A