简体   繁体   English

如何检测 Xamarin.Forms 应用程序何时在应用程序中心运行?

[英]How to detect when Xamarin.Forms app is running in App Center?

I have a Xamarin Forms app, with tests using Xamarin.UITest, and I need to detect when it's running in App Center Test.我有一个 Xamarin Forms 应用程序,使用 Xamarin.UITest 进行测试,我需要检测它何时在 App Center Test 中运行。

According to the docs , an environment variable RUNNING_IN_APP_CENTER should be set to 1 automatically - but Environment.GetEnvironmentVariable("RUNNING_IN_APP_CENTER") doesn't have a value at runtime.根据文档,环境变量RUNNING_IN_APP_CENTER应自动设置为1 - 但Environment.GetEnvironmentVariable("RUNNING_IN_APP_CENTER")在运行时没有值。

Indeed, if I loop over all environment variables, it's not there:事实上,如果我遍历所有环境变量,它就不存在:

KNOX_STORAGE:/data/knox/ext_sdcard
ANDROID_SOCKET_zygote:11
ASEC_MOUNTPOINT:/mnt/asec
MONO_DEBUG:gen-compact-seq-points
TMPDIR:/data/user/0/com.acme.widgets.dev/cache
XA_HTTP_CLIENT_HANDLER_TYPE:Xamarin.Android.Net.AndroidClientHandler
PATH:/sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin
MC_AUTH_TOKEN_PATH:/efs
XDG_CONFIG_HOME:/data/user/0/com.acme.widgets.dev/files/.config
DOWNLOAD_CACHE:/data/cache
ANDROID_ASSETS:/system/app
XA_TLS_PROVIDER:btls
ANDROID_ROOT:/system
MONO_GC_PARAMS:major=marksweep
XAMARIN_BUILD_ID:4658cc0f-1a7c-4c97-93a6-f2f09c5edb04
BOOTCLASSPATH:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/bouncycastle.jar:/system/framework/apache-xml.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/sprengine.jar:/system/framework/android.hidl.base-V1.0-java.jar:/system/framework/android.hidl.manager-V1.0-java.jar:/system/framework/knoxsdk.jar:/system/framework/timakeystore.jar:/system/framework/fipstimakeystore.jar:/system/framework/sec_edm.jar:/system/framework/knoxanalyticssdk.jar:/system/framework/smartbondingservice.jar:/system/framework/ucmopensslenginehelper.jar:/system/framework/esecomm.jar:/system/framework/securetimersdk.jar:/system/framework/sec_sdp_sdk.jar:/system/framework/sec_sdp_hidden_sdk.jar:/system/framework/framework-oahl-backward-compatibility.jar:/system/framework/android.test.base.jar:/system/framework/knoxvpnuidtag.jar:/system/framework/SemAudioThumbnail.jar:/system/framework/knoxguard.jar:/system/framework/drutils.jar
ANDROID_DATA:/data
LANG:en-GB
EXTERNAL_STORAGE:/sdcard
ANDROID_BOOTLOGO:1
ENC_EMULATED_STORAGE_TARGET:/storage/enc_emulated
HOME:/data/user/0/com.acme.widgets.dev/files
SYSTEMSERVERCLASSPATH:/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar:/system/framework/com.android.location.provider.jar:/system/framework/hqm.jar:/system/framework/hcm.jar
ANDROID_STORAGE:/storage
XDG_DATA_HOME:/data/user/0/com.acme.widgets.dev/files/.local/share

I've also tried altering my App Center CLI command to include extra environment variables, as per the docs:根据文档,我还尝试更改我的 App Center CLI 命令以包含额外的环境变量:

--test-parameter "app_env=MY_VAR=1"

But just the same, the MY_VAR is not available in the app.但同样, MY_VAR在应用程序中不可用。

Is there some other way to read environment variables that I'm missing, or perhaps some other way to detect when running in App Center Test?是否有其他方法可以读取我缺少的环境变量,或者是否有其他方法可以在 App Center Test 中运行时进行检测?

Can't you just use the "Test Compiler Directive" to detect that in code:难道你不能只使用“测试编译器指令”在代码中检测它:

#if ENABLE_TEST_CLOUD
    Xamarin.Calabash.Start(); 
    App.IsRunningInTestMode=true;
#endif

Look into your AppDelegate and MainActivity where you are enabling the Test configuration.查看您启用测试配置的 AppDelegate 和 MainActivity。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM