【问题标题】:How to fix warnings on Cypress run via custom Windows Powershell arguments?如何通过自定义 Windows Powershell 参数修复赛普拉斯运行的警告?
【发布时间】:2019-12-17 16:04:26
【问题描述】:

我有以下 Powershell 脚本

我需要传递参数,因为我正在使用另一个软件来触发 Cypress (Uipath)

Param(


    $RunType="--headed",
    $ProductCode="WR",
    $TestFile="cypress/integration/dongle/1-purchase.js"

   )


cd C:\Users\daniel\Desktop\senna-tests\cypress-cast

npx cypress run $RunType --env code= + $ProductCode --spec + $TestFile


# If running in the console, wait for input before closing.
if ($Host.Name -eq "ConsoleHost")
{
    Write-Host "Press any key to continue..."
    $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}

它有效,但我收到了这个丑陋的警告,我想解决这个问题:

‼ 警告:您似乎正在传递 --spec 一个以空格分隔的参数列表:

"+ cypress/integration/dongle/1-purchase.js"

这可行,但不建议这样做。

如果您尝试传递多个参数,请用逗号分隔它们: 赛普拉斯运行 --spec arg1,arg2,arg3

此警告的最常见原因是使用未转义的 glob 模式。如果你是 试图传递一个 glob 模式,使用引号将其转义: 赛普拉斯运行 --spec "**/*.spec.js"

【问题讨论】:

  • 我不熟悉该应用程序,但我认为这只是一个命令行实用程序。有时,使用类似的实用程序,最好将参数作为数组传递。如果您从命令提示符手动执行此操作,您将运行什么示例行?
  • npx cypress run --headed --env code=WR --spec "cypress/integration/dongle/1-purchase.js"

标签: node.js windows powershell cypress


【解决方案1】:

很高兴您找到了解决方案,对于延迟回复感到抱歉。我无法验证它,但通常使用数组作为参数可以解决命令行实用程序的一些问题 - 我对一些存储供应商的实用程序使用类似的东西。

只是一个建议:

$RunType = "--headed"
$ProductCode = "code=WR"
$TestFile = "cypres/integration/dongle/1-purchase.js"

$cypArgs = @()
$cypArgs = $cypArgs + "cypress"
$cypArgs = $cypArgs + "run" + "$RunType"
$cypArgs = $cypArgs + "--env" + "$ProductCode"
$cypArgs = $cypArgs + "--spec" + "$TestFile"
& npx.exe $cypArgs

【讨论】:

    【解决方案2】:

    我通过删除加号,替换为昏迷解决了这个问题。 此外,我能够解决变量产品代码中的问题(它不直接接受 =,因此将其作为变量)。

    Param(
    
    
        $RunType="--headed",
        $ProductCode="code=WR",
        $TestFile="cypress/integration/dongle/1-purchase.js"
    
       )
    
    
    cd C:\Users\daniel\Desktop\senna-tests\cypress-cast
    
    npx cypress run $RunType --env, $ProductCode --spec , $TestFile
    
    
    # If running in the console, wait for input before closing.
    if ($Host.Name -eq "ConsoleHost")
    {
        Write-Host "Press any key to continue..."
        $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
    }
    

    【讨论】:

      猜你喜欢
      • 2019-12-22
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 2020-03-17
      • 1970-01-01
      相关资源
      最近更新 更多