从命令行启动 Nunit 项目时,沿 nunit3-console 路径搜索文件

问题描述 投票:0回答:1

我使用以下命令运行测试:

C:\Users\user\NUnit.Console-3.17.0\bin\net6.0\nunit3-console.exe C:\Users\user\source\repos\mmfo_autotest\RegressionTestSuite\bin\Release\net6.0\Regression_Test_Suite.dll

我收到一个错误:

System.IO.FileNotFoundException : Could not find file 'C:\Users\user\.nuget\packages\nunit.consolerunner\3.17.0\tools\agents\net6.0\appsettings.json'.

但是appsettings.json位于项目根文件夹中

C:\Users\user\source\repos\mmfo_autotest\RegressionTestSuite\bin\Release\net6.0\appsettings.json

处理文件的代码:

string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json");
string text = File.ReadAllText(path);
_configuration ??= JsonConvert.DeserializeObject<ConfigurationData>(text);
return _configuration;

与 selenium-manager 的情况相同。在 nunit3-console 路径中查找此文件。尽管它确实并且应该位于项目的根文件夹中。

----> OpenQA.Selenium.WebDriverException : Unable to locate or obtain Selenium Manager binary at C:\Users\user\.nuget\packages\nunit.consolerunner\3.17.0\tools\agents\net6.0\selenium-manager\windows\selenium-manager.exe

如何让selenium-manager和appsettings.json在项目根文件夹中搜索到?

版本: NUnit - 4.1.0 NUnit.ConsoleRunner - 3.17.0

c# selenium-webdriver nunit
1个回答
0
投票

您必须将 nunit3-console 的路径添加到会话的 PATH 变量中。重击:

CSPROJ_PATH="src/YOURPROJ/YOURPROJ.csproj"

# Function to extract package version from csproj file
get_package_version() {
    grep "PackageReference Include=\"$1\"" $CSPROJ_PATH | awk -F'"' '{print $4}'
}

# Function to check the existence of an executable
check_executable() {
    if [ ! -f "$1" ]; then
        echo "$2 not found at $1"
        exit 2
    fi
}

# NUnit setup
NUNIT_VERSION=$(get_package_version "NUnit.ConsoleRunner")
echo "NUnit version: $NUNIT_VERSION"
NUNIT_PATH="${HOME}/.nuget/packages/nunit.consolerunner/${NUNIT_VERSION}/tools"
NUNIT_EXECUTABLE="${NUNIT_PATH}/nunit3-console${ext}"
echo "Checking executable: NUnit Console"
check_executable "$NUNIT_EXECUTABLE" "NUnit Console"

# Add NUnit path to PATH
export PATH=$PATH:$NUNIT_PATH

您必须将 Windows 的 HOME 变量更改为

/c/Users/${USERNAME}

© www.soinside.com 2019 - 2024. All rights reserved.