尝试构建一个在活动中使用 kotlin 协程的简单示例:
lifecycleScope.launch {
val result = httpGet("http://hmkcode-api.appspot.com/rest/api/hello/Android")
textView.setText(result)
}
Run Code Online (Sandbox Code Playgroud)
无法摆脱错误“未解析的引用生命周期范围”
gradle 文件的相关部分:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-rx2:1.3.2"
def androidArchVersion = '1.1.1'
implementation "android.arch.lifecycle:viewmodel:$androidArchVersion"
implementation "android.arch.lifecycle:livedata:$androidArchVersion"
annotationProcessor "android.arch.lifecycle:compiler:$androidArchVersion"
testImplementation "android.arch.core:core-testing:$androidArchVersion"
implementation "android.arch.lifecycle:extensions:$androidArchVersion"
}
kotlinOptions {
jvmTarget = '1.8'
apiVersion = '1.3'
languageVersion = '1.3'
}
Run Code Online (Sandbox Code Playgroud)
}
我有一个包含输入字段和其下方的按钮的网络视图(网络视图是第 3 方代码)当我在手机上打开视图时,只要在字段中插入数字,按钮就会更改颜色并启用。
输入字段是
<input type="tel" name="input" id="input" class="inputbox" autocomplete="off" placeholder="number" value="">
Run Code Online (Sandbox Code Playgroud)
当我使用 Espresso 运行自动测试时,我可以将文本放入字段中,但按钮未启用
onWebView().withElement(findElement(Locator.ID, "input"))
.perform(clearElement())
.perform(DriverAtoms.webKeys("22222222"))
.perform(webClick())
.withElement(findElement(Locator.ID, "continueButton"))
.perform(webClick());
Run Code Online (Sandbox Code Playgroud)
Firefox 检查器显示 onChange 事件有一个事件侦听器,我认为其侦听器是这样的:
function(e) {
e.persist();
var t = /^[0-9\b]+$/;
d((function(a) {
return Object(c.a)(Object(c.a)({}, a), {}, Object(M.a)({}, e.target.name, t.test(e.target.value) ? e.target.value : e.target.value.replace(/[^0-9]/g, "")))
})), e.target.value.replace(/[^0-9]/g, "").length > 0 ? (j(!1), b("primary"), k(""), R("")) : (b("primary disabled"), k("hidden"), R("paddingTop20"))
}
Run Code Online (Sandbox Code Playgroud)
所以我尝试触发 onchange 但没有运气:
onWebView().forceJavascriptEnabled().withElement(findElement(Locator.ID, "input"))
.perform(clearElement())
.perform(webClick())
.perform(DriverAtoms.webKeys("22222222"))
.perform(webClick())
.perform(SimpleAtom("function(elem) {\n" +
"var e = document.createEvent('Event');\n" …Run Code Online (Sandbox Code Playgroud) 尝试使用 boost 进行 http 连接。到目前为止,我已经遵循了官方指南,并且能够正确获得响应并解析正文:
// Send the HTTP request to the remote host
http::write(stream, req);
// This buffer is used for reading and must be persisted
beast::flat_buffer buffer;
// Declare a container to hold the response
http::response<http::dynamic_body> res;
// Receive the HTTP response
http::read(stream, buffer, res);
// Write the message to standard out
std::cout << res << std::endl;
std::string body { boost::asio::buffers_begin(res.body().data()),
boost::asio::buffers_end(res.body().data()) };
Run Code Online (Sandbox Code Playgroud)
现在的问题是我不知道如何获取标头并检查状态码。有什么帮助吗?
android ×2
android-ndk ×1
boost ×1
boost-asio ×1
build.gradle ×1
gradle ×1
javascript ×1
kotlin ×1