如何从 Firebase 测试实验室设备下载文件

How to download file from Firebase Test Lab device

我正在尝试从 Google Firebase 测试实验室设备下载文件。这些文件是从 运行 仪器化测试生成的。文件是截图。我需要下载屏幕截图,因为后续运行的测试会将屏幕与这些屏幕截图进行比较。因此,屏幕截图是视觉变化检测的基线。

我尝试寻找连接到 Firebase 测试实验室设备 Device File Explorer 的方法。但是好像没有办法远程访问它。

自从 Firebase Test Lab cleans up the device 测试之后,我假设我能实现我想做的事情的唯一方法是将代码添加到测试中 push 某个地方的文件.

我想将文件推送到的一个地方是存储测试结果的 Google 云存储桶。从下面的文档来看,这似乎是存储桶的预期用途:

After Test Lab completes testing of your app, you can review test results in the Firebase console or in a Google Cloud storage bucket in your project. You can also add a gsutil command to the shell command shown above to copy the test results data to your local computer. To learn more, see Analyzing Firebase Test Lab Results. (Firebase documentation)

对于这种方法,我的插桩测试如何将文件推送到存储桶?它怎么知道要使用哪个桶?执行文件传输的API是什么?

我可以采用的另一种方法是 Take Screenshots from Firebase Test Lab Instrumentation Tests 这会将屏幕截图放入桶中。但我看到两个潜在的问题。

第一个问题是屏幕截图库的屏幕截图可能与从 UiAutomation.takeScreenshot(). In other words, the baseline screenshot is taken with screenshot library but on subsequent runs I would take the screenshot with UiAutomation.takeScreenshot() and compare them. Since the libraries are different, their screenshots might differ. A possible solution would be to take both screenshots with the screenshot library. But then I would need to figure out how to read the screenshot back into memory so I can perform my comparison operations. Today I read them in as Bitmaps 截取的屏幕截图不同。

对于这种方法,我的插桩测试如何将屏幕截图库的屏幕截图加载为 Bitmaps

第二个问题是弄清楚如何将屏幕截图从存储桶下载到我的本地计算机。存储桶的用户界面没有下载按钮。它只有一个上传按钮:

对于这种方法,我如何将文件从存储桶下载到我的本地计算机,以便我可以将它们添加到我的插桩测试可以读取的资源目录?

好的,我希望我在下面回答了你所有的问题:

默认情况下,/sdcard/Screenshots 中的所有文件都会从设备复制到您有权访问的 GCS 存储桶中。您可以在测试期间将自己的文件写入设备上的同一文件夹中。测试实验室将拾取它们并将它们复制到存储桶中。

如果你想下载额外的文件夹并下载到本地,我可以推荐flank,它有一个名为"directories-to-pull"的选项可以指定多个目录。它已经提供了很多你试图通过手工实现的东西,甚至更多。

如果您不想使用侧翼,gcloud 也有此选项,但会将文件放入您的 GCS 存储桶中。没有下载到本地机器。

云存储 UI 似乎相当有限。它允许您下载单个文件,但不能下载文件夹作为 zip。使用 gsutil 递归下载文件:

gsutil -m cp -r gs://path/to/bucket/folder path/to/local/folder

默认情况下,Test Lab 会为您提供一个 GCS 存储桶位置,它将文件复制到该位置,但您可以使用自己的存储桶和位置,例如使用 gcloud 客户端:

gcloud firebase test android run --results-bucket=gs://my-bucket --results-dir=path/to/folder

为您提供更多信息。您不需要为了使用 --directories-to-pull 而使用 Flank。该标志在测试实验室的 gcloud firebase test android run 命令中可用——有关详细信息,请参阅 https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run

此外,您当然可以从云存储下载文件 UI -- 只需单击文件名,它会询问您要将文件保存在本地驱动器上的哪个位置(或取决于文件的位置)类型,您可能需要右键单击并选择 "Save Link As...")。