4 Answers, 1 is accepted
0
Hello Jon,
Anthony
the Telerik team
Use the Clipboard Class. This is basic .NET code and not specific to Test Studio.
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
Jon
Top achievements
Rank 1
answered on 13 Aug 2012, 09:30 PM
Hi Anthony
The clipboard class doesn't work. I can only assume this is because the content is running in a MTU state, the clipboard function must be run in a STA thread.
I did some research and found that the following code snippet should work, but doesn't in Test Studio...
If you could take another look at this I would greatly appreciate it!
Thanks Jon
The clipboard class doesn't work. I can only assume this is because the content is running in a MTU state, the clipboard function must be run in a STA thread.
I did some research and found that the following code snippet should work, but doesn't in Test Studio...
//COM Voodoo IDataObject idat = null; Exception threadEx = null; Thread staThread = new Thread(new ParameterizedThreadStart( delegate { Console.WriteLine("Thread Started"); try { Console.WriteLine("Grabbing IdataObj"); idat = Clipboard.GetDataObject(); } catch (Exception ex) { Console.WriteLine("Exception caught"); threadEx = ex; } })); staThread.SetApartmentState(ApartmentState.STA); Console.WriteLine("Starting Thread"); Console.WriteLine("Apartment State: {0}", staThread.GetApartmentState().ToString()); staThread.Start(); staThread.Join(); var content = idat.GetData(DataFormats.Text); Console.WriteLine("Clipboard contents: {0}", content); Console.WriteLine("Press Any Key..."); Console.ReadKey(false);If you could take another look at this I would greatly appreciate it!
Thanks Jon
0
Accepted
Hello Jon,
Kind regards,
Anthony
the Telerik team
The following code works in our testing:
public string ClipboardMethod(){ string content = Clipboard.GetText(); return content;} [CodedStep(@"New Coded Step")]public void ClipboardTest_CodedStep(){ string content = string.Empty; var thread = new Thread(obj => { content = this.ClipboardMethod(); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); Log.WriteLine(content);}Kind regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
Jon
Top achievements
Rank 1
answered on 14 Aug 2012, 04:01 PM
Thanks Anthony that worked.
Cheers
Jon
Cheers
Jon