Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: SetClipboardText Doesn't work correctly #916

Closed
unalman opened this issue Feb 28, 2025 · 36 comments · Fixed by #920
Closed

[Bug]: SetClipboardText Doesn't work correctly #916

unalman opened this issue Feb 28, 2025 · 36 comments · Fixed by #920

Comments

@unalman
Copy link

unalman commented Feb 28, 2025

I tried SetClipboardText() method but i got this error.
OpenQA.Selenium.WebDriverArgumentException: 'Only '[PLAINTEXT]' content types are supported. 'plaintext' is given instead'

Then i created custom method for setclipboard. And it work.

 public static void SetClipboardTextCustom(this DeviceManager deviceManager, string textContent, string label)
 {
     // Clipboard'a metin ekle
     deviceManager.Driver.ExecuteScript("mobile: setClipboard", new Dictionary<string, object>
     {
         { "content", textContent },  
         { "label", label },        
         { "type", "PLAINTEXT" }      
     });
 }

i guess the problem here is ToLower()

public static string SetClipboardText(IExecuteMethod executeMethod, string textContent, string label)
        {
            if (textContent == null)
            {
                throw new ArgumentException($"{nameof(textContent)} cannot be null");
            }

            var encodedStringContentBytes = Encoding.UTF8.GetBytes(textContent);

            return (string) executeMethod.Execute(AppiumDriverCommand.SetClipboard,
                PrepareArguments(new[] {"content", "contentType", "label"},
                    new object[]
                    {
                        Convert.ToBase64String(encodedStringContentBytes),
                        ClipboardContentType.PlainText.ToString().ToLower(), label
                    })).Value;
        }

https://github.com/appium/dotnet-client/blob/main/src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs#L25

@Dor-bl
Copy link
Collaborator

Dor-bl commented Feb 28, 2025

Hi,
Please add the following details to the issue:
platform (Android /iOS)
Appium dotnet client version
appium server version

What values did you passed to the method?

@KazuCocoa
Copy link
Member

The endpoint https://github.com/appium/WebDriverAgent/blob/d7cff1a389586f3f492cfd789175e21d838f21da/WebDriverAgentLib/Utilities/FBPasteboard.m#L29 conver the content type as lower case. I assume it might not be content type related

@mykola-mokhnach
Copy link

UIA2 driver does not normalise the characters case

@KazuCocoa
Copy link
Member

KazuCocoa commented Mar 2, 2025

toUpperCase() https://github.com/appium/appium-uiautomator2-server/blob/master/app/src/main/java/io/appium/uiautomator2/handler/SetClipboard.java#L53 ? (so, client's lower/upper might not be related) Ruby and Python clients sent with plaintext. They worked to set/get clipboard contents on my local simulator/emulator with latest uia2/xcuitest/espresso.

I think attaching the appium server log also might help.

e.g.

