目录
- 实验概述
- 实验内容
- 1. 下载安装AutoIT。
- 2. 测试win系统自带计算器程序, 2+4=6,是否正确? 写出Script。(小提示:使用WinGetText获得输出)
- 3.测试win系统自带计算器程序, 写出3个以上的测试用例的代码,运行看是否正确?
- Test: 2*4
- Test: 8/4
- Test:8-4
- Test: 1/4*8
实验概述
目的及要求:锻炼学生对自动化功能测试的熟悉程度。
基本原理:功能测试需要从GUI的角度设计自动化测试脚本。利用AutoIT等自动化软件,编写自动测试脚本并记录结果,为缺陷记录提供帮助。
实施环境:AutoIt、Windows 7;
实验内容
1. 下载安装AutoIT。
在https://www.autoitscript.com/site/autoit/downloads/下载autoIt的安装包。
2. 测试win系统自带计算器程序, 2+4=6,是否正确? 写出Script。(小提示:使用WinGetText获得输出)
Run( "calc.exe" )
WinWaitActive( "计算器" )
ControlClick( "计算器" , "" , 132 )
ControlClick( "计算器" , "" , 93 )
ControlClick( "计算器" , "" , 134 )
ControlClick( "计算器" , "" , 121 )$Result=WinGetText( "计算器" )
$Result1=StringRegExpReplace($Result,'(?m)[\n|\r]','')
if $Result1== "6" ThenFileWriteLine( "C:\result.txt" , "true" )
ElseFileWriteLine( "C:\result.txt" , "False" &$Result1)
EndIf
3.测试win系统自带计算器程序, 写出3个以上的测试用例的代码,运行看是否正确?
Test: 2*4
Run( "calc.exe" )
WinWaitActive( "计算器" )
ControlClick( "计算器" , "" , 132 )
ControlClick( "计算器" , "" , 92 )
ControlClick( "计算器" , "" , 134 )
ControlClick( "计算器" , "" , 121 )$Result=WinGetText( "计算器" )
$Result1=StringRegExpReplace($Result,'(?m)[\n|\r]','')
if $Result1== "8" ThenFileWriteLine( "C:\result.txt" , "true" )
ElseFileWriteLine( "C:\result.txt" , "False" &$Result1)
EndIf
Test: 8/4
Run( "calc.exe" )
WinWaitActive( "计算器" )
ControlClick( "计算器" , "" , 138 )
ControlClick( "计算器" , "" , 91 )
ControlClick( "计算器" , "" , 134 )
ControlClick( "计算器" , "" , 121 )$Result=WinGetText( "计算器" )
$Result1=StringRegExpReplace($Result,'(?m)[\n|\r]','')
if $Result1== "2" ThenFileWriteLine( "C:\result.txt" , "true" &$Result1)
ElseFileWriteLine( "C:\result.txt" , "False" &$Result1)
EndIf
Test:8-4
Run( "calc.exe" )
WinWaitActive( "计算器" )
ControlClick( "计算器" , "" , 138 )
ControlClick( "计算器" , "" , 94 )
ControlClick( "计算器" , "" , 134 )
ControlClick( "计算器" , "" , 121 )$Result=WinGetText( "计算器" )
$Result1=StringRegExpReplace($Result,'(?m)[\n|\r]','')
if $Result1== "4" ThenFileWriteLine( "C:\result.txt" , "true" &$Result1)
ElseFileWriteLine( "C:\result.txt" , "False" &$Result1)
EndIf
Test: 1/4*8
Run( "calc.exe" )
WinWaitActive( "计算器" )
ControlClick( "计算器" , "" , 134 )
ControlClick( "计算器" , "" , 114 )
ControlClick( "计算器" , "" , 92 )
ControlClick( "计算器" , "" , 138 )
ControlClick( "计算器" , "" , 121 )$Result=WinGetText( "计算器" )
$Result1=StringRegExpReplace($Result,'(?m)[\n|\r]','')
if $Result1== "2" ThenFileWriteLine( "C:\result.txt" , "true" &$Result1)
ElseFileWriteLine( "C:\result.txt" , "False" &$Result1)
EndIf
result.txt在c盘下,可以自己改路径。
autoIt确实有点难用了,引号里删一个字就开始乱码,而且在win10里识别不到我的计算器的按钮ID,就用学院楼的电脑开始写,学院楼的电脑截图好不方便啊,snipaste真的香香。