Getting text from putty via Clipboard

Ranorex Spy, Recorder, and Studio.
chandu.ise
Posts: 11
Joined: Wed Aug 13, 2008 8:27 am

Getting text from putty via Clipboard

Post by chandu.ise » Fri Aug 29, 2008 5:43 pm

Hi michael,
Thanxs for ur precious reply.. Sorry michael i couldnt get what u said i was trying the above operation but couldnt succeed... pLe if u dont mind can u please let me know in detail how to select putty system icon for copying it into clipboard...and by the way ple provide me with any help documentation for ranorex studio...will be awaiting for ur reply soon

regards

chandrashekar

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Mon Sep 01, 2008 2:53 pm

Hi chandrashekar,

when you left-click on the small icon on the upper-left corner of Putty's window, the system menu will pop up. There's a menu item called "Copy All to Clipboard" you should click on to copy all the text from the putty session to the clipboard. You can then use the Clipboard.GetText() method to retrieve this text in your code.

Just use the Ranorex Recorder to record the mouse clicks on the menu item and let the recorder generate the code for you.

You can find documentation on RanorexStudio on our homepage:
http://www.ranorex.com/gui-testing-guid ... tudio.html

Regards,
Alex
Ranorex Support Team

PS: If you want to respond to a forum post, you can also click the "PostReply" button instead of creating a new thread for each post. :D

chandu.ise
Posts: 11
Joined: Wed Aug 13, 2008 8:27 am

logger info

Post by chandu.ise » Mon Sep 01, 2008 5:25 pm

Thanks Alex,
I never thought that i get reply so soon from this forum...I have one more thing to clarify, let me know how u would invoke putty through renorex studio.. i tried system.diagnostics cmd to invoke as u invoke anyother console...but i couldnt succeed calling PUTTY..could u ple help me out with this issue

regards
chandrashekar

chandu.ise
Posts: 11
Joined: Wed Aug 13, 2008 8:27 am

logger info-putty

Post by chandu.ise » Tue Sep 02, 2008 5:02 am

Hi Alex,
I tried to do as u said,but i am facing a problem "The name 'Clipboard' doesnt exist in the current context" in the Ranorex studio...could u ple tell me what could be the problem...ple let me know the other version of using clipboard.GetText() command..

regards
chandrashekar

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Tue Sep 02, 2008 10:18 am

You need to specify the exact path to your Putty.exe executable in the Process.Start or Ranorex.Application.StartWindowsApplication method.

The ClipBoard class is in the System.Windows.Forms namespace, so you might need to add a using statement and add a reference to the System.Windows.Forms DLL to your project.

Regards,
Alex
Ranorex Support Team

chandu.ise
Posts: 11
Joined: Wed Aug 13, 2008 8:27 am

logger info

Post by chandu.ise » Tue Sep 02, 2008 2:14 pm

Thanks alex,
Finally i got what i was trying
I added the System.windows.Form DLL in to my Reference...i included using system.windows.Form in the program.cs and i used Clipboard.getText()...what exact parameters i need to pass ??...i wanted a particular string to be found out of clipboard Content..how can i search in the Clipboard contents...If you help me out this i could finish off my automation part...please let me know ASAP

regards
chandrashekar

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Tue Sep 02, 2008 2:44 pm

The Clipboard is a .NET framework class, please consult the MSDN documentation for the exact parameters to its methods.
You might also want to take a look at the documentation of the .NET string class that provides methods to search in strings.

Regards,
Alex
Ranorex Support Team

chandu.ise
Posts: 11
Joined: Wed Aug 13, 2008 8:27 am

pseudo code - putty

Post by chandu.ise » Wed Sep 03, 2008 7:23 am

Alex,

i have pasted the code for clipboard control...please correct me,i am facing problem executing that...kindly help me out,its very important for me.
steps : assume u have copied the contents from putty now u want to access it in your ranorex studio...just see the try block and let me know what has to be done...bcoz when i execute that piece of code i am getting errors thats y !!!



using System;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Ranorex;

namespace MemCPU
{
class Program
{
[STAThread]
public static int Main(string[] args)
{
int error = 0;
string str;

Logger.LogFileTitle = "Ranorex Log File";
Logger.Initialize(false, "test1.txt", "test1.xml", LogLevel.Info);

try
{
Automation.Test1(); //contains code for executing cmd and copying contents into clipboard

Dim idata as IDataObject = Clipboard.GetDataObject();
if iData.GetDataPresent(DataFormats.Text)
{
str = (String)iData.GetData(DataFormats.Text);
}
else
{
str = "Could not retrieve data off the clipboard.";
}
}
catch (ValidationException)
{
Logger.Error("Validation failed!");
error = -1;
}

chandu.ise
Posts: 11
Joined: Wed Aug 13, 2008 8:27 am

finally solved-putty

Post by chandu.ise » Wed Sep 03, 2008 10:30 am

Alex,

I have done what ever u suggested me...just check with my code bcoz i was facing trouble with my verification...let me know what i should do...everything works fine..thanks for everything

regards
chandrashekar


IDataObject idata;
Logger.LogFileTitle = "Ranorex Log File";
Logger.Initialize(false, null, "test1.xml", LogLevel.Info);
try
{

Automation.Test1(); // Invoke putty
Automation.Test2(); // mouse move on putty system menu

idata = Clipboard.GetDataObject();
if(idata.GetDataPresent(DataFormats.Text))
{
str = (String)idata.GetData(DataFormats.Text);
Logger.Info("contents copied into Clipboard...");
res = str.Contains(searchstr);
Logger.Info("Finding CPU Model in Clipboard...");
Validate.AreEqual(res,"True","CPU Model String Not present"); }
else {
str = "Could not retrieve data off the clipboard.";
}
Logger.OpenLogViewer();

}

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Thu Sep 04, 2008 8:35 am

You are comparing a bool to a string instance (variable res is obviously a bool, "True" a string). That can't work.

Replace the "True" literal with the true keyword or use the Validate.IsTrue method:

Code: Select all

Validate.AreEqual(res,true,"CPU Model String Not present");
// or
Validate.IsTrue(res, "CPU Model String Not present");
Regards,
Alex
Ranorex Support Team

chandu.ise
Posts: 11
Joined: Wed Aug 13, 2008 8:27 am

Ranorex

Post by chandu.ise » Fri Sep 05, 2008 6:07 pm

Hi

Thanks for everything...I got what i was trying...


regards
chandrashekar