Friday, January 25, 2019

Class: JSONObject not found in namespace - Solution

When you run the jmeter and if you see the error - Class: JSONObject not found in namespace

This mean that you dont have the class in jmeter lib you mentioned in the BeanShell script. To fix this copy the jar needed and paste it under lib folder in jmeter and restart it.

Download json jar from here - https://github.com/stleary/JSON-java

Thursday, January 24, 2019

How to get response data using BeanShell post possessor

In the BeanShell post possessor the script section has the following -

ctx, vars, props, prev, data and log.

In the above, the data is byte array of the parent sampler. So we can use string class from java to construct a string from the byte array like this -

String myResponseData = new String(data);


If you want to parse json from the above string you can use the following -

JSONObject jsonObj = new JSONObject(myResponseData);

Wednesday, January 16, 2019

Curl https error

When curl says https error just change the single quote to double quote it will work.

For example -



This is windows default installed libcurl.

Monday, July 18, 2016

How to generate html report from jmeter output? ie., JTL -> HTML


How to generate html report from jmeter output? ie., JTL -> HTML


Steps
1) Find and replace the special characters in the jtl file.

Making use of vim find and replace commands will replace all special characters like &#xw;, &#xww;, &#xwww;, &#xwwww; and &#x12123 with empty space. This step have to be done because xsltproc will not work if these characters present.

vim -c ":%s/&#x\w;//g" -c ":wq" log.jtl
vim -c ":%s/&#x\w\w;//g" -c ":wq" log.jtl
vim -c ":%s/&#x\w\w\w;//g" -c ":wq" log.jtl
vim -c ":%s/&#x\w\w\w\w;//g" -c ":wq" log.jtl
vim -c ":%s/&#x0//g" -c ":wq" log.jtl
vim -c ":%s/&#x\d+//g" -c ":wq" log.jtl

2) Execute xsltproc command using the attached style sheet Jmeter-Results-Details.xsl.

xsltproc Jmeter-Results-Details.xsl log.jtl  > output/result.html

Here log.jtl is the jmeter result file. The result.html is the converted html file we want.

Note:

A) The steps are for linux machine. If you have a windows machine the utility xsltproc can be installed separately and find and replace can be done using any document editing software.

B) Style sheet used - XSLT Style Sheet for JTL to HTML

Monday, January 16, 2012

How to start chrome browser using selenium webdriver?

For starting the chrome browser follow the instructions here - http://code.google.com/p/selenium/wiki/ChromeDriver

If you find it is difficult then dont worry just download the appropriate driver associated with your OS and then use the following code -

System.setProperty("webdriver.chrome.driver","path/to/chromedriver.exe");

It is the path to your downloaded chromedriver.exe

If you have a certificate warning for your product which uses https then use the following code -

       System.setProperty("webdriver.chrome.driver","path/to/chromedriver.exe");
        DesiredCapabilities dc = DesiredCapabilities.chrome();
        String[] options = { "--ignore-certificate-errors" };
        dc.setCapability("chrome.switches", Arrays.asList(options));
        return new ChromeDriver(dc);

Internet explorer is not starting using selenium webdriver. Message : Protected Mode must be set to the same value

If internet explorer is not starting using selenium webdriver and shows the error message says that "Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones. "

Create a desired capabilities instance and use it while creating the internet explorer driver. This is what the configuration done for this error as per the docs in selenium wiki. selenium help wiki link - http://code.google.com/p/selenium/wiki/InternetExplorerDriver
Required Configuration

    On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
    The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.

Even if it does not start the browser, create a desired capabilities instance and set ingnore flakiness boolean to true. Here is the code for code for ignoring the the protected mode security for all zones.
   
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
 capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        WebDriver driver = new InternetExplorerDriver(capabilities);

Thursday, May 19, 2011

How to download java sources using ant?

How to download java sources using ant?

It is very easy to download the source files using ant. For that you have to add a target which logins to the cvs using the cvspass tag. First set the property cvs.root to the actual cvs root. You can get this value in "Root" file under CVS folder in the source directories.

Step 1:

        <property name="cvs.root"   value=":pserver:anonymous@product-server:/url/of/the/product" />


Now add a target which logins to the cvs -

Step 2 :

<target name="cvslogin" description="Log in to CVS">
                <echo message="Setting Password for : ${cvs.root}" />
                <cvspass cvsRoot="${cvs.root}" password="anon"/>
</target>


The cvspass tag will look into the file ".cvspass" by default in windows xp it will look at "C:\Documents and Settings\jerald\.cvspass".

Step 4:

Check the .cvspass file for the cvs.root value ie., ":pserver:anonymous@product-server:/url/of/the/product" is present. If not open up a command prompt and login to cvs by issuing the following commands.

C:\>set cvsroot=:pserver:anonymous@product-server:/url/of/the/product

C:\>cvs login
Logging in to :pserver:anonymous@product-server:2401:/url/of/the/product
CVS Password:

Step 5:

Add another target to download the source code. You can also download the source from the same target but am separating this login target for clarity. Here is the target for downloading the source -

    <target name="downloadsource" depends="cvslogin">
                <cvs cvsRoot="${cvs.root}" package="product/package1" dest="${destinationdirectory}" />
    </target>


