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

fix: clipboard get/set contentType #478

Merged
merged 11 commits into from
Aug 14, 2019
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.appium.espressoserver.lib.handlers

import android.app.Instrumentation
import android.util.Base64

import java.nio.charset.StandardCharsets
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package io.appium.espressoserver.lib.model

import com.google.gson.annotations.SerializedName

import java.util.Arrays
import io.appium.espressoserver.lib.handlers.exceptions.InvalidArgumentException

enum class ClipboardDataType {
@SerializedName("PLAINTEXT")
PLAINTEXT;


companion object {

fun supportedDataTypes(): String {
return Arrays.toString(values())
fun invalidClipboardDataType(contentType: String?) : InvalidArgumentException {
return InvalidArgumentException(
"Only case insensitive ${values().map { it.toString() }} content types are supported. " +
"'$contentType' is given instead"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@

package io.appium.espressoserver.lib.model

import com.google.gson.annotations.SerializedName

data class GetClipboardParams(
val contentType: ClipboardDataType = ClipboardDataType.PLAINTEXT
) : AppiumParams()
@SerializedName("contentType")
private val _contentType: String?
) : AppiumParams() {
val contentType : ClipboardDataType
get() {
if (_contentType == null) return ClipboardDataType.PLAINTEXT

return when (_contentType.toUpperCase()) {
ClipboardDataType.PLAINTEXT.name ->
ClipboardDataType.PLAINTEXT
else ->
throw ClipboardDataType.invalidClipboardDataType(_contentType)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,23 @@

package io.appium.espressoserver.lib.model

import com.google.gson.annotations.SerializedName

data class SetClipboardParams(
val contentType: ClipboardDataType = ClipboardDataType.PLAINTEXT,
@SerializedName("contentType")
private val _contentType: String?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what the point in having the underscore in the property name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid to conflict with val contentType : ClipboardDataType in line 26

val content: String? = null,
val label: String? = null
) : AppiumParams()
) : AppiumParams() {
val contentType : ClipboardDataType
get() {
if (_contentType == null) return ClipboardDataType.PLAINTEXT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move the getter to a shared method to avoid duplication?


return when (_contentType.toUpperCase()) {
ClipboardDataType.PLAINTEXT.name ->
ClipboardDataType.PLAINTEXT
else ->
throw ClipboardDataType.invalidClipboardDataType(_contentType)
}
}
}
29 changes: 29 additions & 0 deletions test/functional/commands/clipboard-e2e-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { initSession, deleteSession, MOCHA_TIMEOUT } from '../helpers/session';
import { APIDEMO_CAPS } from '../desired';


chai.should();
chai.use(chaiAsPromised);


describe('clipboard', function () {
this.timeout(MOCHA_TIMEOUT);

let driver;
before(async function () {
driver = await initSession(APIDEMO_CAPS);
});
after(async function () {
await deleteSession();
});

it('should set and get clipboard', async function () {
await driver.setClipboard(new Buffer.from('Hello').toString('base64'), 'plaintext');
// 'SGVsbG8=' is 'Hello' in base 64 encoding with a new line.
const text = await driver.getClipboard('PLAINTEXT');
text.should.eql('SGVsbG8=\n');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour, '\n', does not change from UIA2

(new Buffer('SGVsbG8=\n', 'base64').toString()).should.eql('Hello');
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note.
Expects 'SGVsbG8=' instead of Hello

});