New to Telerik Test Studio? Download 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:

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