Possible errors:

1)  If you see any error "[cvs] Empty password used - try 'cvs login' with a real password" then the problem is there is no entry in ".cvspass" file. Do the step 4 and check the entry is added in the ".cvspass" file. Also do remember the ".cvspass" file is created when "cvs login" is invoked for the first time. If there is a change in cvsroot then a new line is added in that file. It is stored in this file for later access to the repository.

2)  If you see " cvs checkout: warning: unrecognized response `'ssh' is not recognized as an internal or external command,....." then check the correctness of cvs root string. Ie., ":pserver:anonymous@product-server:/url/of/the/product" some times you may miss the ":" or spelling mistakes. 

Sunday, October 17, 2010

How to delete a line which contain matching text line using vim?

I have already added a blog post with a tip for deleting all the matching lines for a matching patern. But this is some thing similar still it is easy after you seached for a text. ie., first search the pattern by "/" and the execute the command -
:g//d
This will delete all the lines with matching patterns. Tested in linux and also in windows.

Sunday, October 3, 2010

How to find number of matches in gvim

It is a easy tip to find the number of matching for the given pattern. Just search and replace it with any thing and see the success message given by vim. It will say "42 substitutions on 21 lines". And now undo changes. Thats it.

Sunday, September 19, 2010

How to find and replace with a new line character in windows gvim?

How to find and replace with a new line character in windows gvim?

It is very easy to find and replace with a new line in windows gvim.  In linux EOL ie., "End Of Line"

character will be "\n" but in windows it is "\r\n".   "\r" character is called as carriage return. Just visualize

old type writer machine carriage return. Now when it comes to find and replace with a new line using

windows is by the following steps,

1)Go to command mode by pressing "Esc" key.
2)Find and replace with a carriage return instead of a new line character. ie.,

:s/SearchText/\r/gc


For linux users, find and replace with a new line. ie.,

:s/SearchText/\n/gc

How to start another batch file in separate process?

Consider a usecase like when you trying to start a apache/tomcat server using a batch file.  After starting the server the batch file will stop thare. Meaning if you have the following in a batch file a.bat,

a.bat:

call c:\Installs\Tomact\bin\run.bat
time
unzip a.zip


then the command unzip and time will never executed. In that case starting a new command prompt and call those command via another batch file is possible and it is easy.

Split the above batch file into two batch files namely a.bat and b.bat with content as follows,

a.bat:

call c:\Installs\Tomact\bin\run.bat


b.bat:


time

unzip a.zip



Now write a another batch file with name c.bat as follows,

c.bat:

start call a.bat
start call b.bat

Now running the c.bat file will run both the batch files will run in separate process and all the commands are executed.

How to delete a line which contain matching text line using vim?

It is easy to delete all lines which have matching text at one shot.  For that you have to change the mode to command by presssing "Esc" key.Then type

:g/match text/d

thats it. All the lines which contain the "match text" will be deleted. This is tested with windows gvim.

Wednesday, August 25, 2010

error: 'Access denied for user 'root'@'localhost' (using password: NO)'

error: 'Access denied for user 'root'@'localhost' (using password: NO)'
Some of us come ac crossed this error when we try connecting Mysql  using no password. ie., when we connect  the mysql by the command "mysql -u root" . When we installing mysql in windows it will ask root password for creating my.ini file. After configuring root password when ever you connect the mysql you should use the command "mysql -u root -p" and enter the password when prompted.  


This will create head aches when you connect mysql through java driver using connection string with out password in a development environment.  To over come this, just reset the password to empty string by using the following three steps/commands - 

  1. UPDATE mysql.user SET Password=PASSWORD('') WHERE User='root';
  2. grant all privileges on *.* to root;
  3. FLUSH PRIVILEGES;

How to password protect a text file using vim?

I heard this tip very recently. For password protecting a file(may be a text file contains some secure password) using vim just open it using "x" option. ie., vim -x <filename>. Or you can do this in some other way while saving it using :X instead of :w

How to enable visual block mode in gvim


This post is for friends who LEARNED vim in linux machine and now using a windows gvim. For friends who used with Linux vim will know "ctrl+v" enables visual block mode. But this key combinations are used to paste the clipboard contents in windows gvim. So, how to enable that visual block mode in windows gvim? It is easy :) press "ctrl+q" thats it. Now don't forget to hold shift key to select block of text for editing.

How to remove end of line using vim/gvim

I was just wondering how to remove all the end of line "\n" or "\n\r" characters and make the entire content into one line.  It is very simple. Go to command mode by pressing the escape key and press "shift + j".  Okay if you want this to be done by a search and replacing command then type :%s/\n//gc in command mode.

How to remove empty lines usgin gvim in windows/Linux

I am searching for this in the internet but with no luck :( And some what managed to make it work. So i just post it for the sake of people who search for deleting or removing blank or empty lines from a file. I tested this on gvim in windows machine and also vim in linux machine.

Steps:

  1. Go to command mode by pressing esc.
  2. Then type - ":%s/^[\ \t]*\n//g" with out quotes. :)