[06065348][HTTP] <-- POST /session/06065348-7843-43d9-be3f-138cb04dcdea/appium/device/get_clipboard 200 1161 ms - 12
[06065348][HTTP] --> POST /session/06065348-7843-43d9-be3f-138cb04dcdea/appium/device/set_clipboard {"contentType":"plaintext","content":"aGFwcHkgdGVzdGluZw==","label":"Note"}
[06065348][AndroidUiautomator2Driver@40db] Driver proxy active, passing request on via HTTP proxy
[06065348][AndroidUiautomator2Driver@40db] Matched '/session/06065348-7843-43d9-be3f-138cb04dcdea/appium/device/set_clipboard' to command name 'setClipboard'
[06065348][AndroidUiautomator2Driver@40db] Proxying [POST /session/06065348-7843-43d9-be3f-138cb04dcdea/appium/device/set_clipboard] to [POST http://127.0.0.1:8200/session/2367214d-4947-4247-8fd9-1a92265eb8d5/appium/device/set_clipboard] with body: {"contentType":"plaintext","content":"aGFwcHkgdGVzdGluZw==","label":"Note"}
[06065348][AndroidUiautomator2Driver@40db] Got response with status 200: {"sessionId":"2367214d-4947-4247-8fd9-1a92265eb8d5","value":null}
[06065348][AndroidUiautomator2Driver@40db] Replacing sessionId 2367214d-4947-4247-8fd9-1a92265eb8d5 with 06065348-7843-43d9-be3f-138cb04dcdea
[06065348][HTTP] <-- POST /session/06065348-7843-43d9-be3f-138cb04dcdea/appium/device/set_clipboard 200 132 ms - 65

[06065348][HTTP] --> POST /session/06065348-7843-43d9-be3f-138cb04dcdea/appium/device/get_clipboard {"contentType":"plaintext"}
[06065348][AndroidUiautomator2Driver@40db] Calling AppiumDriver.getClipboard() with args: ["plaintext","06065348-7843-43d9-be3f-138cb04dcdea"]
[06065348][SettingsApp] Getting the clipboard content
[06065348][ADB] Running '/Users/kazu/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys activity services io.appium.settings'
[06065348][ADB] Running '/Users/kazu/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell settings get secure default_input_method'
[06065348][ADB] Running '/Users/kazu/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell ime enable io.appium.settings/.AppiumIME'
[06065348][ADB] Running '/Users/kazu/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell ime set io.appium.settings/.AppiumIME'
[06065348][ADB] Running '/Users/kazu/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am broadcast -n io.appium.settings/.receivers.ClipboardReceiver -a io.appium.settings.clipboard.get'
[06065348][ADB] Running '/Users/kazu/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell ime set com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME'
[06065348][AndroidUiautomator2Driver@40db] Responding to client with driver.getClipboard() result: "aGFwcHkgdGVzdGluZw=="
[06065348][HTTP] <-- POST /session/06065348-7843-43d9-be3f-138cb04dcdea/appium/device/get_clipboard 200 998 ms - 32

@unalman
Copy link
Author

unalman commented Mar 2, 2025

Hi, Please add the following details to the issue: platform (Android /iOS) Appium dotnet client version appium server version

What values did you passed to the method?

-Android
-Appium.WebDriver 6.0.0
-Appium server version 2.13.1

What values did you passed to the method?
Actually i tried many things. when i wrote something like this.

deviceManager.Driver.SetClipboardText("hello", "label");

i got this error

OpenQA.Selenium.WebDriverArgumentException: 'Only '[PLAINTEXT]' content types are supported. 'plaintext' is given instead'

appium server log

[6aaab50b][HTTP] Request idempotency key: 1516b066-1e0d-49e2-b762-e0e38b12983b
[6aaab50b][HTTP] --> POST /session/6aaab50b-a74a-408c-b936-e4b191b8ea33/appium/device/set_clipboard {"content":"aGVsbG8=","contentType":"plaintext","label":"label"}
[6aaab50b][AndroidUiautomator2Driver@13d6] Command 'setClipboard' has been deprecated and will be removed in a future version of Appium or your driver/plugin. Please use a different method or contact the driver/plugin author to add explicit support for the command before it is removed
[6aaab50b][AndroidUiautomator2Driver@13d6] Driver proxy active, passing request on via HTTP proxy
[6aaab50b][AndroidUiautomator2Driver@13d6] Matched '/session/6aaab50b-a74a-408c-b936-e4b191b8ea33/appium/device/set_clipboard' to command name 'setClipboard'
[6aaab50b][AndroidUiautomator2Driver@13d6] Proxying [POST /session/6aaab50b-a74a-408c-b936-e4b191b8ea33/appium/device/set_clipboard] to [POST http://127.0.0.1:8200/session/03b48325-7c93-47a1-a26b-ac2bdf41192c/appium/device/set_clipboard] with body: {"content":"aGVsbG8=","contentType":"plaintext","label":"label"}
[6aaab50b][AndroidUiautomator2Driver@13d6] Got response with status 400: {"sessionId":"03b48325-7c93-47a1-a26b-ac2bdf41192c","value":{"error":"invalid argument","message":"Only '[PLAINTEXT]' content types are supported. 'plaintext' is given instead","stacktrace":"io.appium.uiautomator2.common.exceptions.InvalidArgumentException: Only '[PLAINTEXT]' content types are supported. 'plaintext' is given instead\n\tat io.appium.uiautomator2.handler.SetClipboard.safeHandle(SetClipboard.java:58)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:259)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:253)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chan...
[6aaab50b][W3C] Matched W3C error code 'invalid argument' to InvalidArgumentError
[6aaab50b][HTTP] <-- POST /session/6aaab50b-a74a-408c-b936-e4b191b8ea33/appium/device/set_clipboard 400 22 ms - 3777

@KazuCocoa
Copy link
Member

Could you share the entire appium server as well to see the dependent version etc as GIST?

@unalman
Copy link
Author

unalman commented Mar 2, 2025

@KazuCocoa
Copy link
Member

KazuCocoa commented Mar 2, 2025

Hm,

[Test]
public void WhenSetClipboardContentTypeIsPlainTextGetClipboardShouldReturnEncodedBase64String()
{
_driver.SetClipboard(ClipboardContentType.PlainText, ClipboardTestString);
Assert.That(() => Regex.IsMatch(_driver.GetClipboard(ClipboardContentType.PlainText), Base64RegexPattern, RegexOptions.Multiline),
Is.True);
}
[Test]
public void WhenClipboardContentTypeIsPlainTextWithLabelGetClipboardTextShouldReturnActualText()
{
_driver.SetClipboardText(ClipboardTestString, label:"testing");
Assert.That(() => _driver.GetClipboardText(), Does.Match(ClipboardTestString));
}
worked without such an exception.

[74da8c93][HTTP] --> POST /session/74da8c93-2a52-4aa7-80ee-c41d26b2915a/appium/device/set_clipboard {"content":"Hello Clipboard","contentType":"plaintext"}
[74da8c93][AndroidUiautomator2Driver@1cea] Driver proxy active, passing request on via HTTP proxy
[74da8c93][AndroidUiautomator2Driver@1cea] Matched '/session/74da8c93-2a52-4aa7-80ee-c41d26b2915a/appium/device/set_clipboard' to command name 'setClipboard'
[74da8c93][AndroidUiautomator2Driver@1cea] Proxying [POST /session/74da8c93-2a52-4aa7-80ee-c41d26b2915a/appium/device/set_clipboard] to [POST http://127.0.0.1:8200/session/709c91e5-76d6-42c7-ad02-3f5d41bd9c73/appium/device/set_clipboard] with body: {"content":"Hello Clipboard","contentType":"plaintext"}
[74da8c93][AndroidUiautomator2Driver@1cea] Got response with status 200: {"sessionId":"709c91e5-76d6-42c7-ad02-3f5d41bd9c73","value":null}
[74da8c93][AndroidUiautomator2Driver@1cea] Replacing sessionId 709c91e5-76d6-42c7-ad02-3f5d41bd9c73 with 74da8c93-2a52-4aa7-80ee-c41d26b2915a
[74da8c93][HTTP] <-- POST /session/74da8c93-2a52-4aa7-80ee-c41d26b2915a/appium/device/set_clipboard 200 123 ms - 65
[74da8c93][HTTP] Request idempotency key: a116fc14-ee7d-4bf3-9c30-19c346fa22dd
[51e2d0a4][HTTP] --> POST /session/51e2d0a4-b19e-4915-bf92-dcb9e98186cd/appium/device/set_clipboard {"content":"SGVsbG8gQ2xpcGJvYXJk","contentType":"plaintext","label":"testing"}
[51e2d0a4][AndroidUiautomator2Driver@325e] Driver proxy active, passing request on via HTTP proxy
[51e2d0a4][AndroidUiautomator2Driver@325e] Matched '/session/51e2d0a4-b19e-4915-bf92-dcb9e98186cd/appium/device/set_clipboard' to command name 'setClipboard'
[51e2d0a4][AndroidUiautomator2Driver@325e] Proxying [POST /session/51e2d0a4-b19e-4915-bf92-dcb9e98186cd/appium/device/set_clipboard] to [POST http://127.0.0.1:8200/session/58e1b45c-d38c-4162-9a0c-186d49f85c45/appium/device/set_clipboard] with body: {"content":"SGVsbG8gQ2xpcGJvYXJk","contentType":"plaintext","label":"testing"}
[51e2d0a4][AndroidUiautomator2Driver@325e] Got response with status 200: {"sessionId":"58e1b45c-d38c-4162-9a0c-186d49f85c45","value":null}
[51e2d0a4][AndroidUiautomator2Driver@325e] Replacing sessionId 58e1b45c-d38c-4162-9a0c-186d49f85c45 with 51e2d0a4-b19e-4915-bf92-dcb9e98186cd
[51e2d0a4][HTTP] <-- POST /session/51e2d0a4-b19e-4915-bf92-dcb9e98186cd/appium/device/set_clipboard 200 186 ms - 65

The only thing I could think of is.... host machine? I used macOS, not Win. Other logs in the attached GIST looks good. I modified my local uia2 driver version also but mine worked with plaintext as current implementation.

Android SDK 29 emulator worked on my local as well.

https://dev.azure.com/AppiumCI/dotnet-client/_build/results?buildId=30011&view=results running on Win env also passed. hm..

@KazuCocoa
Copy link
Member

Could you run appium driver run uiautomator2 reset once and re-run the set clipboard once again?
Then, it would be appreciated if you share both logs, appium driver run uiautomator2 reset and the appium server log.

@Dor-bl
Copy link
Collaborator

Dor-bl commented Mar 3, 2025

@KazuCocoa, the build you provided isn't running the SetClipboardText, but I can confirm it does work on Win ENV

][HTTP] --> POST /session/c43e2ed5-e0e8-46ef-8fba-acbcbfa23ca7/appium/device/set_clipboard {"content":"aGVsbG8=","contentType":"plaintext","label":"label"}
[c43e2ed5][AndroidUiautomator2Driver@5b05] Command 'setClipboard' has been deprecated and will be removed in a future version of Appium or your driver/plugin. Please use a different method or contact the driver/plugin author to add explicit support for the command before it is removed

Regardless, I suggest @unalman update his Dotnet client to the latest version (7.1.0)

@Dor-bl
Copy link
Collaborator

Dor-bl commented Mar 3, 2025

Another question for @unalman. What is the type of deviceManager.Driver?

@unalman
Copy link
Author

unalman commented Mar 5, 2025

after this appium driver run uiautomator2 reset

https://gist.github.com/unalman/0cb337586e636d16cda5ccb117c42823

deviceManager.Driver is small a class.

   public class DeviceManager : IDisposable
   {
       private AndroidDriver _driver;

       public DeviceManager(string serial, string appiumHost, int implicitWaitSeconds, int commandTimeoutSeconds)
       {
           try
           {
               var serverUri = new Uri(appiumHost);
               var driverOptions = new AppiumOptions()
               {
                   AutomationName = AutomationName.AndroidUIAutomator2,
                   PlatformName = "Android",
                   DeviceName = "Android Device",
               };

               driverOptions.AddAdditionalAppiumOption("udid", serial);
               driverOptions.AddAdditionalAppiumOption("noReset", true);
               driverOptions.AddAdditionalAppiumOption("newCommandTimeout", 300);
               driverOptions.AddAdditionalAppiumOption("unicodeKeyboard", true);
               driverOptions.AddAdditionalAppiumOption("resetKeybord", true);

               _driver = new AndroidDriver(serverUri, driverOptions, TimeSpan.FromSeconds(commandTimeoutSeconds));
               _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(implicitWaitSeconds);
           }
           catch (Exception ex)
           {
               Console.WriteLine($"DeviceManager initialization failed: {ex.Message}");
               throw;
           }
       }

       public AndroidDriver Driver => _driver;

       public void Dispose()
       {
           if (_driver != null)
           {
               _driver.Quit();
               _driver.Dispose();
               _driver = null;
           }
       }

   }

I updated the latest version but it doesn't change anything.

@KazuCocoa
Copy link
Member

Thank you for the logs. I still couldn't reproduce this error with .net client and the same uia2 driver version against the endpoint, but actually your log still had the error...

Can you share the device logcat?

The adb logcat may have like below endpoint call:

03-05 00:26:36.025  7936  7964 I appium  : channel read: POST /session/87b62a93-9f2b-4af0-856d-7d86c51b6993/appium/device/set_clipboard
03-05 00:26:36.026  7936  7964 I appium  : SetClipboard command
03-05 00:26:36.031   552  2303 D androidtc: Initializing SystemTextClassifier, type = System
03-05 00:26:36.037   552  2303 E ClipboardService: Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
03-05 00:26:36.038  7936  7964 I appium  : AppiumResponse: {"sessionId":"87b62a93-9f2b-4af0-856d-7d86c51b6993","value":null}
03-05 00:26:36.126   552   696 E ClipboardService: Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
03-05 00:26:36.400   552   552 W Looper  : Slow dispatch took 224ms main h=android.os.Handler c=android.database.ContentObserver$$ExternalSyntheticLambda0@9c06581 m=0
03-05 00:26:36.407   552   552 W Looper  : Slow delivery took 224ms main h=android.os.Handler c=android.database.ContentObserver$$ExternalSyntheticLambda0@f0d3180 m=0
03-05 00:26:36.408   552   552 W Looper  : Drained
03-05 00:26:36.409  1552  1552 I UnicodeIME: onFinishInput:
03-05 00:26:36.434   552  2303 W InputManager-JNI: Input channel object '2c6733e InputMethod (client)' was disposed without first being removed with the input manager!
03-05 00:26:36.466   721   935 D EGL_emulation: app_time_stats: avg=13311.98ms min=13311.98ms max=13311.98ms count=1
03-05 00:26:36.495   210   210 I servicemanager: Notifying apexservice they have clients: 1
03-05 00:26:36.512  1552  1552 I AppiumIME: onStartInput
03-05 00:26:36.753  1552  1552 D ClipboardReceiver: Getting current clipboard content
03-05 00:26:36.797  1552  1552 I AppiumIME: onFinishInput
03-05 00:26:36.800   552  2424 W InputManager-JNI: Input channel object '7bda7b InputMethod (client)' was disposed without first being removed with the input manager!
03-05 00:26:36.836  1552  1552 I UnicodeIME: onStartInput

@Dor-bl
Copy link
Collaborator

Dor-bl commented Mar 5, 2025

@KazuCocoa Could it be related to the below?

     driverOptions.AddAdditionalAppiumOption("unicodeKeyboard", true);
     driverOptions.AddAdditionalAppiumOption("resetKeybord", true);

@KazuCocoa
Copy link
Member

Not really. They usually don't affect this set clipboard endpoint. I added these caps also to have the same capabilities, but no error occurred.

@unalman
Copy link
Author

unalman commented Mar 5, 2025

@KazuCocoa Could it be related to the below?

     driverOptions.AddAdditionalAppiumOption("unicodeKeyboard", true);
     driverOptions.AddAdditionalAppiumOption("resetKeybord", true);

As I said before, this method work perfectly but SetClipboardText() method doesn't work

 public static void SetClipboardTextCustom(this DeviceManager deviceManager, string textContent, string label)
 {
     // Clipboard'a metin ekle
     deviceManager.Driver.ExecuteScript("mobile: setClipboard", new Dictionary<string, object>
     {
         { "content", textContent },  
         { "label", label },        
         { "type", "PLAINTEXT" }      
     });
 }

@KazuCocoa
Copy link
Member

KazuCocoa commented Mar 5, 2025

Yes, so I was wondering why only your environment had an issue with SetClipboardText which sent "type", "plaintext" because uia2 server handles such a type with toUpperCase on their side. (#916 (comment))

driver.SetClipboardText("hello", "label");

@KazuCocoa
Copy link
Member

KazuCocoa commented Mar 5, 2025

I don't mind sending PLAINTEXT in this .net client if it works for ios as well (or only Android). I just wanted to clarify the reason what caused the error since this repo's CI also didn't have this error with:

[Test]
public void WhenClipboardContentTypeIsPlainTextWithLabelGetClipboardTextShouldReturnActualText()
{
_driver.SetClipboardText(ClipboardTestString, label:"testing");
Assert.That(() => _driver.GetClipboardText(), Does.Match(ClipboardTestString));
}

@unalman
Copy link
Author

unalman commented Mar 5, 2025

I couldn't understand either.

@unalman
Copy link
Author

unalman commented Mar 5, 2025

@KazuCocoa
Copy link
Member

Would #920 help? It sends "contentType":"PLAINTEXT", so if this issue was uia2 server's model.contentType.toUpperCase() (#916 (comment)), this should help. Also, it is appreciatd to check if the same error occurs with GetClipboardText also since the method also does the same thing in the uia2 server side. .net client sends the same contentType.

@unalman
Copy link
Author

unalman commented Mar 6, 2025

Thanks for your help. Do I have to wait for your next release to test it?

@KazuCocoa
Copy link
Member

I don't know well about .net client's deps management, but if your project could refer to the GitHub branch, you can test that out. It is appreciated to do it if possible since this occurs only your environment for now 🙏

@Dor-bl
Copy link
Collaborator

Dor-bl commented Mar 7, 2025

@unalman, would you prefer I send you the .nupkg that includes @KazuCocoa Fix?
You can join our Slack channel, and I will share it there.

@unalman
Copy link
Author

unalman commented Mar 8, 2025

sure. can u invite mi to slack channel

mail: [email protected]

@unalman
Copy link
Author

unalman commented Mar 11, 2025

@Dor-bl sent me nuget package. But i got new error. but i understand why i got this. In Turkish, the capital letter "i" is "İ" i guess thats why toUpper() work differently.

OpenQA.Selenium.WebDriverArgumentException: 'Only '[PLAINTEXT]' content types are supported. 'PLAİNTEXT' is given instead'

appium log

[598a8ea1][AndroidUiautomator2Driver@0806] Proxying [POST /session/598a8ea1-e533-49c5-809e-1c959a933f5e/appium/device/set_clipboard] to [POST http://127.0.0.1:8200/session/a24e53a8-0834-4bde-b324-de25ec87ad45/appium/device/set_clipboard] with body: {"content":"aGVsbG8=","contentType":"PLAİNTEXT","label":"label"}
[598a8ea1][AndroidUiautomator2Driver@0806] Got response with status 400: {"sessionId":"a24e53a8-0834-4bde-b324-de25ec87ad45","value":{"error":"invalid argument","message":"Only '[PLAINTEXT]' content types are supported. 'PLAİNTEXT' is given instead","stacktrace":"io.appium.uiautomator2.common.exceptions.InvalidArgumentException: Only '[PLAINTEXT]' content types are supported. 'PLAİNTEXT' is given instead\n\tat io.appium.uiautomator2.handler.SetClipboard.safeHandle(SetClipboard.java:58)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:259)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:253)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chan...
[598a8ea1][W3C] Matched W3C error code 'invalid argument' to InvalidArgumentError
[598a8ea1][HTTP] <-- POST /session/598a8ea1-e533-49c5-809e-1c959a933f5e/appium/device/set_clipboard 400 21 ms - 3

full appium log

https://gist.github.com/unalman/2b9dbdba1619b5f2a7644ebda03c080a

You can test like that

   var text = "i";
   Console.WriteLine(text.ToUpper(new CultureInfo("en-US", false))); // result: I
   Console.WriteLine(text.ToUpper(new CultureInfo("tr-TR", false))); // result: İ

@KazuCocoa
Copy link
Member

KazuCocoa commented Mar 11, 2025

It was helpful. So, we should use ToLowerInvariant / ToUpperInvariant instead of ToLower / ToUpper to avoid host language config. I didn't know of this .net behavior...

@KazuCocoa
Copy link
Member

I made an update in #920

@unalman
Copy link
Author

unalman commented Mar 11, 2025

Yes, this seems like it could solve our problem. @Dor-bl could you send me new version again?

@Dor-bl
Copy link
Collaborator

Dor-bl commented Mar 11, 2025

@unalman Sent on Slack

@unalman
Copy link
Author

unalman commented Mar 12, 2025

Unfortunately I got again 'PLAİNTEXT' error. Could there be a ToUpper() method running somewhere else?

[83d41add][AndroidUiautomator2Driver@02ba] W3C timeout argument: {"implicit":15000}}
[83d41add][AndroidUiautomator2Driver@02ba] Set implicit wait to 15000ms
[83d41add][AndroidUiautomator2Driver@02ba] Responding to client with driver.timeouts() result: null
[83d41add][HTTP] <-- POST /session/83d41add-4a1a-46aa-ac79-deed974f6f15/timeouts 200 3 ms - 14
[83d41add][HTTP] Request idempotency key: 47a449c8-86e8-488c-980d-474a4dc95578
[83d41add][HTTP] --> POST /session/83d41add-4a1a-46aa-ac79-deed974f6f15/appium/device/set_clipboard {"content":"aGVsbG8=","contentType":"PLAİNTEXT","label":"label"}
[83d41add][AndroidUiautomator2Driver@02ba] Command 'setClipboard' has been deprecated and will be removed in a future version of Appium or your driver/plugin. Please use a different method or contact the driver/plugin author to add explicit support for the command before it is removed
[83d41add][AndroidUiautomator2Driver@02ba] Driver proxy active, passing request on via HTTP proxy
[83d41add][AndroidUiautomator2Driver@02ba] Matched '/session/83d41add-4a1a-46aa-ac79-deed974f6f15/appium/device/set_clipboard' to command name 'setClipboard'
[83d41add][AndroidUiautomator2Driver@02ba] Proxying [POST /session/83d41add-4a1a-46aa-ac79-deed974f6f15/appium/device/set_clipboard] to [POST http://127.0.0.1:8200/session/c161e4bd-813c-49f3-950c-a21c7438400f/appium/device/set_clipboard] with body: {"content":"aGVsbG8=","contentType":"PLAİNTEXT","label":"label"}
[83d41add][AndroidUiautomator2Driver@02ba] Got response with status 400: {"sessionId":"c161e4bd-813c-49f3-950c-a21c7438400f","value":{"error":"invalid argument","message":"Only '[PLAINTEXT]' content types are supported. 'PLAİNTEXT' is given instead","stacktrace":"io.appium.uiautomator2.common.exceptions.InvalidArgumentException: Only '[PLAINTEXT]' content types are supported. 'PLAİNTEXT' is given instead\n\tat io.appium.uiautomator2.handler.SetClipboard.safeHandle(SetClipboard.java:58)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:259)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:253)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chan...
[83d41add][W3C] Matched W3C error code 'invalid argument' to InvalidArgumentError
[83d41add][HTTP] <-- POST /session/83d41add-4a1a-46aa-ac79-deed974f6f15/appium/device/set_clipboard 400 27 ms - 3779

Appium logs

https://gist.github.com/unalman/045c407eeda00fc7745c9468d1b6983e

@Dor-bl Dor-bl added the Bug label Mar 12, 2025
@Dor-bl
Copy link
Collaborator

Dor-bl commented Mar 12, 2025

@KazuCocoa, Maybe we should just consider moving this method to the mobile extension. mobile: setClipboard

@unalman
Copy link
Author

unalman commented Mar 12, 2025

Maybe ToUpperInvariant() would be a better solution here. If the letters are enlarged correctly here, other problems may not occur.

75f7f59

@KazuCocoa
Copy link
Member

No ToUpper call with the latest #920 with my latest comment #916 (comment). The only place is below, which will be fixed in #921

kazu $ git grep 'ToUpper'
src/Appium.Net/Appium/ScreenOrientationExtensions.cs:            orientation.ToString().ToUpper();

Maybe we should just consider moving this method to the mobile extension.

It's also good after the PR merge, which fixes the current main. Both formats in terms of contentType are the same.

@Dor-bl
Copy link
Collaborator

Dor-bl commented Mar 12, 2025

So what's the call here @KazuCocoa ?
Should we merge, or you want to try another fix before?

@KazuCocoa
Copy link
Member

I'm good with #920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants