【问题标题】:C# GoogleAPI - How to set a time duration when variable type is "object"?C# GoogleAPI - 如何在变量类型为“对象”时设置持续时间?
【发布时间】:2020-03-04 18:03:22
【问题描述】:

我在使用“Google.Apis.Testing.v1.Data”时遇到了问题,他们的文档对我没有帮助。

我必须设置一个“超时”值(= 一个持续时间),但变量类型是“对象”而不是“浮点”例如。我试图放置一个 int、一个浮点数和一个字符串,但这不起作用。

对象 API 文档是 here。我的变量是“TestTimeout”,这绝对是一个持续时间。

当我搜索解决方案时,我在 java 中看到变量类型是字符串,但这没有帮助 (here)

仅供参考,我正在使用此库在他们的测试设备上执行我的 android 应用程序。这是 Firebase 中称为 TestLab 的服务。超时值需要更高,因为我没有足够的时间来执行我的测试。这是我的代码,除了 TimeOut 之外,一切都运行良好。

        TestMatrix testMatrix = new TestMatrix();

        testMatrix.TestSpecification = new TestSpecification();
        testMatrix.TestSpecification.TestTimeout = 600.0f; // I tested 600, 600.0f, "600", "30m", "500s"

        testMatrix.EnvironmentMatrix = new EnvironmentMatrix();
        testMatrix.EnvironmentMatrix.AndroidDeviceList = new AndroidDeviceList();
        testMatrix.EnvironmentMatrix.AndroidDeviceList.AndroidDevices = new List<AndroidDevice>();

        foreach (TestMatrixModel.TestData testData in _model.ListTests)
        {
            if (testData.IsSelected)
            {
                //Here I'm using my own data class to set GoogleAPI objects, it's simple
                //as it asks me strings even for integer numbers, and it's working
                foreach (int indice in testData.ChosenAndroidVersionsIndices)
                {
                    AndroidDevice device = new AndroidDevice();

                    device.AndroidModelId = testData.ModelID;
                    device.AndroidVersionId = testData.AvailableAndroidVersions[indice];
                    device.Locale = testData.AvailableLocales[testData.ChosenLocale];
                    device.Orientation = testData.Orientation;

                    testMatrix.EnvironmentMatrix.AndroidDeviceList.AndroidDevices.Add(device);
                }
            }
        }

好的,这是请求的结果:

    {
  "testMatrixId": "matrix-2dntrwio3kco7",
  "testSpecification": {
    "testTimeout": "300s",
    "testSetup": {},
    "androidTestLoop": {
      "appApk": {
        "gcsPath": "gs://myLinkIntoGoogleCloudStorage.apk"
      }
    }
  },
  "environmentMatrix": {
    "androidDeviceList": {
      "androidDevices": [
        {
          "androidModelId": "grandpplte",
          "androidVersionId": "23",
          "locale": "en_001",
          "orientation": "landscape"
        },
        {
          "androidModelId": "hero2lte",
          "androidVersionId": "23",
          "locale": "en_001",
          "orientation": "landscape"
        },
etc.....

如您所见,它似乎是一个设置为“300s”的字符串......那么为什么“500s”无法输入?

非常感谢。

【问题讨论】:

  • 您遇到的错误是什么?使用“500s”。从generated sourcse 看来,它应该接受一个字符串。该错误是编译时错误,还是您发出请求时的错误?

标签: c# google-api-dotnet-client firebase-test-lab


【解决方案1】:

好的,我得到了答案:

testMatrix.TestSpecification.TestTimeout = "600s"; 

所以它是一个字符串,需要以“s”结尾。为什么当我尝试时这不起作用?只是因为我的代码在...之后被另一个 TestSpecification 覆盖了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    • 2021-07-21
    相关资源
    最近更新 更多