-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Changes from 10 commits
b2c903d
fa77844
f9cf571
7b0ecb5
fc9cf53
17cde48
d3fd61a
ff791f3
f0a6c15
1b63d7c
68756da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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?, | ||
val content: String? = null, | ||
val label: String? = null | ||
) : AppiumParams() | ||
) : AppiumParams() { | ||
val contentType : ClipboardDataType | ||
get() { | ||
if (_contentType == null) return ClipboardDataType.PLAINTEXT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
} | ||
} |
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note. |
||
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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