首页 > 解决方案 > 如何在纠缠中为每个测试用例传递参数?

问题描述

我在 azure 中有一个 powershell 脚本

Invoke-Pester -Script @{Path = 'C:\Turing\Test\Frida-launcher.ps1'; Parameters = @{frida_process_id = '1655944245'; frida_user = 'heber.solis@softtek.com'; frida_psw = 'password'}} -OutputFile "frida-results.xml" -OutputFormat "NUnitXML"

它在管道运行的机器上调用另一个 powershell 脚本

param($frida_process_id, $frida_user, $frida_psw)
"current location: $(Get-Location)"
"script root: $PSScriptRoot"
"retrieve available modules"
$modules = Get-Module -list
if ($modules.Name -notcontains 'pester') {
    Install-Module -Name Pester -Force -SkipPublisherCheck
}

#$frida_process_id = $args[0]
#$frida_user = $args[1]
#$frida_psw  = $args[2]



Describe "Suites - Prueba" {

    It "Test Case Script - HEB - FRIDA - eCommerce - 706161449 _ Conexion Exitosa " {

        Start-Process -FilePath "C:\Turing\App\TuringExpo.exe"  "$frida_process_id $frida_user $frida_psw"  -Wait
        Set-Content -Path TestDrive:\log.txt -Value 'I am a file'
        $actual = "Actual value"
        $actual | Should -Be "Actual value" # Test will pass / Assert 
        $actual | Should -Not -Be "Some other value" # Test will pass / Assert Negative 
        # $actual | Should -Be "not actual value"  # Test will fail
        'C:\Turing\App\log.txt' | Should -Exist
        Set-Content -Path TestDrive:\log.txt -Value 'Success'
        'TestDrive:\log.txt' | Should -FileContentMatch 'Success' # Test will pass 
    }
}

问题是到目前为止我只需要运行一个测试用例,但是现在,我需要运行一个测试套件但我不知道如何发送每个测试用例的参数。

我试着这样做

Invoke-Pester -Script @{Path = 'C:\Turing\Test\Frida-launcher.ps1'; Parameters = @{frida_process_id = '807028544'; frida_user = 'heber.solis@softtek.com'; frida_psw = 'password'}
@{frida_process_id = '1354584657'; frida_user = 'heber.solis@softtek.com'; frida_psw = 'password'}} -OutputFile "frida-results.xml" -OutputFormat "NUnitXML"

但它抛出了这个错误

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "。'C:\agent_work_temp\67c2cb15-7277-43ea-a21e-c1a5aaab3309.ps1'"在 C:\agent_work_temp\67c2cb15-7277-43ea-a21e-c1a5aaab3309.ps1:3 char:99 + ... ida_user = 'heber.solis@softtek.com'; frida_psw = 'password'}} -Outpu ... + ~ 在散列文字中的键后缺少“=”运算符。在 C:\agent_work_temp\67c2cb15-7277-43ea-a21e-c1a5aaab3309.ps1:3 char:99 + ... ida_user = 'heber.solis@softtek.com'; frida_psw = 'password'}} -Outpu ... + ~ 哈希文字不完整。+ CategoryInfo : ParserError: (:

[错误]PowerShell 以代码“1”退出。整理:PowerShell脚本

谢谢您的帮助

标签: powershellpester

解决方案


推荐阅读