0

I have windows file import method and applciation works fine if i click buttons manually but same code fails if i run my application using tools like QTP (Quick Test Professional)

I have highlighted failing line in bold. [ 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 code which triggers the import. SwfWindow("Swfname:=ImportFWImagesWF").SwfButton("Swfname:=btnNext","text:=Import").Click

I am overriding Stream c# class. and I am ending up having Socket exceptions "System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host"

I am overriding Stream c# class. My class name is RemoteFileStream

Server Code

    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
    }

NOTE: Exception rises only when I access my application from QTP tool. If I manually run my application there is no issues. Is it because of permission issue? Please help me.

kudlatiger
  • 3,028
  • 8
  • 48
  • 98
  • Hi, could you describe the actual failure : what happens ? you get an exception, or data is simply not written ? – Kek Jun 27 '12 at 12:59
  • 1
    Sounds like it could be a permission issue. You should double check to see what user id is being used when QTP is automatically run and make sure that user has write permission on the file you are accessing. – J.C. Yamokoski Jun 27 '12 at 13:27
  • it not firing or catching exception. debugger jumps out and dissapears. I used try-catch but its not catching. But when i click "break all" it stops near end of while loop. seems like while loop is not ending. – kudlatiger Jun 27 '12 at 13:40
  • Hi Jony, even i feel its permission issue. I am working on it. – kudlatiger Jun 27 '12 at 13:42
  • Please add the QTP step that triggers this action. – Motti Jun 28 '12 at 08:38
  • Hi Motti,SwfWindow("Swfname:=ImportFWImagesWF").SwfButton("Swfname:=btnNext","text:=Import").Click – kudlatiger Jun 29 '12 at 04:08

1 Answers1

0

When QTP runs steps it has the option of using simulating events in the application (in .NET's case firing .NET event) or simulating device actions. The way to tell which option QTP is using for a click step can be to see if the mouse cursor moved to the button when the step took place.

If QTP is using event run then it could be that it didn't run the exact events that the application is expecting thus giving different results than during manual testing. In this case you can try using the DeviceReplay object (as described here).

Motti
  • 110,860
  • 49
  • 189
  • 262