自动化脚本测试流程跑跑卡丁车0

发布时间:2021-07-05 来源:脚本之家 点击:

不过没有关系,遇到这种情况时,我们可以对上面的代码进行局部优化,就能实现目的在默认情况下,脚本在本地计算机上运行

神武3手游日常脚本

strComputer="."
Set objCmdLib=CreateObject("Microsoft.CmdLib")
Set objCmdLib.ScriptingHost=WScript.Application
Set objWMIService=GetObject("winmgmts:\" & strComputer & "\root\cimv2")
WScript.Echo objCmdLib.getHostName(objWMIService)
首先,定义一个事件:

  在CDog类的通用声明部分添加下列代码:

->PublicEventAwake()->

  在CDog类中添加Sleep子过程:

->PublicSubSleep()

 DimiAsLong
 Fori=1To1000000
  DoEvents:DoEvents:DoEvents
  exit
  RaiseEventAwake
EndSub
->

  代码中,一开始做一些1000000次无用的循环,计算机短暂停顿后,Sleep子过程激发Awake事件


'======================================
' VBS 中 SendKeys 模拟键盘击键
' 2009-07-26
' 刘林
'======================================
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd"
' 让脚本等待1000毫秒,也就是1秒再执行下一条语句
WScript.Sleep 1000
' -- 发送字符时,输入法一定要在英文件状态下
' 发送分号
WshShell.SendKeys ";"
WScript.Sleep 1000
' 发送冒号
WshShell.SendKeys ":"
WScript.Sleep 1000
' 发送双引号 -- 利用chr把双引号转换出来
WshShell.SendKeys Chr(34)
WScript.Sleep 1000
' 发送带有双引号的字符串
WshShell.SendKeys Chr(34)&"this is a string"&Chr(34)
WScript.Sleep 1000
' -- 切记,这里是模拟的击键操作,所以不能发送中文
'WshShell.SendKeys Chr(34)&"这是一个字符串"&Chr(34)
WScript.Sleep 1000
'================================================
' -- 如何模拟回车,上档键,Alt键喃?
'================================================
' -- 如何模拟回车, -- {enter}这就代表是发送回车
WshShell.SendKeys "this is a enter!{enter}"
WScript.Sleep 1000
' -- 如何模拟上档键Shift, -- +这就代表是发送shift
WshShell.SendKeys "this is +a" ' 结果为 this is A
WScript.Sleep 1000
' -- 如何模拟Alt, -- %这就代表是发送Alt
WshShell.SendKeys "this is %{TAB}" ' 结果为 切换窗口
WScript.Sleep 1000
'===========================================================
' -- 那么如何发送%, + ^ 喃
WshShell.SendKeys "this is {+}{^}{%}" ' 结果为 切换窗口
WScript.Sleep 1000
' -- 这里你可能已经明白了,发送送特殊字符时,请放到 {} 中
'===========================================================
'======================================
' 更多信息请看VBS帮助文档 2009-07-26
'======================================

  方法一

  这种方法是在窗体的MouseDown、MouseUp和MouseMove等事件的处理过程中添加代码,实现在鼠标左键按下后移动时,改变窗体的Left和Top属性,实现移动无标题栏的窗体


->PublicFunctionZDX(XAsCurrency)AsString
DimlnPAsInteger
DimPrcAsString
DimTmpAsString
DimNoBAsCurrency
DimDxAsString
DimXxAsString
DimZhenAsBoolean
DimStr(10)AsString
DimChinaAsString
China="分角元拾佰仟万拾佰仟亿"
Str(0)="零"
Str(1)="壹"
Str(2)="贰"
Str(3)="叁"
Str(4)="肆"
Str(5)="伍"
Str(6)="陆"
Str(7)="柒"
Str(8)="捌"
Str(9)="玖"

Zhen=True
X=FormatNumber(X,2)
Prc=CStr(X)
Prc=Replace(Prc,",","")

lnP=Len(Prc)
Fori=lnP-1To1Step-1
IfMid(Prc,i,1)="."Then
SelectCaselnP-i
Case1
Prc=Replace(Prc,".","") "0"
Case2
Prc=Replace(Prc,".","")
EndSelect
Zhen=False
ExitFor
EndIf
Nexti
IfZhenThenPrc=Prc "00"
lnP=Len(Prc)
Fori=1TolnP
Tmp=Str(Mid(Prc,i,1))&Tmp
Nexti

ZDX=""
fy=1
Fori=1TolnP
Xx=Mid(Tmp,i,1)
Dx=Mid(China,i,1)

IfXx<>"零"Then
ZDX=Xx&Dx&ZDX
f=1
Else
Ifi=3Then
ZDX=Dx&ZDX
EndIf

Ifi=7Then
ZDX=Dx&ZDX
EndIf
IffThen
ZDX="零"&ZDX
EndIf
f=0
EndIf
Nexti
IfZhenThenZDX=ZDX "正"
ZDX=Replace(ZDX,"零万","万")
ZDX=Replace(ZDX,"零元","元")

EndFunction->
->

起号姿势
  `定义用于恢复桌面的函数
  PrivateDeclareFunctionInvalidateRectAsAnyLib“user32”Alias
“InvalidateRect”_(ByValhwndAsLong,lpRectAsAny,ByValbEraseAsLong)AsLong

  PrivateSubForm_Load()
  Me.Hide
  DimPicAsLong
  DimwAsLong
  DimhAsLong
  DimxAsLong
  Dimsx,sy
  Picture1.AutoRedraw=True
  `获取桌面的HDC
  x=GetDC(0)
  `计算桌面的宽度和高度
  sx=Screen.Width\Screen.TwipsPerPixelX
  sy=Screen.Height\Screen.TwipsPerPixelY
  `计算图像的宽度和高度
  w=Picture1.ScaleX(Picture1.Picture.Width,8,vbPixels)
  h=Picture1.ScaleY(Picture1.Picture.Height,8,vbPixels)

  picture1.picture=loadpicture(“图像文件的完整文件名称”)

  `使透空的图像显示在桌面的中央
  Pic=TransparentBlt(x,_
  sx/2-w/2,_
  sy/2-h/2,_
  w,_
  h,_
  Picture1.hDC,_
  0,_
  0,_
  w,_
  h,_
  RGB(255,255,255))
  EndSub
  PrivateSubTimer1_Timer()
  `两秒钟后恢复桌面
  InvalidateRectAsAny0,ByVal0&,True
  Load自制程序的主窗体名
  Timer1.Enabled=False
  EndSub
  需要注意的是程序完成后如果直接在VB环境下运行有可能会出现透空图像一闪而过的现象,这并不是你的错,只要把程序编译成*.exe的文件后运行一切都会正常的
'XML Upload Class
Class XMLUpload
Private xmlHttp
Private objTemp
Private adTypeBinary, adTypeText
Private strCharset, strBoundary

Private Sub Class_Initialize()
adTypeBinary=1
adTypeText=2
Set xmlHttp=CreateObject("Msxml2.XMLHTTP")
Set objTemp=CreateObject("ADODB.Stream")
objTemp.Type=adTypeBinary
objTemp.Open
strCharset="utf-8"
strBoundary=GetBoundary()
End Sub

Private Sub Class_Terminate()
objTemp.Close
Set objTemp=Nothing
Set xmlHttp=Nothing
End Sub

'指定字符集的字符串转字节数组
Public Function StringToBytes(ByVal strData, ByVal strCharset)
Dim objFile
Set objFile=CreateObject("ADODB.Stream")
objFile.Type=adTypeText
objFile.Charset=strCharset
objFile.Open
objFile.WriteText strData
objFile.Position=0
objFile.Type=adTypeBinary
If UCase(strCharset)="UNICODE" Then
objFile.Position=2 'delete UNICODE BOM
ElseIf UCase(strCharset)="UTF-8" Then
objFile.Position=3 'delete UTF-8 BOM
End If
StringToBytes=objFile.Read(-1)
objFile.Close
Set objFile=Nothing
End Function

'获取文件内容的字节数组
Private Function GetFileBinary(ByVal strPath)
Dim objFile
Set objFile=CreateObject("ADODB.Stream")
objFile.Type=adTypeBinary
objFile.Open
objFile.LoadFromFile strPath
GetFileBinary=objFile.Read(-1)
objFile.Close
Set objFile=Nothing
End Function

'获取自定义的表单数据分界线
Private Function GetBoundary()
Dim ret(12)
Dim table
Dim i
table="abcdefghijklmnopqrstuvwxzy0123456789"
Randomize
For i=0 To UBound(ret)
ret(i)=Mid(table, Int(Rnd() * Len(table) + 1), 1)
Next
GetBoundary="---------------------------" & Join(ret, Empty)
End Function

'设置上传使用的字符集
Public Property Let Charset(ByVal strValue)
strCharset=strValue
End Property

'添加文本域的名称和值
Public Sub AddForm(ByVal strName, ByVal strValue)
Dim tmp
tmp="\r\n--$1\r\nContent-Disposition: form-data; name=""$2""\r\n\r\n$3"
tmp=Replace(tmp, "\r\n", vbCrLf)
tmp=Replace(tmp, "$1", strBoundary)
tmp=Replace(tmp, "$2", strName)
tmp=Replace(tmp, "$3", strValue)
objTemp.Write StringToBytes(tmp, strCharset)
End Sub

'设置文件域的名称/文件名称/文件MIME类型/文件路径或文件字节数组
Public Sub AddFile(ByVal strName, ByVal strFileName, ByVal strFileType, ByVal strFilePath)
Dim tmp
tmp="\r\n--$1\r\nContent-Disposition: form-data; name=""$2""; filename=""$3""\r\nContent-Type: $4\r\n\r\n"
tmp=Replace(tmp, "\r\n", vbCrLf)
tmp=Replace(tmp, "$1", strBoundary)
tmp=Replace(tmp, "$2", strName)
tmp=Replace(tmp, "$3", strFileName)
tmp=Replace(tmp, "$4", strFileType)
objTemp.Write StringToBytes(tmp, strCharset)
objTemp.Write GetFileBinary(strFilePath)
End Sub

'设置multipart/form-data结束标记
Private Sub AddEnd()
Dim tmp
tmp="\r\n--$1--\r\n"
tmp=Replace(tmp, "\r\n", vbCrLf)
tmp=Replace(tmp, "$1", strBoundary)
objTemp.Write StringToBytes(tmp, strCharset)
objTemp.Position=2
End Sub

'上传到指定的URL,并返回服务器应答
Public Function Upload(ByVal strURL)
Call AddEnd
xmlHttp.Open "POST", strURL, False
xmlHttp.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & strBoundary
'xmlHttp.setRequestHeader "Content-Length", objTemp.size
xmlHttp.Send objTemp
Upload=xmlHttp.responseText
End Function
End Class

Dim UploadData
Set UploadData=New XMLUpload
UploadData.Charset="utf-8"
UploadData.AddForm "content", "Hello world" '文本域的名称和内容
UploadData.AddFile "file", "test.jpg", "image/jpg", "test.jpg"
WScript.Echo UploadData.Upload("")
Set UploadData=Nothing

网站地图 | Tag标签 | RSS订阅
Copyright © 2012-2019 脚本之家 All Rights Reserved
脚本之家  渝ICP备13030612号