New to Telerik Test StudioStart a free 30-day trial

Log Clipboard Text

My test copies text into the Clipboard and I would like to log its content.

Solution

This is possible with a coded solution:

  1. Add an Assembly Reference to System.Windows.Forms.
  2. Add a coded step to the test after the step that populates the Clipboard.

Here is the full code-behind file, excluding the standard using/Imports statements and the Dynamic Pages Reference region:

C#
using System.Windows.Forms;
using System.Threading;
 
namespace TestProject8
{     
    public class ClipboardTest : BaseWebAiiTest
    {  
        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);
        }
    }
}
In this article
Solution
Not finding the help you need?
Contact Support