Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 奇怪但真实-手动工作正常,但在自动工具(如QTP)中失败_C#_Qtp - Fatal编程技术网

C# 奇怪但真实-手动工作正常,但在自动工具(如QTP)中失败

C# 奇怪但真实-手动工作正常,但在自动工具(如QTP)中失败,c#,qtp,C#,Qtp,我有windows文件导入方法,如果手动单击按钮,应用程序工作正常,但如果使用QTP(Quick Test Professional)等工具运行应用程序,相同的代码将失败 我用粗体突出显示了失败的一行[remoteStream.Write(缓冲区,0,字节读取);] using (FileStream localStream = File.OpenRead(filePath)) { RemoteFile remoteFile =

我有windows文件导入方法,如果手动单击按钮,应用程序工作正常,但如果使用QTP(Quick Test Professional)等工具运行应用程序,相同的代码将失败

我用粗体突出显示了失败的一行[remoteStream.Write(缓冲区,0,字节读取);]

    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:=importfWimagesSWF”).SwfButton(“Swfname:=btnNext”,“text:=Import”)。单击

我正在覆盖c#类。我最终会遇到套接字异常 “System.Net.Sockets.SocketException:现有连接被远程主机强制关闭”

我正在重写流c#类。我的类名是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
    }
公共重写无效写入(字节[]缓冲区、整数偏移量、整数计数)
{
#区域检查参数
if(buffer==null)
{
抛出(新ArgumentNullException(“缓冲区为空”);
}
如果(偏移量<0 | |计数<0)
{
抛出(新ArgumentOutOfRangeException(“偏移量或计数为负数”);
}
if(偏移量+计数>缓冲区长度)
{
抛出(新参数异常(“偏移量和计数之和大于缓冲区长度”);
}
#端区
_Write(缓冲区、偏移量、计数);//异常来自这里
}

注意:只有当我从QTP工具访问我的应用程序时,异常才会出现。如果我手动运行应用程序,则不会出现任何问题。是因为权限问题吗?请帮助我。

当QTP运行步骤时,它可以选择在应用程序中使用模拟事件(在.NET的情况下是触发.NET事件)或模拟设备操作。判断QTP在单击步骤中使用哪个选项的方法是查看在执行该步骤时鼠标光标是否移动到按钮


如果QTP正在使用事件运行,那么可能是因为它没有运行应用程序所期望的确切事件,因此产生了与手动测试不同的结果。在这种情况下,您可以尝试使用
DevicePlay
对象(as)。

您好,您能描述一下实际的故障:发生了什么?您会遇到异常,或者数据根本没有写入?听起来可能是权限问题。当QTP自动运行时,您应该仔细检查正在使用的用户id,并确保用户对您正在访问的文件具有写入权限。它不会触发或捕获异常。调试器跳出并消失。我曾经试过接球,但它不接球。但当我点击“全部中断”时,它会在while循环的末尾停止。好像while循环还没有结束。嗨,乔尼,连我都感觉到了它的许可问题。我正在处理。请添加触发此操作的QTP步骤。嗨,莫蒂,不,这与DeviceReplay@Deepak在这种情况下,我很抱歉,但我不知道是什么原因导致:(