如何在 GitHub 操作中 运行 Selenium 测试
How to run Selenium tests in GitHub Actions
我正在尝试在 GitHub 操作 中找到与 运行 Selenium 测试等效的命令。在 Azure DevOps 中,我将使用此 YAML 运行 "Visual Studio Test":
- task: VSTest@2
displayName: 'Run functional smoke tests on website and web service'
inputs:
searchFolder: '$(build.artifactstagingdirectory)'
testAssemblyVer2: |
**\FeatureFlags.FunctionalTests\FeatureFlags.FunctionalTests.dll
uiTests: true
runSettingsFile: '$(build.artifactstagingdirectory)/drop/FunctionalTests/FeatureFlags.FunctionalTests/test.runsettings'
overrideTestrunParameters: |
-ServiceUrl "https://$(WebServiceName)-staging.azurewebsites.net/"
-WebsiteUrl "https://$(WebsiteName)-staging.azurewebsites.net/"
在GitHub个动作中,对应的任务是什么? VsTest.Console.exe 似乎不存在于 GitHub runner/agent 中,因此答案可能涉及安装 Visual Studio Test Platform installer - 但显然我想避免这种情况会严重减慢每次构建。
感谢@Eldar 帮助我指明了正确的方向。基本答案是(运行 in a Windows runner):
- name: Functional Tests
run: |
$vsTestConsoleExe = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe"
$targetTestDll = "functionaltests\FeatureFlags.FunctionalTests.dll"
$testRunSettings = "/Settings:`"functionaltests\test.runsettings`" "
#Note that the `" is an escape character to quote strings, and the `& is needed to start the command
$command = "`& `"$vsTestConsoleExe`" `"$targetTestDll`" $testRunSettings "
Write-Host "$command"
Invoke-Expression $command
shell: powershell
使用 Invoke-Expression 似乎有助于解决我收到的一些初始错误。带有上下文的完整 yaml 可在 GitHub 上查看:
注意要找到 vstest.console.exe 文件,我使用这个 yaml 来搜索 GitHub Actions runner。有些文件夹被锁定,因此如果您搜索根 C: 文件夹,则会引发错误。使用上面提供的 link,我能够建立 Visual Studio 的根文件夹并在那里搜索 vstest.console.exe:
- name: search for visual studio test runner
run: |
$var1 = Get-Childitem -Path "C:\Program Files (x86)\Microsoft Visual Studio" -Filter "vstest.console.exe" -Recurse | select -ExpandProperty FullName
Write-Host "VS test runner: $var1"
shell: powershell
由于 Marketplace 上提供的 Setup VSTeset.console.exe 操作,现在变得简单多了。
Windows 代理上仍然需要 运行,但 YAML 行数已显着减少。
以下代码片段假定名为“functional-tests”的工件已 uploaded then downloaded 放入“./ functional-tests/".
- name: Add VSTest.console.exe to the PATH
uses: darenm/Setup-VSTest@v1
- name: Run functional tests
run: vstest.console.exe "functional-tests\<functional-tests-project-dll-name-here>.dll"
我的经验是,如果您在工作级别设置 environment variables,这些将由 vstest.console.exe
自动选取。这可能适用于在步骤或工作流级别设置它们,但我没有测试过。
我正在尝试在 GitHub 操作 中找到与 运行 Selenium 测试等效的命令。在 Azure DevOps 中,我将使用此 YAML 运行 "Visual Studio Test":
- task: VSTest@2
displayName: 'Run functional smoke tests on website and web service'
inputs:
searchFolder: '$(build.artifactstagingdirectory)'
testAssemblyVer2: |
**\FeatureFlags.FunctionalTests\FeatureFlags.FunctionalTests.dll
uiTests: true
runSettingsFile: '$(build.artifactstagingdirectory)/drop/FunctionalTests/FeatureFlags.FunctionalTests/test.runsettings'
overrideTestrunParameters: |
-ServiceUrl "https://$(WebServiceName)-staging.azurewebsites.net/"
-WebsiteUrl "https://$(WebsiteName)-staging.azurewebsites.net/"
在GitHub个动作中,对应的任务是什么? VsTest.Console.exe 似乎不存在于 GitHub runner/agent 中,因此答案可能涉及安装 Visual Studio Test Platform installer - 但显然我想避免这种情况会严重减慢每次构建。
感谢@Eldar 帮助我指明了正确的方向。基本答案是(运行 in a Windows runner):
- name: Functional Tests
run: |
$vsTestConsoleExe = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe"
$targetTestDll = "functionaltests\FeatureFlags.FunctionalTests.dll"
$testRunSettings = "/Settings:`"functionaltests\test.runsettings`" "
#Note that the `" is an escape character to quote strings, and the `& is needed to start the command
$command = "`& `"$vsTestConsoleExe`" `"$targetTestDll`" $testRunSettings "
Write-Host "$command"
Invoke-Expression $command
shell: powershell
使用 Invoke-Expression 似乎有助于解决我收到的一些初始错误。带有上下文的完整 yaml 可在 GitHub 上查看:
注意要找到 vstest.console.exe 文件,我使用这个 yaml 来搜索 GitHub Actions runner。有些文件夹被锁定,因此如果您搜索根 C: 文件夹,则会引发错误。使用上面提供的 link,我能够建立 Visual Studio 的根文件夹并在那里搜索 vstest.console.exe:
- name: search for visual studio test runner
run: |
$var1 = Get-Childitem -Path "C:\Program Files (x86)\Microsoft Visual Studio" -Filter "vstest.console.exe" -Recurse | select -ExpandProperty FullName
Write-Host "VS test runner: $var1"
shell: powershell
由于 Marketplace 上提供的 Setup VSTeset.console.exe 操作,现在变得简单多了。
Windows 代理上仍然需要 运行,但 YAML 行数已显着减少。
以下代码片段假定名为“functional-tests”的工件已 uploaded then downloaded 放入“./ functional-tests/".
- name: Add VSTest.console.exe to the PATH
uses: darenm/Setup-VSTest@v1
- name: Run functional tests
run: vstest.console.exe "functional-tests\<functional-tests-project-dll-name-here>.dll"
我的经验是,如果您在工作级别设置 environment variables,这些将由 vstest.console.exe
自动选取。这可能适用于在步骤或工作流级别设置它们,但我没有测试过。