How to use ANT to save current process run time? - ant

How to save current process running time in some text file using Ant, then read file and assign to Ant variable?

You can use ant exec task. There you can specify the executable ps and the necessary arguments (PID, options). You can check the argumengs here.
You specify outputproperty in ant exec task so the output will be redirected to this property.
Then you can put the value in a file using the echo task.

Related

Jtl file is empty when running Jmeter using ant

I am trying to run Jmeter with ant, (since I want to display the results of test, with all the steps).
The issue is that after I managed to run the command the Jtl file is empty, I am trying to run the basic test.jmx default test.
I run the command ant -Detest=Test run
the build is successful but the jtl results are empty. moreover it is finished after one second, while if I run via UI mode it should take more time.
Can someone please advise how to use ant with Jmeter, or how to get fully reports like in csv in html out put?
[][build results]
[][build.xml from ant\bin location]
[][location of test.jtl results file]
[][results are empty]
Most probably something is wrong with your JMeter test itself, i.e.
JMeter failed to start (installation or configuration issues)
it has 0 threads in Thread Group
there is an If Controller condition which prevent test execution
the test relies on a JMeter Plugin which is not installed
etc.
So I would recommend amending your build.xml file and enable writing JMeter log file by adding the next line to <jmeter> section: jmeterlogfile="${testpath}/jmeter-ant.log >
So it would look like
<jmeter
jmeterhome="${jmeter.home}"
testplan ="${testpath}/${test}.jmx"
resultlog="${testpath}/${test}.jtl"
jmeterlogfile="${testpath}/jmeter-ant.log>
When you run your test one more time you should see jmeter-ant.log file in the folder where your .jmx file lives.
More information: JMeter Ant Task

Jmeter with ant - reports creation

I am trying to create report using ant in jmeter, meaning the full report.
I downloaded ant and it is installed as expected.
first I want to understand if ant command need to perform after test plan ran in the past? meaning it is offline process that creates the html reports? after the test plan finished?
Or is it command that actually used to run the test plan and create the html, meaning I do not need to run jmeter before?.
I used this command
jmeter -n -t C:\JMETER\Framework\Test_Fragment\Kung_Fu.jmx -l C:\Users\stackoverflow\Desktop\Jmeter_reports\results22_05_2018.csv
to run jmeter from command line, and create csv, so do I need two commands? one for creating csv and one for the ant? and if I create the csv where can I find the jtl of the testplan.
Name of test plan kung_fu
name of csv results22_05_2018.csv
what are the processes to run he ant, since I rename the Kung_Fu.jmx to test.jmx and put it in extras folder and when I command ant, it says test.jtl is not found.
can someone give a full explanation about the whole process
Rename results22_05_2018.csv into results22_05_2018.jtl and copy it to "extras" folder of your JMeter installation
Execute the following command in "extras" folder of your JMeter installation:
ant -Dtest=results22_05_2018 xslt-report
HTML report will be available as results22_05_2018.html
For more details see:
build.xml - reference Ant build file, by default it:
looks for Test.jmx file in the current folder
executes it and stores the result into Test.jtl file
applies XSLT transformation to the Test.jtl file and generates HTML file out of it.
JMeter Ant Task
Five Ways To Launch a JMeter Test without Using the JMeter GUI

Ant inside Robot Framework

Robot framework is generic keywords base testing framework. So can we use Ant task as a keyword in robot?
If yes what are the possible ways?
You can't use directly a Ant Task as a Robot keyword, but you can use Run Process keyword from the Process Library to launch the Ant command line you want to run:
*** test cases ***
my test
Run Process ant command line to launch
We can use "Run And Return Rc And Output" keyword from "OperatingSystem" Library
*** test cases ***
Test Ant
${RC} ${Output} Run And Return Rc And Output ant -f "antFile name"
where you need to set ANT_HOME and also set ANT in path variable
as
set PATH=%PATH%;%ANT_HOME%/bin
which will then run the ant task defined in ant file.
#{Flag}= Run And Return Rc And Output run.py
should Contain #{Flag} Camera Locked
The result will be saved in Flag variable and the next line will search for Camera Locked Text in output.
If you simply want to run just use Run And Return Rc

Ant exec task as another user

I would like to execute a shell script from an ant build (I saw the exec task seems to do it), but this script has to be executed from a user different thant the one launching ant. Is there a way to do this?
You could use the sshsexec task. Connect locally or to a remote machine:
<sshexec host="localhost"
username="dude"
password="yo"
command="touch somefile"/>
This task will require the optional jsch.jar to be installed in your ANT lib.
Specifying a pirvate key would enable a password-less login.
Couldn't you execute, from ant, a script that executes the actual script using sudo? See How to pass the password to su/sudo/ssh without overriding the TTY? for how to pass the password from the command line.

Is executing a sequence of Commands possible using ANT Exec task

In ANT Exec task. I need to cd into a folder (Windows OS) (eg: D:\Testrun) and execute a set of commands in a sequence which will be passed as parameters to the ant script. Is this possible ? Could anyone quote a sample example ? Could the results of the command execution be logged in a file ?
Could you wrap up the sequence of commands into a script (e.g. a .bat script)? You could pass parameters to the script from your ant task. You could direct the output of the script to a file using the output attribute of the exec task.

Resources