[Jmeter]通过批处理调用java,java从CSV动态读取登录的用户名和密码,并将其作为参数组合成字符串,写入外部.bat文件,然后通过Java执行这个外部批处理文件...
问题1:怎样通过批处理调用java代码?
问题2:怎样通过java从CSV文件获取到用户名和密码存入变量?
问题3:怎样将获取到的用户名和密码组合成字符串,写入外部批处理文件?
问题4:怎样在批处理文件调用ANT的时候,将用户名和密码作为参数传进去?
问题5:怎样通过java调用.bat文件?
问题6:怎样保证java在调用.bat的时候不出现闪退?
问题7:怎样让java在执行.bat的时候,.bat的控制台输出日志?
问题8:怎样让java执行.bat完成之后不会有残余的cmd.exe进程?
/*************CIM_US_TP_SmokeTest.bat*****************/
@echo off
color 0aecho autotest beginning,Please Wait... ...set AutoPath=%~dp0
%AutoPath:~0,2%
pushd %AutoPath%cd /d %AutoPath%
set JmeterPath=..\..\..\
echo AutoPath=%AutoPath%
echo JmeterPath=%JmeterPath%forfiles /p %AutoPath%Result /m *.jtl -d -7 /c "cmd /c del /f @path">nul 2>nul
forfiles /p %JmeterPath%extras /m *.html -d -7 /c "cmd /c del /f @path">nul 2>nuljavac getUserAccount_US_TP_SmokeTest.java
java getUserAccount_US_TP_SmokeTestexit
/*************CIM_US_TP_SmokeTest.bat*****************/
/************getUserAccount_US_TP_SmokeTest.java************/
import java.io.*;public class getUserAccount_US_TP_SmokeTest {public static String AutomationPath = System.getProperty("user.dir");public static void main( String[] args ) throws InterruptedException {System.out.println( "AutomationPath:" + AutomationPath );getUserAccount_US_TP_SmokeTest generator = new getUserAccount_US_TP_SmokeTest();String userName = generator.getUserName();
// System.out.println( "userName:" + userName );String password = generator.getPassWord();
// System.out.println( "password:" + password );generator.runAnt( userName, password );}private void runAnt( String userName, String password ) throws InterruptedException {Process p;String cmd = "ant -f "+AutomationPath+"\\CIM_US_TP_SmokeTest.xml"+" -DuserName=" + userName + " -Dpassword=" + password;String path=AutomationPath+"\\cmd_US_TP_Smoke.bat";fileWrite(cmd,path);try {System.out.println( "Execute in command line:: " + path );p =Runtime.getRuntime().exec(path);//取得命令结果的输出流InputStream fis=p.getInputStream();//用一个读输出流类去读InputStreamReader isr=new InputStreamReader(fis);//用缓冲器读行BufferedReader br=new BufferedReader(isr);String line=null;//直到读完为止while((line=br.readLine())!=null) {System.out.println(line);}Thread.sleep(10000);System.out.println( "Execute cmd over. ");} catch( IOException e ) {e.printStackTrace();}}public void fileWrite(String cmd,String path){File file = new File(path);try {if(!file.exists()){file.createNewFile();}FileWriter fw=new FileWriter(file,false);PrintWriter pw=new PrintWriter(fw);pw.println(cmd);pw.close(); fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }public String getUserName() {String userName="";try {BufferedReader reader = new BufferedReader(new FileReader(AutomationPath+"\\Data\\AccountInfo\\AutoTestAccount_Office_US_TP.csv"));//换成你的文件名reader.readLine();//第一行,为标题信息String line=reader.readLine();//读取第二行reader.close();String item[] = line.split(",");//CSV格式文件为逗号分隔符文件,这里根据逗号切分userName = item[0];//这就是你要的数据了//System.out.println("Get Login Email: "+userName);} catch (Exception e) {e.printStackTrace();}return userName;}public String getPassWord() {String password="";try {BufferedReader reader = new BufferedReader(new FileReader(AutomationPath+"\\Data\\AccountInfo\\AutoTestAccount_Office_US_TP.csv"));//换成你的文件名reader.readLine();//第一行,为标题信息String line=reader.readLine();//读取第二行reader.close();String item[] = line.split(",");//CSV格式文件为逗号分隔符文件,这里根据逗号切分 password= item[1];//这就是你要的数据了//System.out.println("Get Login Password: "+password);} catch (Exception e) {e.printStackTrace();}return password;}
}
/************getUserAccount_US_TP_SmokeTest.java************/
/************CIM_US_TP_SmokeTest.xml**********************/
<?xml version="1.0"?>
<project name="morningstar" default="all" basedir=".\">
<property name="JMeter.home" value=".\..\..\..\"/>
<property name="mail_to" value="lemon.li@morningstar.com,na.gong@morningstar.com,sandy.zhou@morningstar.com,jenny.zhang@morningstar.com"/>
<property name="to_me_only" value="jenny.zhang@morningstar.com"/>
<property name="ReportName" value="CIMUSSmokeTestReport"/>
<property name="ComputerName" value="SZOTWIN2K801"/>
<property name="LoginEmail" value="${userName}"/>
<echo>${userName}</echo>
<property name="LoginPassword" value="${password}"/>
<echo>${password}</echo>
<tstamp>
<format property="time" pattern="yyyyMMddhhmm"/>
</tstamp>
<target name="all" >
<antcall target="runCWP" />
<antcall target="runUDF" />
<antcall target="transferAll"/>
<antcall target="transferFailure"/>
<antcall target="sendEmail"/>
</target>
<target name="runCWP" depends="">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
<jmeter jmeterhome="${JMeter.home}" resultlog="${basedir}/Result/${ReportName}${time}.jtl">
<testplans dir="${basedir}\Script\SmokeTest" includes="CIM_US_TP_CWP_SmokeTest.jmx"/>
</jmeter>
</target>
<target name="runUDF" depends="">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
<jmeter jmeterhome="${JMeter.home}" resultlog="${basedir}/Result/${ReportName}${time}.jtl">
<testplans dir="${basedir}\Script\SmokeTest" includes="CIM_US_TP_UDF_SmokeTest.jmx"/>
</jmeter>
</target>
<target name = "transferAll" depends = "">
<xslt in="${basedir}/Result/${ReportName}${time}.jtl"
out="${JMeter.home}/extras/${ReportName}${time}.html"
style="${JMeter.home}/extras/JMeter-results-detail-report_21.xsl"/>
</target>
<target name = "transferFailure" depends = "">
<xslt in="${basedir}/Result/${ReportName}${time}.jtl"
out="${JMeter.home}/extras/${ReportName}${time}_failure.html"
style="${JMeter.home}/extras/JMeter-results-detail-report_21_failure.xsl"/>
</target>
<target name="sendEmail">
<mail mailhost="internalmail.morningstar.com" mailport="25" subject="CIM US Automation Test Report(Smoke Test)!" messagefile="${JMeter.home}/extras/${ReportName}${time}_failure.html" messagemimetype="text/html" tolist="${mail_to}">
<from address="jenny.zhang@morningstar.com"/>
<!-- <fileset dir="${JMeter.home}/extras/">
<include name="${ReportName}${time}.html"/>
<include name="expand.png"/>
</fileset> -->
<!-- <message>This email was sent automatically by ANT. <br />
Please check the automation test report by the link below. <br />
If there are any questions, please contact with Jenny Zhang. Thank you! <br /><br />
http://${ComputerName}/${ReportName}${time}.html
</message> -->
</mail>
</target>
</project>
/************CIM_US_TP_SmokeTest.xml**********************/
转载于:https://www.cnblogs.com/MasterMonkInTemple/p/3818017.html
[Jmeter]通过批处理调用java,java从CSV动态读取登录的用户名和密码,并将其作为参数组合成字符串,写入外部.bat文件,然后通过Java执行这个外部批处理文件...相关推荐
- java 文件 字符串_java将字符串写入到txt文件中
将字符串写入到txt文件中import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundExceptio ...
- oracle位于xdb的服务器,[Java教程]位于XDB的服务器localhost要求用户名和密码
[Java教程]位于XDB的服务器localhost要求用户名和密码 0 2012-11-08 18:00:14 最近,电脑上安装了Oracle数据库,再使用Tomcat服务器发布Java WEB程序 ...
- sqllite java 密码,SQLite登录检查用户名和密码
我正在创建一个应用程序(使用Java和SQLite)(JFrame,使用Netbeans)我有我想要登录的用户 . (我有所有正确的包JDBC,SQLite等) 我遇到的问题似乎是获取用户名/密码来检 ...
- java 字符串 转 文件路径_连接用户输入字符串转换为完整的文件路径(Java)
我写了一个简短的脚本来创建一个文件到我的桌面,文件出现了 . 我只是在main中完成了所有操作,如下所示: import java.io.*; import java.util.Scanner; pu ...
- CAD二次开发--系统找不到指定的文件/应用程序不支持实时(JIT)调试解决办法【即:C#调用外部exe文件在CAD内部执行失败处理办法】
我们知道一个大型的程序系统很多功能之间是相互独立的,因此对于一个exe可执行文件我们可以直接进行调用,丰富我们程序中的功能!但是今天在测试的时候发现,原本调试时候可以调用的exe文件,在打包后竟提示错 ...
- java如何将字符串写入到txt文件中,值得收藏!
ClickHouse 是什么? ClickHouse:是一个用于联机分析(OLAP)的列式数据库管理系统(DBMS) 我们首先理清一些基础概念 OLTP:是传统的关系型数据库,主要操作增删改查,强调事 ...
- c语言打开外部doc文件,C语言-内部函和外部函数.doc
C语言-内部函和外部函数 8.10 内部函数和外部函数?函数本质上是全局的,因为一个函数要被另外的函数调用,但是,也可以指定函数根据函数能否被其他源文件调用,将函数区分为内部函数和外部函数. 8.10 ...
- Java 调用 BAT 文件
本文内容大多基于官方文档和网上前辈经验总结,经过个人实践加以整理积累,仅供参考. 1 准备一个测试用批处理文件:test.bat mysqldump -uroot -p123456 test > ...
- Python数据分析之Pandas读写外部数据文件
点击上方"Datawhale",选择"星标"公众号 第一时间获取价值内容 阅读目录 1 引言 2 文本文件(txt.csv) 2.1 读取数据 2.2 写入数据 ...
最新文章
- 2018年看好这些半导体企业
- android 窗口缩放,Android界面整体缩放
- pycharm中传入命令行参数
- python人脸识别毕业设计-Python 40行代码实现人脸识别功能
- oracle 内核参数设置
- python的使用说明_Python教程:Python中__init__.py的使用用法说明
- Session何时创建实例
- Cowboy 源码分析(二十六)
- 垃圾收集(GC)中如何确定哪些内存是垃圾
- 即时战略类游戏:北加尔Northgard for Mac中文版
- 终于申请自己的博客了
- [目标检测]论文翻译代码理解-SCRDet: Towards More Robust Detection for Small, Cluttered and Rotated Objects
- 一些著名的软件都用什么语言编写?程序员都熟知这些软件!
- LNK1120: 一个无法解析的外部命令
- 国家标准计算机软件测试文档范文,软件测试相关国家标准.doc
- ES VS CK,成本太高,效率太低?不存在的
- 【Microsoft】Project Oxford
- 协同过滤美食推荐系统(SSM,MySQL)+全套视频教程
- Android 按钮设置边框实例
- JAVA中List 转long[]的方法
热门文章
- Apollo后台配置:配置集群
- Linux CentOS6.7设置为固定静态IP的方法
- python3 import导入模块
- MySQL使用覆盖索引来优化limit语句
- Spring Cloud Alibaba基础教程:Nacos 生产级版本 0.8.0
- Mybatis中的resultType与resultMap区别
- 未处理sqlexception中value_plsql异常处理
- 第一行代码学习笔记第七章——探究内容提供器
- 最优化——线性规划中最大规划和最小规划之间的转换
- html div圆滑效果,美化网页div -让边框拥有阴影,边角变得圆滑