VBScript入门1+QTP

上午实习任务: 

  • 预习vbscript的分支和循环语句
  • 写代码判断月份是否大/小月
  • 写代码判断年份是否闰/平年
  • 写代码输出:输入的年份和月份,给出其相应月份的最大天数
  • 对两位数加法器的脚本用分支语句加强,使其能够回放正确和错误的数据

 

下午实习任务:

  • 将上午的年份和月份的代码改造成为过程(函数)

要点:

1、isNumeric(var)            判断var是否为数字

2、a = inputbox("xxx")    输入框输入

3、.GetVisibleText             获取当前框内的值

4、获取数据表里的值

Dim y
y = DataTable.GetSheet("Action2").GetParameter("A").Value

5、存储函数库

(1)存为xxx.qfl

使用LoadFunctionLibrary “绝对路径” + “xxx.qfl”

LoadFunctionLibrary "C:\Program Files\HP\QuickTest Professional\Tests\函数库\" + "checkM.qfl"

(2)存为xxx.txt

使用ansi编码

使用executefile “绝对路径+名称”

executefile "C:\Program Files\HP\QuickTest Professional\Tests\函数库\checkM.qfl"

6、统一调用函数库

(1)编写函数

点击[file] --> [new] --> [function library]

保存

(2)加载函数

点击[file] --> [settings]

[resource] --> “+”

选中对应函数加载


任务一:判断月份是否为大/小月

Dim m, n
m = inputbox("请输入月份:")
'msgbox m

If isNumeric(m) Then
	If m>=1 and m<=12 Then
		if(m=2 or m=4 or m=6 or m=9 or m=11) then
			msgbox m&"月是小月"
		else
			msgbox m&"月是大月"
		end if
	else
		msgbox "请输入正确的月份!"
	End If
else 
	msgbox "请输入数字!"
End If

任务二:判断年份是否为闰/平年

Dim y
'y = DataTable.GetSheet("Action2").GetParameter("A").Value
y = inputbox("请输入年份:")

If isNumeric(y) Then
	If ( (y mod 400)=0 or ((y mod 4)=0 and(y mod 100)<>0) ) then
		msgbox y & "是闰年"
	else
		msgbox y & "是平年"
	end if
else
	msgbox "输入年份非法!"
end if

任务三:输出:输入的年份和月份,给出其相应月份的最大天数

Dim y, m, s
y = inputbox("请输入年份:")
m = inputbox("请输入月份:")
s = 0

If (isnumeric(m) and isnumeric(y)) Then
	If ( (y mod 400)=0 or ((y mod 4)=0 and(y mod 100)<>0) ) then
		s = 1
	else
		s = 0
	end if

	If m>=1 and m<=12 Then
		if(m=2) then
			if(s=1) then
				msgbox "闰年"&m&"月有29天!"
			else
				msgbox "平年"&m&"月有28天!"
			end if
		elseif(m=4 or m=6 or m=9 or m=11) then
			msgbox m&"月有30天!"
		else
			msgbox m&"月有31天!"	
		end if
	else
		msgbox "请输入正确的月份!"
	End If
else
	msgbox "输入年份或月份非法!"
End If

任务四:对两位数加法器的脚本用分支语句加强

Window("Program Manager").WinListView("SysListView32").Activate "两位数加法器.exe"

Dim a, b

VbWindow("Form1").VbEdit("Text1").Set DataTable("p_Text", dtLocalSheet)
VbWindow("Form1").VbEdit("Text2").Set DataTable("p_Text1", dtLocalSheet)
VbWindow("Form1").VbButton("加").Click

a = VbWindow("Form1").VbEdit("Text1").GetVisibleText
If VbWindow("Form1").Dialog("测试技术").Exist Then
	VbWindow("Form1").Dialog("测试技术").WinButton("确定").Click
End If
'If a>99or a<-99 Then	
'	VbWindow("Form1").Dialog("测试技术").WinButton("确定").Click
'End If

VbWindow("Form1").Close

对于任何会弹出错误窗口的数据,都自动点击“确定”关闭


任务五:改造成为函数

1、检查月份

Sub checkM(m)
	If isNumeric(m) Then
		If m>=1 and m<=12 Then
			if(m=2 or m=4 or m=6 or m=9 or m=11) then
				msgbox m&"月是小月"
			else
				msgbox m&"月是大月"
			end if
		else
			msgbox "请输入正确的月份!"
		End If
	else 
		msgbox "请输入数字!"
	End If
End Sub

2、检查年份

Sub checkY(y)
	If isNumeric(y) Then
		If ( (y mod 400)=0 or ((y mod 4)=0 and(y mod 100)<>0) ) then
			msgbox y & "是闰年"
		else
			msgbox y & "是平年"
		end if
	else
		msgbox "输入年份非法!"
	end if
End Sub

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值