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

The 'value' of 'getPasteboard' is always empty #330

Closed
electricbubble opened this issue May 7, 2020 · 11 comments
Closed

The 'value' of 'getPasteboard' is always empty #330

electricbubble opened this issue May 7, 2020 · 11 comments

Comments

@electricbubble
Copy link

Method: POST
URL: http://localhost:8100/session/885C63E2-6F66-4DB8-921B-72B34D254099/wda/setPasteboard
Body: {"content":"SGkgYWdhaW4=","contentType":"plaintext"}

Method: POST
URL: http://localhost:8100/session/885C63E2-6F66-4DB8-921B-72B34D254099/wda/getPasteboard
Body: {"contentType":"plaintext"}
+ (NSData *)dataForType:(NSString *)type error:(NSError **)error
{
  UIPasteboard *pb = UIPasteboard.generalPasteboard;
  NSLog(@"### %@", pb.hasStrings ? @"YES" : @"NO");
  NSLog(@"### %@", pb.hasImages ? @"YES" : @"NO");
  NSLog(@"### %@", pb.hasURLs ? @"YES" : @"NO");
  if ([type.lowercaseString isEqualToString:@"plaintext"]) {
    if (pb.hasStrings) {
      return [[pb.strings componentsJoinedByString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding];
    }
  } else if ([type.lowercaseString isEqualToString:@"image"]) {
    if (pb.hasImages) {
      return UIImagePNGRepresentation((UIImage *)pb.image);
    }
  } else if ([type.lowercaseString isEqualToString:@"url"]) {
    if (pb.hasURLs) {
      NSMutableArray<NSString *> *urls = [NSMutableArray array];
      for (NSURL *url in pb.URLs) {
        if (nil != url.absoluteString) {
          [urls addObject:(id)url.absoluteString];
        }
      }
      return [[urls componentsJoinedByString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding];
    }
  } else {
    NSString *description = [NSString stringWithFormat:@"Unsupported content type: %@", type];
    if (error) {
      *error = [[FBErrorBuilder.builder withDescription:description] build];
    }
    return nil;
  }
  return [@"" dataUsingEncoding:NSUTF8StringEncoding];
}
2020-05-07 09:42:10.674052+0800 WebDriverAgentRunner-Runner[2168:590313] Getting the most recent active application (out of 1 total items)
    t =    17.33s Find the Application 'com.apple.mobilenotes'
    t =    17.33s     Requesting snapshot of accessibility hierarchy for app with pid 2133
2020-05-07 09:42:10.844680+0800 WebDriverAgentRunner-Runner[2168:590313] Returning local object of class NSString
2020-05-07 09:42:10.866392+0800 WebDriverAgentRunner-Runner[2168:590313] ### NO
2020-05-07 09:42:10.867659+0800 WebDriverAgentRunner-Runner[2168:590313] ### NO
2020-05-07 09:42:10.868586+0800 WebDriverAgentRunner-Runner[2168:590313] ### NO

I don't understand, is it a problem with my iOS device and system?

- Version
iPhone 6s 11.4.1
iPhone X 13.4.1
Xcode 11.4.1
@KazuCocoa
Copy link
Member

Did you use it on simulators?
https://appium.io/docs/en/writing-running-appium/ios/ios-xctest-pasteboard/index.html#mobile-getpasteboard

Perhaps, you can get/set the value if WDA was foreground (I haven't checked it, but we expected this works on simulators mainly)
appium/appium#11610

@electricbubble
Copy link
Author

I haven't tried it on the simulator.

You're right, when WDA is foreground, I can get the content.

Thank you very much for your reply 🥳

@George-BC
Copy link

Did you use it on simulators?
https://appium.io/docs/en/writing-running-appium/ios/ios-xctest-pasteboard/index.html#mobile-getpasteboard

Perhaps, you can get/set the value if WDA was foreground (I haven't checked it, but we expected this works on simulators mainly)
appium/appium#11610

Is this still accurate? I have tried both Activate App and Background App, clipboard still returns nothing.

@KazuCocoa
Copy link
Member

I think so.
I quickly checked on my env, 14.2 x iPhone SE 2nd Gen x Xcode 12.1 combination. It worked when WDA was foreground.

Afaik, if you enabled clipboard sync between other devices (Handoff feature), it could affect when you copy something on other devices.
https://apple.stackexchange.com/questions/253109/how-can-i-disable-universal-clipboard-on-macos-and-ios

@George-BC
Copy link

George-BC commented Nov 13, 2020

I think so.
I quickly checked on my env, 14.2 x iPhone SE 2nd Gen x Xcode 12.1 combination. It worked when WDA was foreground.

Afaik, if you enabled clipboard sync between other devices (Handoff feature), it could affect when you copy something on other devices.
https://apple.stackexchange.com/questions/253109/how-can-i-disable-universal-clipboard-on-macos-and-ios

Could you please share a code sample? I don't understand why something like this doesn't work:

async getClipboard() {
       try {
           const backgroundApp = this.driver.backgroundApp(10);
           while (backgroundApp) {
               const clipboard = await this.driver.getClipboard();
               console.log(clipboard);
               let buff = new Buffer(clipboard, 'base64');
               return buff.toString('ascii');
           }
       } catch (error) {
           assert.fail("Unable to get clipboard");
       }
   }

Switching to Settings doesn't work either. Clipboard will still be empty or undefined.

@KazuCocoa
Copy link
Member

KazuCocoa commented Nov 13, 2020

You should bring WDA to your foreground. It looks like you brought your test app to the background, but you did not bring WDA to the foreground.

Instead of this.driver.backgroundApp(10);, you should do like below addressed in http://appium.io/docs/en/commands/device/clipboard/get-clipboard/#description

@driver.activate_app 'com.example.WebDriverAgentRunner'  # here should be your proper WDA bundle id
@driver.get_clipboard

@George-BC
Copy link

Oh, thanks! I'm using WebDriverIO, will investigate.

@George-BC
Copy link

Is this an Appium issue? None of these work, first line timeout, others just fail immediately:
await this.driver.activateApp(undefined, 'com.facebook.WebDriverAgentRunner');
await this.driver.activateApp(null, 'com.facebook.WebDriverAgentRunner');
await this.driver.activateApp( 'com.facebook.WebDriverAgentRunner');

Bundle ID appears correct based on start of Appium logs

[2020-11-16 13:59:49:293 - [debug] [WD Proxy] Got response with status 200: {
2020-11-16 13:59:49:293 - [debug] [WD Proxy]   "value" : {
2020-11-16 13:59:49:293 - [debug] [WD Proxy]     "message" : "WebDriverAgent is ready to accept commands",
2020-11-16 13:59:49:293 - [debug] [WD Proxy]     "state" : "success",
2020-11-16 13:59:49:293 - [debug] [WD Proxy]     "os" : {
2020-11-16 13:59:49:293 - [debug] [WD Proxy]       "name" : "iOS",
2020-11-16 13:59:49:293 - [debug] [WD Proxy]       "version" : "13.3",
2020-11-16 13:59:49:293 - [debug] [WD Proxy]       "sdkVersion" : "12.0"
2020-11-16 13:59:49:293 - [debug] [WD Proxy]     },
2020-11-16 13:59:49:293 - [debug] [WD Proxy]     "ios" : {
2020-11-16 13:59:49:293 - [debug] [WD Proxy]       "simulatorVersion" : "13.3",
2020-11-16 13:59:49:293 - [debug] [WD Proxy]       "ip" : "192.168.11.159"
2020-11-16 13:59:49:293 - [debug] [WD Proxy]     },
2020-11-16 13:59:49:293 - [debug] [WD Proxy]     "ready" : true,
2020-11-16 13:59:49:293 - [debug] [WD Proxy]     "build" : {
2020-11-16 13:59:49:294 - [debug] [WD Proxy]       "time" : "Oct 19 2020 15:53:00",
2020-11-16 13:59:49:294 - [debug] [WD Proxy]       "productBundleIdentifier" : "com.facebook.WebDriverAgentRunner"
2020-11-16 13:59:49:294 - [debug] [WD Proxy]     }
2020-11-16 13:59:49:294 - [debug] [WD Proxy]   },](url)

@KazuCocoa
Copy link
Member

The productBundleIdentifier depends on how you set the bundle id. It refers to updatedWDABundleId capability or the default bundle id (com.facebook.WebDriverAgentRunner). If you built/installed the WDA without updatedWDABundleId capability, then it might be the default value. Or if you use Xcode 11 or newer, probably it has .xctrunner suffix like com.facebook.WebDriverAgentRunner.xctrunner. Xcode 11+ do like this change automatically in some cases outside of Appium.

If you manually have changed the bundle id, you should set it as you did.

@George-BC
Copy link

This is on BrowserStack, I don't have to interact with WebDriverAgent, its set up automatically. I tried updatedWDABundle capability earlier also, setting a custom name and had same result as above.

@KazuCocoa
Copy link
Member

Got it. Then, please ask their support team. I guess they have their own rule.
await this.driver.activateApp( 'com.facebook.WebDriverAgentRunner'); syntax seems good, but the bundle id depends on their environment.

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

No branches or pull requests

3 participants