Download file from a URL using AutoIt, and run in Robot Framework. (Also can use in other application)
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 <InetConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
; 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <InetConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> ; 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | *** 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 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2019-01-03 [Robot Framework] 校验字符串中是否包含某个子字符串,校验同时满足两个条件中任意一个
2018-01-03 [Robot Framework] Robot Framework里面的变量怎么知道是在哪里定义的?
2018-01-03 [Robot Framework] Robot Framework怎么调试?
2014-01-03 Jmeter中控制某一段脚本失败后重复执行,并在每个HTTP Request名字中加上循环次数