public static void SetClipboard(IExecuteMethod executeMethod, ClipboardContentType clipboardContentType,
                                        string base64Content)
        {
            switch (clipboardContentType)
            {
            case ClipboardContentType.Image:
            case ClipboardContentType.Url:
                if (executeMethod.GetType().GetGenericTypeDefinition() == typeof(AndroidDriver <>))
                {
                    throw new NotImplementedException(
                              $"Android only supports contentType: {nameof(ClipboardContentType.PlainText)}");
                }

                executeMethod.Execute(AppiumDriverCommand.SetClipboard,
                                      PrepareArguments(new[] { "content", "contentType", "label" },
                                                       new object[] { base64Content, clipboardContentType.ToString().ToLower(), null }));
                break;

            default:
                executeMethod.Execute(AppiumDriverCommand.SetClipboard,
                                      PrepareArguments(new[] { "content", "contentType", "label" },
                                                       new object[] { base64Content, clipboardContentType.ToString().ToLower(), null }));
                break;
            }
        }
Ejemplo n.º 2
0
 public void Copy(ClipboardContentType type, object contents)
 {
     System.Windows.Forms.IDataObject data = new System.Windows.Forms.DataObject(this.GetDataFormatByContentType(type), contents);
     if (type == ClipboardContentType.FileDrop)
     {
         MemoryStream stream = new MemoryStream(4);
         byte[]       bytes  = new byte[] { 5, 0, 0, 0 };
         stream.Write(bytes, 0, bytes.Length);
         data.SetData("Preferred DropEffect", stream);
     }
     this.Contents = data;
 }
Ejemplo n.º 3
0
        private string GetDataFormatByContentType(ClipboardContentType type)
        {
            switch (type)
            {
            case ClipboardContentType.FileDrop:
                return(System.Windows.Forms.DataFormats.FileDrop);

            case ClipboardContentType.Text:
                return(System.Windows.Forms.DataFormats.Text);

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 4
0
        private async Task ProcessClipboardAsync(int retryCount = 2)
        {
            try
            {
                var content = Clipboard.GetContent();
                if (content.Contains(StandardDataFormats.Bitmap))
                {
                    currentContent = ClipboardContentType.Bitmap;

                    SetClipboardPreviewText("(image)");
                }
                else if ((content.Contains(StandardDataFormats.StorageItems)) && ((await content.GetStorageItemsAsync()).FirstOrDefault(x => x is StorageFile) != null))
                {
                    currentContent = ClipboardContentType.StorageItem;

                    SetClipboardPreviewText("(file)");
                }
                else if (content.Contains(StandardDataFormats.Text))
                {
                    currentContent = ClipboardContentType.Text;
                    string text = await content.GetTextAsync();

                    SetClipboardPreviewText(text);
                }
                else
                {
                    //Unknown clipboard content.
                    SetClipboardPreviewText("");
                }
            }
            catch (Exception ex)
            {
                SetClipboardPreviewText("");
                Debug.WriteLine($"Failed to access clipboard: {ex.ToString()}");

                if (retryCount > 0)
                {
                    Debug.WriteLine("Will retry");
                    await Task.Delay(1000);
                    await ProcessClipboardAsync(retryCount - 1);
                }
            }
        }
Ejemplo n.º 5
0
        public static string GetClipboard(IExecuteMethod executeMethod, ClipboardContentType clipboardContentType)
        {
            switch (clipboardContentType)
            {
            case ClipboardContentType.Image:
            case ClipboardContentType.Url:
                if (executeMethod.GetType().GetGenericTypeDefinition() == typeof(AndroidDriver <>))
                {
                    throw new NotImplementedException($"Android only supports contentType: {nameof(ClipboardContentType.PlainText)}");
                }
                return((string)executeMethod.Execute(AppiumDriverCommand.GetClipboard,
                                                     PrepareArgument("contentType", clipboardContentType.ToString().ToLower())).Value);

            case ClipboardContentType.PlainText:
                return((string)executeMethod.Execute(AppiumDriverCommand.GetClipboard,
                                                     PrepareArgument("contentType", clipboardContentType.ToString().ToLower())).Value);

            default:
                return((string)executeMethod.Execute(AppiumDriverCommand.GetClipboard,
                                                     PrepareArgument("contentType", clipboardContentType.ToString().ToLower())).Value);
            }
        }
 /// <summary>
 /// Get the content of the clipboard.
 /// </summary>
 /// <param name="contentType"></param>
 /// <remarks>Android supports plaintext only</remarks>
 /// <returns>The content of the clipboard as base64-encoded string or an empty string if the clipboard is empty</returns>
 public string GetClipboard(ClipboardContentType contentType) => AppiumCommandExecutionHelper.GetClipboard(this, contentType);
 /// <summary>
 /// Sets the content to the clipboard
 /// </summary>
 /// <param name="contentType"></param>
 /// <param name="base64Content"></param>
 public void SetClipboard(ClipboardContentType contentType, string base64Content) => AppiumCommandExecutionHelper.SetClipboard(this, contentType, base64Content);
Ejemplo n.º 8
0
 private string GetDataFormatByContentType(ClipboardContentType type)
 {
     switch (type)
     {
         case ClipboardContentType.FileDrop:
             return System.Windows.Forms.DataFormats.FileDrop;
         case ClipboardContentType.Text:
             return System.Windows.Forms.DataFormats.Text;
         default:
             throw new NotSupportedException();
     }
 }
Ejemplo n.º 9
0
 public void Cut(ClipboardContentType type, object contents)
 {
     System.Windows.Forms.IDataObject data = new System.Windows.Forms.DataObject(this.GetDataFormatByContentType(type), contents);
     if (type == ClipboardContentType.FileDrop)
     {
         MemoryStream stream = new MemoryStream(4);
         byte[] bytes = new byte[] { 2, 0, 0, 0 };
         stream.Write(bytes, 0, bytes.Length);
         data.SetData("Preferred DropEffect", stream);
     }
     this.Contents = data;
 }
Ejemplo n.º 10
0
 public ClipboardContent(ClipboardContentType type, byte[] content)
 {
     Type    = type;
     Content = content;
     Files   = null;
 }