File is getting download in jmeter bin folder from 'Save Responses to a file' assertion.
I'm not able to verify the downloaded file, Is there any assertion available other than MD5Hex Assertion or I need to write JAVA/Groovy code?
If you need to check file presence you can add a JSR223 Assertion and use the following code assuming File.exists() function :
if (!new File('Bulk.pdf').exists()) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('File is absent')
}
If the file will not be present you will get an error message like:
More information: Scripting JMeter Assertions in Groovy - A Tutorial
You can check using notExists with more readable version
import java.nio.file.*;
if (Files.notExists(Paths.get("Bulk.pdf"))) {
Related
When I'm trying to run cypress test I'm getting this error:
The following error originated from your test code, not from Cypress.
\> Cannot find module './commands'
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.
I was expecting my tests to run, and I've tried to create an index.js in the support folder with:
import './commands'
Cypress.on('uncaught:exception', (err, runnable) => {
return false;
})
But that doesn't seem to work.
When I had this issue it was because I tried to import from the wrong file.
Instead of importing in the test file, commands should be imported into /cypress/support/e2e(.js|.ts) file.
Ref Custom Commands
We recommend defining queries is in your cypress/support/commands.js file, since it is loaded before any test files are evaluated via an import statement in the supportFile.
That way they are available in any test that requires them. This is because the /cypress/support/e2e.js file is automatically integrated into the start of any and all test runs.
JMeter 2.12
python 2.7.18
I'm getting JMeterLibException: 'Incorrect log file format' for the below code using robot framework
${logPath}= set variable C:/Tests/output1.log
run jmeter C:/Tests/apache-jmeter-5.4.1/bin/jmeter.bat C:/Tests/100users.jmx ${logPath}
${result} analyse jtl convert ${logPath}
log ${result}
FOR ${ELEMENT} IN #{result}
log dictionary ${ELEMENT}
It seems that your "JMeterLib" (whatever it is) expects some specific JMeter .jtl file format and JMeter 5.4.1 default settings are not compatible with it.
Unfortunately we cannot really help you without seeing this "JMeterLib" output or source code so I can only provide a generic piece of advice:
JMeter .jtl file output is controllable via special set of properties responsible for Results file configuration, once you determine what exact metrics does your "JMeterLib" expect you can amend JMeter's configuration accordingly in order to make it compatible with your 3rd-party software assumptions.
More information:
Configuring JMeter
Apache JMeter Properties Customization Guide
You should use jtl file extension instead of log
${logPath}=set variableD:/Tests/output1.jtl
We have ftp server with few directories and files under it, I am able to connect through browser and access directories successfully. However when used the same server:port with credentials not able to connect. Tried using JSR233 sampler also to list the files, but no success.
please guide.
TestPlan:
FTP request defaults (Server IP and port:21)>get(RETR)
--Thread Group
---FTP request (nothing added as remote file since just want to get list of files/directories)
---JSR233 sampler with below script
import org.apache.commons.net.ftp.FTPClient
def ftpClient = new FTPClient()
ftpClient.connect("xx.xx.xx.xx", 21)
ftpClient.login("'abc", "tesst")
ftpClient.listFiles().each {
log.info(it.getName())
}
log.info("---")
for FTP request getting an error as below:
Response message: java.io.FileNotFoundException: (The system cannot find the path specified)
Request is going as:
ftp://xx.xx.xx.xx:21/ (Ascii) ->
for JSR233 sampler: shows success without any response, files are list listed even in jmeter log also.
Please suggest how to achieve this.
Added screen shot of jmeter.log and .jmx file.
[![FTP req defaults[![FTP req![JSR233 sampler[![res msg: The system cannot find the path specified)
[]2]3]4]5
Able to get results in the Jmeter log file now, there was extra ' in the credentials going.
You might need to call FTPClient.changeWorkingDirectory() method before listing files as your abc user.
Prior to doing anything else you might want to test whether you connected to the FTP server or not by calling ftpClient.isConnected() method
Also be aware that FTPClient.login() method returns true if login is successful and false otherwise.
According to the Load Testing FTP and SFTP Servers Using JMeter article your code needs to be amended like:
import org.apache.commons.net.ftp.FTPClient
def ftpClient = new FTPClient()
ftpClient.connect('xx.xx.xx.xx', 21)
if (ftpClient.isConnected()) {
if (ftpClient.login('abc', 'tesst')) {
ftpClient.changeWorkingDirectory('/path/to/the/folder/with/files/') // navigate to the folder which content you want to list
ftpClient.listFiles().each {
log.info(it.getName())
}
} else {
log.error('Failed to login')
}
} else {
log.error('Failed to connect')
}
If none of the above hints will help post update your question with the jmeter.log file contents.
I am doing a protractor test. I want to print the messages i wrote inside the test using Console.Log("Message") to JUnitXmlReporter(the XML file). OR .... is ther anyway to create a custom Output files using protractor. I want to print a Data i fetched from the test to a File.
Have you tried:
https://github.com/larrymyers/jasmine-reporters
from their page:
JUnitXmlReporter - Report test results to a file in JUnit XML Report format.
NUnitXmlReporter - Report test results to a file in NUnit XML Report format.
you can also create a custom one:
http://jasmine.github.io/2.1/custom_reporter.html
hope it helps
You can keep things simple. You dont need any custom reporters to write the console information to a file. Just use the terminal output redirecting operator.
protractor conf.js > consoleLog.log
To append
protractor conf.js >> consoleLog.log
Check here for more options
I have a Jmeter project that is executed by Maven and is able to locate external Beanshell scripts by the path src/test/jmeter/external-scripts-dir/script1.bsh , but when I run Jmeter directly in the GUI on my computer the relative location doesn't work and the tests cannot be ran standalone. This forces me to run Jmeter from Maven.
So, I have a project file located at a Maven layout location like C:\files\git\projectA\src\test\jmeter\Project.jmx but since I ran jmeter from its installation folder at C:\Jmeter2.12 , it cannot find the relative location of the external script I mentioned earlier.
To solve this, all I need is to set a variable to the directory containing the .jmx file. Is there any possible way to do this?
I can dynamically determine the home of Jmeter ( C:\Jmeter2.12 ) pretty easily (using the following code) but that doesn't help me get the location of the project file.
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer
.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}
Is there something similar to the above code that would allow me to deduce the project file location?
If you're looking for the way to locate current script when you run JMeter in GUI mode you can try the following Beanshell expression:
${__BeanShell(import org.apache.jmeter.gui.GuiPackage;GuiPackage.getInstance().getTestPlanFile();)}
If you brake this down into 5 lines there will be:
import org.apache.jmeter.gui.GuiPackage;
import org.apache.commons.io.FilenameUtils;
String testPlanFile = GuiPackage.getInstance().getTestPlanFile();
String testPlanFileDir = FilenameUtils.getFullPathNoEndSeparator(testPlanFile);
vars.put("testPlanFileDir", testPlanFileDir);
log.info("testPlanFileDir:" + testPlanFileDir);
Your current .jmx file fill be stored as scriptFile JMeter Variable.
References:
GuiPackage class JavaDoc
How to use BeanShell: JMeter's favorite built-in component guide
The solution was (thanks to Ardesco) to do the following:
Use the following variables, set in the Test Plan global variables:
projectHome = ${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}
jmeterHome = ${__BeanShell(System.getProperty("user.dir");)}
scriptHome = ${projectHome}/scripts
Thanks to the accepted answer, I was able to solve a related problem.
Now, I can calculate this parameter once and re-use it as a user variable.
JMETER_SCRIPTS_DIRECTORY=${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}
Its usage is ${JMETER_SCRIPTS_DIRECTORY}.
Interestingly, it works in both GUI mode and NON GUI mode (from command line).