我有windows文件导入方法,如果我手动点击按钮,applciation工作正常但是如果我使用QTP(Quick Test Professional)等工具运行我的应用程序,相同的代码将失败
我用粗体突出显示了失败的行。 [remoteStream.Write(buffer,0,bytesRead);]
using (FileStream localStream = File.OpenRead(filePath))
{
RemoteFile remoteFile = this.serverComponent.GetUploadFileHandle(filePath);
if (remoteFile == null)
{
stopWatch.Stop();
}
using (RemoteFileStream remoteStream = new RemoteFileStream(remoteFile))
{
long localFileSize = localStream.Length;
long readSoFar = 0;
int bytesRead = 0;
byte[] buffer = new byte[bufferSize];
while ((bytesRead = localStream.Read(buffer, 0, bufferSize)) > 0)
{
remoteStream.Write(buffer, 0, bytesRead);
readSoFar += bytesRead;
progressListener.UpdateFileProgress(firmwareID, readSoFar, localFileSize);
}
}
uploadSuccess = this.server.UploadFileDone(remoteFile);
}
stopWatch.Stop();
progressListener.UpdateFileStatus(firmwareID, uploadSuccess ? FirmwareImportStatus.ImportSuccessful : FirmwareImportStatus.ImportFailed);
}
触发导入的QTP代码。 SwfWindow( “Swfname:= ImportFWImagesWF”)。SwfButton( “Swfname:= btnNext”, “文本:=导入”),点击
我正在覆盖 Stream c#class。我最终得到了Socket异常 “System.Net.Sockets.SocketException:远程主机强行关闭现有连接”
我正在重写Stream c#class。我的班级名称是 RemoteFileStream
服务器代码
public override void Write(byte[] buffer, int offset, int count)
{
#region Check Args
if (buffer == null)
{
throw (new ArgumentNullException("The buffer is null"));
}
if (offset < 0 || count < 0)
{
throw (new ArgumentOutOfRangeException("The offset or count is negative."));
}
if (offset + count > buffer.Length)
{
throw (new ArgumentException("The sum of offset and count is larger than the buffer length."));
}
#endregion
_rf.Write(buffer, offset, count);//Exception comes from here
}
注意:只有当我从QTP工具访问我的应用程序时,异常才会上升。如果我手动运行我的应用程序没有问题。是因为许可问题吗?请帮帮我。
答案 0 :(得分:0)
当QTP运行步骤时,它可以选择在应用程序中使用模拟事件(在.NET的情况下触发.NET事件)或模拟设备操作。判断QTP用于单击步骤的方法可以是查看步骤发生时鼠标光标是否移动到按钮。
如果QTP正在使用事件运行,那么可能是它没有运行应用程序所期望的确切事件,从而给出与手动测试期间不同的结果。在这种情况下,您可以尝试使用DeviceReplay
对象(described here)。