创建批处理命令
该示例使用“探索”阶段的 Selenium 脚本来运行扫描。相同原则可适用于任何其他自动化框架。
关于此任务
假定使用 Selenium 脚本,那么端口 56232 用于 Selenium 和 AppScan Standard 之间的通信。还可以根据需要更改这些。
注: 在每个代码样本中,该步骤中添加的代码将以粗体突出显示。
如果想要自己完成该示例,包含已使用文件的文件夹可在以下位置找到:
[AppScan Standard installation folder]\Docs\Selenium Example
注: 如果 AppScan 的路径不同,将需要更改 JAR 文件中的路径。
过程
- 创建 TXT 文件并在文本编辑器中将其打开。
-
输入 AppScan 命令以打开 AppScan 并定义起始 URL、登录凭证、“仅测试”选项、开放代理和代理侦听端口:
START "" "[AppScan Standard installation folder]\AppScanCMD.exe" /starting_url "https://demo.testfire.net" /credentials "jsmith:demo1234" /test_only /opr /lp "53262"
提示: 可根据需要添加其他注释,例如定义特定测试策略,创建报告(有关详细信息,请参阅CLI)。 -
添加一个十五秒的超时批处理,以给 AppScan 时间来打开:
START "" "[AppScan Standard installation folder]\AppScanCMD.exe" /starting_url "https://demo.testfire.net" /credentials "jsmith:demo1234" /test_only /opr /lp "53262" timeout /t 15
-
添加 Selenium 脚本:
START "" "[AppScan Standard installation folder]\AppScanCMD.exe" /starting_url "https://demo.testfire.net" /credentials "jsmith:demo1234" /test_only /opr /lp "53262" timeout /t 15 java -jar selenium-server-standalone-2.52.0.jar -trustAllSSLCertificates -htmlSuite "*firefox" "https://demo.testfire.net" "mytestsuite.html" "results.html"
重要: Selenium 的起始 URL 必须与 AppScan 模板中的起始 URL 完全相同。 -
在 Selenium 脚本中插入 Selenium 会将其请求发送到的 AppScan 代理端口和主机:
START "" "[AppScan Standard installation folder]\AppScanCMD.exe" /starting_url "https://demo.testfire.net" /credentials "jsmith:demo1234" /test_only /opr /lp "53262" timeout /t 15 java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=56232 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=56232 -jar selenium-server-standalone-2.52.0.jar -trustAllSSLCertificates -htmlSuite "*firefox" "https://demo.testfire.net" "mytestsuite.html" "results.html"
-
在末尾添加命令以关闭 AppScan 代理并开始“测试”阶段:
START "" "[AppScan Standard installation folder]\AppScanCMD.exe" /scan_template " C:\Users\<username>\Documents\AppScan\QA Automation Demo Template.scant " /test_only /opr /lp "56232" timeout /t 15 java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=64345 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=56232 -jar selenium-server-standalone-2.52.0.jar -trustAllSSLCertificates -htmlSuite "*firefox" "https://demo.testfire.net" "mytestsuite.html" "results.html" "[AppScan Standard installation folder]\AppScanCMD.exe" cpr
- 保存文件,并使用命令行运行文件。
结果
重要: 如果进程因为任何原因而未完成,或者您在其完成之前将其停止,可能发现 Internet Explorer 和 Chrome 代理设置已更改,而且将需要手动撤销更改。