Is there a way of accessing the current script's absolute physical path via a variable/property? There doesn't appear to be anything listed via a Debug Sampler.
It's incredibly annoying that actions like loading CSV files and JMX Includes uses the current working directory as its relative path.
I used the answer provided by haridsv. It worked great except that I needed to put the directory to the JMX file in a variable. I made a "User Defined Variables" component and used BeanShell in the variable's "Value" field like this:
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}
The first BeanShell section calls the Java class that gets the directory in question. The second appends a file separator to the path, which is of course optional.
Include Controller
As per component's reference:
This element does not support variables/functions in the filename
field.
However, if the property includecontroller.prefix is
defined, the contents are used to prefix the pathname. If the file
cannot be found at the location given by prefix+filename, then the
controller attempts to open the fileName relative to the JMX launch
directory (versions of JMeter after 2.3.4).
You can pass JMeter a java property named includecontroller.prefix
which can be used to prepend a directory to the JMX file you're
including.
1) In case of console launch use:
-Jincludecontroller.prefix=/full/path/to/jmx/scripts/dir/
2) in case of GUI - add the same to .sh/.cmd/.bat file or write a wrapper file;
3) in case of Jmeter Ant Task usage - set as separate property:
<jmeter
jmeterhome="${jmeter.home}"
testplan="..."
resultlog="...">
<property name="jmeter.save.saveservice.assertion_results" value="all"/>
<property name="jmeter.save.saveservice.output_format" value="xml"/>
<property name="includecontroller.prefix" value="..."/>
</jmeter>
CSV Data Set Config
As per component's reference:
Relative file names are resolved with respect to the path of the
active test plan.
Absolute file names are also supported, but note
that they are unlikely to work in remote mode, unless the remote
server has the same directory structure. If the same physical file is
referenced in two different ways - e.g. csvdata.txt and ./csvdata.txt - then these are > > treated as different files. If the OS does not distinguish between upper
and lower case, csvData.TXT would also be opened separately.
You can declare a test plan variable that retrieves parameter value with the folder containing csv data files:
e.g.csv.path | ${__P(csv.path, ${__property(user.dir)}${__BeanShell(File.separator,)})}
CSV Data Set Config
Filename = ${csv.path}${__P(users-list,)}
Setting from console:
-Jcsv.path=/full/path/to/csv/data/dir/
Setting for distributed testing setup:
-Gcsv.path=/full/path/to/csv/data/dir/
By saying "current script's absolute physical path", I am guessing OP is referring to the location where the testplan (jmx file) is loaded from. I needed exactly this to generate a CSV file from BeanShell script at the beginning of the run, which is subsequently used in a CSV Data Set Config to read back, so I wanted the script to work just like how the later works when no path is specified. I went through the JMeter source and found this working solution:
import org.apache.jmeter.services.FileServer;
log.info(FileServer.getFileServer().getBaseDir());
I tested this and saw the correct path in the jmeter.log.
My particular issue was that my relative Include Controller path included a backslash which broke on Linux and OSX.
The solution was to use a forward slash in relative paths, which works on all platforms.
Related
I am new in Netbeans, I am doing project which is manipulate with MS Access Database (.mdb or .accdb).
Inside my code, I need to write the whole directory of my database file in order to connect it, like:
conn = DriverManager.getConnection("jdbc:ucanaccess://D:/abc/def/db.accdb");
Which folder should I put my database file in so that I no need to write the whole directory to connect it, like: conn = DriverManager.getConnection("jdbc:ucanaccess://db.accdb");?
You do not want to hardcode a database path in your code: good point!
Unfortunately, it looks like UCanAccess offers no special folder to automagically find the database: it just tries to find it where it is declared. So if you use a relative path, it will rely on Java processing and Javadoc for File class says:
By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.
If you use shortlinks under window, you can specify a start directory in the shortlink, but I would not rely on it because it is not a common usage even on Windows.
So the correct way (and common usage) is to use an environment variable. This variable would contain the database fullpath if you have no other external configuration value, or it will contain the path of a property file that in turn contains other configuration values.
Due to a project requirement I had to move from Selenium 2.0 to Watir and Cucumber framework. Earlier we were using Java and often set the default file path as:
System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"/browsers/chromedriver.exe");
Now I am trying to set up something similar in Ruby also, but being new to Ruby, I'm failing to get the root directory of the project. It only gets the path of the file which the current user is working using __FILE__ or Dir.pwd.
My Watir project structure is like this:
root
-config
-features
-pages
-step_definitions
-support
-hooks.rb
-browsers
...
...
I want to specify in hooks.rb that if the parameter passed is "Chrome", then run the Chrome browser, and when it is "FF" run the Firefox browser, but it always gives me the current working directory path and I need the root directory.
I am on WINDOWS 7, Using Ruby version 1.9.3p551.
Ruby's File class has several different methods that are useful for what you're trying to do, so read the documentation for absolute_path, expand_path, realdirpath and realpath.
I'd recommend starting with absolute_path:
Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless dir_string is given, in which case it will be used as the starting point. If the given pathname starts with a “~” it is NOT expanded, it is treated as a normal directory name.
I built the path from your hooks.rb to the root directory in my tests directory on my Desktop, and added this code to hooks.rb:
PATH_TO_ROOT = File.absolute_path('../..', File.dirname(__FILE__))
Running it shows:
PATH_TO_ROOT # => "/Users/ttm/Desktop/tests/ruby/root"
You'll always have to maintain the '../..' relative string but that is easier than hard-wiring your code with a fixed absolute path.
I tend to put code similar to this in any project that has multiple directories, especially when I'm calling library files. Write your code correctly, and you can do it once assigning the value to a constant, and you can then reference that constant wherever you need to know the absolute path to the installation.
book = Roo::Excel.new(File.join(File.absolute_path('../..', File.dirname(__FILE__)),"config/data/test.xls"))
It's a lot easier than that:
path_to_book = File.absolute_path('../../config/data/test.xls', File.dirname(__FILE__))
path_to_book # => "/Users/ttm/Desktop/tests/ruby/root/config/data/test.xls"
File.dirname(__FILE__) is the anchor for your relative path. Simply define the relative path to the file you want and let Ruby do the rest.
"Relative path to your project directory" talks about relative pathing in Ruby.
The answer to your question is going to be specific to the code that you are trying to use in your hooks.rb. If you could post a sample of what code you are using for this from your hooks.rb, that would be great. But the answer to your question is likely going to be some combination of the following:
File.join(File.dirname(__FILE__), '../../')
Where the first parameter is your current directory (root\features\support) and the second parameter is going to be the relative path to your root directory ('../../').
I want to use the relative path in xml files in our project. I have the files in the following location.
D:/SDC-Builds/SRDM2.3.0/SRDM/Svr/IdP/IdPserver/conf/attribute-r.xml
I have other xml file which needs to ref the above location, I use the following relative path to be independent of machines and folder names.
In D:/SDC-Builds/SRDM2.3.0/SRDM/Svr/IdP/IdPserver/others/service.xml, i am using the code like below
service.xml
<srv:ConfigurationResource="../../../../../../IdP/IdPserver/conf/attribute-r.xml">
</srv>
Please tell me am i using proper convention to refer the attribute-r.xml ?
If your Project Root Directory is SRDM, then you need to get back from your executable path.
Say you have your exe file at SRDM/Svr/bin/EXECUTABLE.exe then,
you need to mention in xml as
<srv:ConfigurationResource="../IdP/IdPserver/conf/attribute-r.xml"></srv>
ie. Current working directory is SRDM/Svr/bin/ and from that you need to get back up to common junction[Svr] in your case.
I have a .property file in my Java project. In that property file have more than 20 values. Now I want to parse that property file and change the specific property value at run time(that is when run the install file). I have used following code
Section
${ConfigWrite} "C:resource\conf.properties" SET WEBSERVICE.URL=http://localhost:8080 $R0
;$R0=CHANGED
SectionEnd
After running exe file ,the property added in property file like this
SETSERVER.URL=http://localhost:8080
I don't know why the SET words comes before this variable?
My requirements:
I need to give value for SERVER.URL property at run time (while installing the exe file)?
I need to replace the value of SERVER.URL property.but Using above added one more new property in that file.
I have used NSIS plugin in Eclipse on Windows platform.
You are missing some quotes when calling the macro, also there is no need to specify SET (in the example from help, SET is actually part of a command in a DOS batch file), and I guess that it is better to add a backslash to the path after the disk drive.
The doc states that the syntax is:
${ConfigWrite} "[File]" "[Entry]" "[Value]" $var
Therefore your call must be:
${ConfigWrite} "C:\resource\conf.properties" "WEBSERVICE.URL" "=http://localhost:8080" $0
Note how the parameters are splitted between the parameter name WEBSERVICE.URL and the value =http://localhost:8080 (note the equal sign at the beginning).
You can make the directories dynamic too:
${ConfigWrite} "$INSTDIR\resource\conf.properties" "WEBSERVICE.URL" "=http://localhost:8080" $0
I want to make JMeter distributed testing. It was said in the manual that first I should start jmeter-server on remote nodes, and then I should update jmeter.config and run jmeter on a master node.
I did all these steps. My test plan includes working with CSV-config files. If I test just from 1 (master) node - then everything works as a charm. But when I try distributed testing all tests fail. Some investigation showed that remote nodes send requests without substitution of ${..}-like parameters. Requests look like
POST data:
5|0|6|http://host.com/portal/|67D1C612DCF291DCD0F71AD15E404F37|host.ui.client.services.LoginService|login|java.lang.String/2004016611|${ADMIN_LOGIN}|1|2|3|4|3|5|5|5|6|6|1|
It's obvious that remote jmeter-server cannot find the CSV-file. Where should I put it?
P.S: I have machines with different OS (Windows 7 and Ubuntu 10.04).
The easiest way to resolve the multiple OS issue is to put the CSV file in the Jmeter BIN directory on all test machines, and do not reference the path in the CSV Data Set Config component.
Put a full path and filename into your 'CSV Data Set Config' component, eg. c:\loadtest\config.csv and ensure that you put the CSV file in the place that is specified.
The components manual also states the following:
Relative file names are resolved with respect to the path of the active test plan.
So it should be possible to put the file in the same directory as the test plan file. This ought to work in both Linux and Windows.
Any reference to data file assumes that such a file exists in respective nodes in the specified path. For example, if you have your CSV files in C:\data, then when you execute the test plan in a distributed fashion, the testplan would look for the data file in C:\data of the node (the slave).
In effect, if you are using 10 slave machines, you need to have c:\data folder in all those 10 machines.
There is no need to copy test plan.
EDITED because the docs reference was wrong - I got burned by my own answer :)
Old question, but I just ran into this issue and the answers here are conflicting.
Is a relative path resolved to the bin/ directory, or to the directory of the current .jmx test script?
Answer: it is only the directory of the test script. From the docs:
Relative file names are resolved with
respect to the path of the active test plan. Absolute file names are
also supported, but note that they are unlikely to work in remote
mode, unless the remote server has the same directory structure. If
the same physical file is referenced in two different ways - e.g.
csvdata.txt and ./csvdata.txt - then these are treated as different
files. If the OS does not distinguish between upper and lower case,
csvData.TXT would also be opened separately.