无法 运行 Python 自托管 Azure VM 上的 Selenium 测试

Unable to run Python Selenium Tests on Self Hosted Azure VM

我正在尝试通过 Azure 管道在我的自托管 VM 中执行 Selenium 测试。我收到以下错误消息。

##[错误]x64 架构的版本规范 3.8 与 Agent.ToolsDirectory 中的任何版本都不匹配。

下面是我的 Yaml

trigger:
- main

pool: default strategy:   matrix:
    Python38:
      python.version: '3.8'
      addToPath: true

steps:
- task: UsePythonVersion@0   inputs:
    versionSpec: '$(python.version)'
    addToPath: true
    architecture: 'x64'   displayName: 'Use Python $(python.version)'

- script: |
    python -m pip install --upgrade pip
    pip install -r requirements.txt   displayName: 'Install dependencies'

- script: |
    pip install pytest-azurepipelines
    pytest tests\test_smoke\test_suite_SmokeTest.py -s -v --browser Chrome --html=report.html --reruns 2   displayName: 'pytest'

- task: DownloadPipelineArtifact@2   inputs:
    buildType: 'specific'
    project: '8801f21d-f4e9-4b65-b01e-68baf825747c'
    definition: '5'
    buildVersionToDownload: 'latest'
    targetPath: '$(Pipeline.Workspace)'

我已经在我的虚拟机中配置了代理。我还在 VM 中安装了 python 3.8.6 并为其配置了 python 路径。

Unable to run Python Selenium Tests on Self Hosted Azure VM

要在私有代理上使用此任务,我们需要将所需的Python版本添加到自托管代理上的工具缓存中,以便使用它的任务。

通常工具缓存位于代理的 _work/_tool 目录下,或者您可以使用命令行任务回显变量 $(Agent.ToolsDirectory) 以获取路径。

然后,在该目录下,根据您的 Python 版本创建以下目录结构:

$AGENT_TOOLSDIRECTORY/
    Python/
        {version number}/
            {platform}/
                {tool files}
            {platform}.complete

The version number should follow the format of 1.2.3. The platform should either be x86 or x64. The tool files should be the unzipped Python version files. The {platform}.complete should be a 0 byte file that looks like x86.complete or x64.complete and just signifies the tool has been installed in the cache properly.

我的测试目录结构:

$AGENT_TOOLSDIRECTORY/
    Python/
        3.9.0/
            x64/
                python-3.9.0-amd64.exe
            x64.complete

现在,它在我的自托管代理上运行良好:

您可以参考 the FAQ in this document 了解更多详情。