【发布时间】:2018-02-12 06:34:13
【问题描述】:
我正在使用适用于 Python 的 AWS Appium。由于我们的项目要求,测试将在 Python 中进行,但我们需要使用 .NET 在 AWS 中以编程方式构建、上传和安排测试。
根据 AWS 文档,测试包 zip 文件的根目录中应包含以下项目:“tests”文件夹、“wheelhouse”文件夹和“requirements.txt”文件。
当我在 Windows 机器上手动构建包时(只需选择文件和文件夹,右键单击并添加到 zip 存档),包被 AWS 接受并且测试正常运行。
但是,当我在 .NET 中以编程方式构建包时,即使输出 zip 文件与手动构建的 zip 文件具有相同的文件夹结构,AWS 也会通过以下错误消息拒绝它:
“我们在您的测试包的 root 中找不到测试目录”
我尝试了 3 种不同的方法在 .NET 中以编程方式构建包。两种方法都会导致相同的错误。简单来说,方法如下:
1/ 创建一个包含“tests”文件夹、“wheelhouse”文件夹和“requirements.txt”文件的“TestPackage”文件夹。使用以下代码压缩整个 TestPackage 文件夹:
ZipFile.CreateFromDirectory("TestPackage", zipPath, CompressionLevel.Optimal, includeBaseDirectory: false);
includeBaseDirectory 标志设置为false,这样所有文件夹和文件都将位于 zip 文件的根目录中。
2/ 创建一个空的 zip 文件。然后使用下面的伪代码将所有文件(“requirements.txt”和文件夹中的所有文件)添加到 zip 文件中:
using (var zipStream = File.Create(zipPath))
{
using (var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Update))
{
// entryName is the relative path to the file
// For eg., a file in the tests folder will have this path:
// @"\tests\test_sample.py"
zipArchive.CreateEntryFromFile(sourceFileName, entryName)
}
}
3/ 使用以下 PowerShell 脚本:
# Get the path to the AWSDeviceTests folder
# Assumption: the script file is in this folder
$ProjectDir = Split-Path -Path $MyInvocation.MyCommand.Path
# Get the paths of the test folders and file
$RequirementsFileDir = Join-Path -Path $ProjectDir -ChildPath "requirements.txt"
$TestsFolderDir = Join-Path -Path $ProjectDir -ChildPath "tests"
$WheelhouseFolderDir = Join-Path -Path $ProjectDir -ChildPath "wheelhouse"
# Zip the test folders and file
$ZipDestination = Join-Path -Path $ProjectDir -ChildPath "TestPackage.zip"
Compress-Archive -LiteralPath $RequirementsFileDir, $TestsFolderDir, $WheelhouseFolderDir -CompressionLevel Optimal -DestinationPath $ZipDestination
以上所有方法都失败了。 ZipFile 和 ZipArchive 来自 .NET 中的 System.IO.Compression。
我想再次强调,所有方法的输出 zip 文件与我手动构建的 zip 文件具有完全相同的文件夹结构,即所有必需的文件夹和文件都在 zip 文件的根目录中。虽然手动构建的文件有效,但以编程方式构建的文件却不行。
我做错了吗?在 .NET 或 Windows 中构建 AWS 设备测试包是否存在已知问题?还是无法以编程方式构建测试包并将其上传到 AWS Device Farm? zip 文件在 AWS Device Farm 中如何解析/验证?
任何帮助或建议将不胜感激。提前谢谢你。
【问题讨论】:
-
我曾经在 Mac 中使用存档器时遇到过类似的问题。在那种情况下,我发现如果我没有事先删除 zip,则 zip 不会更新。所以我不得不先把它删掉,然后再把所有东西都压缩起来。不确定这是否是这里发生的事情,但我希望这会有所帮助。听起来像是 .NET SDK 的一个非常细化的问题。
-
@jmp 感谢您的建议。在我的代码中,我确实检查了 zip 文件是否已经存在,如果存在,我会在从头开始创建新文件之前将其删除。
标签: amazon-web-services zip zipfile aws-device-farm