Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Monday, December 30, 2019

Install Java, Eclipse and RED

1. Check if Java already installed in the system

Write from command line
java -version

Output will show java installed version. If not installed than will show 'java' not recognized as internal or external command.

Check for java compiler version if Java is installed. Write from command line
    javac -version

Output will show installed Java Compiler version.

2. If Java not installed than download and install it

Go to https://www.oracle.com/technetwork/java/javase/downloads/index.html download it. Click Install now after successfully download the exe file to install it.

3. Setting Environment Variable

Navigate to My computer -> Properties-> Advance System Settings-> Environment Variable-> search for Path in System variable and click on Edit, add java/jdk/bin location and Save it.

4. Check installed Java

Write from command line
java -version

Output will show java installed version.

Write from command line
javac -version

Output will show java compiler installed version.

5. Download Eclipse

Go to https://www.eclipse.org/downloads/ and download Eclipse IDE.

6. Install Eclipse

Click Install now after successfully download the exe file. Select Eclipse IDE for Java developers.

7. Install RED - Robot Framework

Go to Eclipse marketplace and search for RED - Robot Framework and add it to your Eclipse IDE.

Monday, June 8, 2015

Read and Write Excel file by using Apache POI in Java

Perform following steps first for correct configuration:
  1. Download Apache POI from here
  2. Add Apache POI .jar files in your Java project as External JARs from Build path
  3. For .xls type Excel file use HSSF and for .xlsx type Excel file use XSSF

Read Excel File:


Reading a file using Apache POI is very simple and involve following steps:
  1. Create a file with specific location to find it
  2. Create an Input stream with that file
  3. Create POI Work book(HSSF/ XSSF) with that Input stream
  4. Create POI Work sheet(HSSF/ XSSF) with that Work book
  5. Get number of rows in the file
  6. Get number of columns in the file
  7. Create a 2 dimension array to store file data
  8. Traverse the array and do followings,
    1. Create HSSF/ XSSF row for each row in the file
    2. Create HSSF/ XSSF cell for each cell in the file
    3. Store the cell value in a String variable
    4. Store the String in respective array cell
Lets have a look at the code doing these steps:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class SimpleFileReadWrite {
 
     public static void main(String[] args) throws IOException
     { 
         File excel =  new File ("D:\\Credential.xlsx");
         FileInputStream fis = new FileInputStream(excel);
         XSSFWorkbook wb = new XSSFWorkbook(fis);
         XSSFSheet ws = wb.getSheet("creden");

         int rowNum = ws.getLastRowNum() + 1;
         int colNum = ws.getRow(0).getLastCellNum();
         String [][] data = new String [rowNum] [colNum];

         for(int i = 0; i <rowNum; i++){
             XSSFRow row = ws.getRow(i);
                 for (int j = 0; j < colNum; j++){
                     XSSFCell cell = row.getCell(j);
                     String value = cell.toString();
                     data[i][j] = value;
                     System.out.println ("the value is " + value);
                 }
         }
}

Write Excel File:


Writing a file using Apache POI is very simple and involve following steps:
  1. Create a file with specific location to create it
  2. Create an Output stream with that file
  3. Create POI Work book(HSSF/ XSSF) with that Input stream
  4. Create POI Work sheet(HSSF/ XSSF) with that Work book with specific name
  5. Store String values in a 2 dimension array to write in file
  6. Traverse the array and do followings,
    1. Create HSSF/ XSSF row for each row in the file
    2. Create HSSF/ XSSF cell for each cell in the file
    3. Set cell value with respective array cell
Lets have a look at the code doing these steps(here I am using the same code I used for reading file. So this program read from a .xlsx file, store data in an 2 dimension array and write it in another .xlsx file):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class SimpleFileReadWrite {
 
     public static void main(String[] args) throws IOException
     {     
         File excel =  new File ("D:\\Credential.xlsx");
         FileInputStream fis = new FileInputStream(excel);
         XSSFWorkbook wb = new XSSFWorkbook(fis);
         XSSFSheet ws = wb.getSheet("creden");

         int rowNum = ws.getLastRowNum() + 1;
         int colNum = ws.getRow(0).getLastCellNum();
         String [][] data = new String [rowNum] [colNum];

         for(int i = 0; i <rowNum; i++){
             XSSFRow row = ws.getRow(i);
                 for (int j = 0; j < colNum; j++){
                     XSSFCell cell = row.getCell(j);
                     String value = cell.toString();
                     data[i][j] = value;
                     System.out.println ("the value is " + value);
                 }
         }

         File outexcel = new File ("D:\\Output_excel.xlsx");
         FileOutputStream fos = new FileOutputStream(outexcel);
         XSSFWorkbook owb = new XSSFWorkbook();
         XSSFSheet sht = owb.createSheet("New sheet");

         for(int i = 0; i <rowNum; i++){
             XSSFRow orow = sht.createRow(i);
                 for (int j = 0; j < colNum; j++){
                     XSSFCell ocell = orow.createCell(j);
                     ocell.setCellValue(data[i][j]);
                     System.out.println ("the value is " + data[i][j]);
                 }
         }
         
         owb.write(fos);
   fos.flush();
   fos.close();
          
     }
 }

Friday, February 13, 2015

Record and Run in JMeter for Performance Test

JMeter is an open source desktop application available for all. By using Apache JMeter we can perform performance test on a web application. A very short, simple and quick intro available, if you want to check the link.

In this post we will learn how to record a test scenario and run it in Windows. Follow step by step process as describe below,
  • Download Apache JMeter.
  • Download Java. And install it.
  • Unzip Apache JMeter file. And open jmeter.bat.
  • Add users by right clicking on the Test plan. Test plan-> Add-> Threads (Users)-> Thread Group.
  • Add Thread group name, Number of threads, Ramp up period and Loop count. Remember in JMeter Thread meaning User. Replace thread word with user. Add User group name, Number of users and others. Ramp up period in sec = Ramp up period/ Number of users. Loop count can be forever also. If you use forever loop than you have manually stop the test.
  • Go to WorkBench section.
  • Right click on Workbench. Add-> Non-Test elements-> HTTP(S) Test Script Recorder.
  • Use the Start button at bottom right corner to start recording. And Stop after recording is done.
  • In your Mozilla Firefox driver go to Options-> Networks-> Manual proxy. Add localhost in your server field and 8080 in the port number field.

  • Add Recording controller. 
  • Right click on the Thread group. Add-> Logic controller-> Recording controller.
  • Perform the test scenario in the browser.
  • After finishing the scenario hit the Stop button in HTTP(S) Test Script Recorder of JMeter.
  • Observe that all test steps are added in Recording controller under the Thread group as HTTP requests.
  • To view performance results we need to add a report. Listener is report/ output in JMeter.
  • Right click on Thread group. Add-> Listener-> Summary report.
  • It is a good practice to clear your previous records before saving the test plan. Try to do it every time you save. 
  • Save your test plan and hit the play button.
  • By hitting the play button you are saying to JMeter, run the recorded test for 50 users. 1 user will be added every second. Running the loop 5 times, that will be 50*5 times for all users.
  • After test run process is finish check the Summery report for test data.
Please leave a reply, about this article was helpful or not? Suggestions of improvements are also welcome. Thanks for your time.

Sunday, September 8, 2013

Selenium simplified tutorial

If you are interested in Selenium Webdriver. Looking for tutorial with good and trusted contents than I have a very special solution for you.

Alan Richardson a very well known tester wrote down a magnificent book called Selenium Simplified. The writer provide a very useful and free course in Udemy and paid course for a more details on Java. Check following links,


I hope this guideline is helpful for you, feel free to post your comment.

Wednesday, October 31, 2012

Selenium Test Report

How to see your written scripts of automated Selenium test case results as a report?

You can see a very rich result report by following below instructions. I am assuming you are running Selenium RC(Java) with Eclipse and in Windows. I am also assuming everything is configured thus your environment is ready to roll.

- When running the selenium server write down this code in the terminal
java -jar selenium-server.jar -htmlSuite "<insert_browser_name_here>""<insert_root_domain_here>" "<insert_full_path_to_suite_here>""<insert_a_full_path_to_store_reports_here>"

- For example,
java -jar selenium-server.jar -htmlSuite "*googlechrome""http://www.google.com""c:\ide_scripts\suite.htm""c:\ide_scripts\results.htm"

- After running test cases in the suite you should be able to see following figures(depending on your test cases and results of your suite),



Monday, January 30, 2012

Running Selenium Webdriver 2.0 in Opera

Following are the steps I used to run selenium webdriver in Opera
(Windows, Mozilla Firefox, Opera, Eclipse, Java)

Selenium IDE with Mozilla Firefox
- Open your Mozilla Firefox browser and Selenium IDE add on
- Record a simple and short test case for your testing application through Firefox and IDE
- Replay it ensure that cases runs alright as you recorded
- Export Test Case as JUnit4(Webdriver) Script from IDE

Selenium Webdriver/ Selenium 2.0
- Run Eclipse
- Create an new project
- Create a Class for the project without Main()
- Add the downloaded webdriver .jar files to your project in Java Build path-> Library
- Download and add another additional jar for Opera, selenium-server-standalone-2.18.0.jar
- Paste the JUnit4 code exported from IDE
- Hit the play button and enjoy ;)

Opera Configaration
- Opera latest versions
- Replace the code in exported JUnit code
-" driver = new FirefoxDriver(); " replace it with " driver = new OperaDriver(); "
- import com.opera.core.systems.OperaDriver;

Sunday, January 29, 2012

Running Selenium Webdriver 2.0 in IE

Following are the steps I used to run selenium webdriver in IE
(Windows, Mozilla Firefox, IE, Eclipse, Java)

Selenium IDE with Mozilla Firefox
- Open your Mozilla Firefox browser and Selenium IDE add on
- Record a simple and short test case for your testing application through Firefox and IDE
- Replay it ensure that cases runs alright as you recorded
- Export Test Case as JUnit4(Webdriver) Script from IDE

Selenium Webdriver/ Selenium 2.0
- Run Eclipse
- Create an new project
- Create a Class for the project without Main()
- Add the downloaded webdriver .jar files to your project in Java Build path-> Library
- Paste the JUnit4 code exported from IDE
- Hit the play button and enjoy ;)

IE Configaration
- IE 6 or Higher versions
- Go to IE Settings -> Internet options -> Security tab -> Enable protected mode for all type of connections
- Replace the code in exported JUnit code
-" driver = new FirefoxDriver(); " replace it with " driver = new InternetExplorerDriver(); "
- import org.openqa.selenium.ie.InternetExplorerDriver;

Wednesday, January 25, 2012

Running test scripts in Selenium 2.0

Following are the steps I used to run selenium webdriver
(Windows, Mozilla Firefox, Eclipse, Java)

Selenium IDE
- Open your Mozilla Firefox browser and Selenium IDE add on
- Record a simple and short test case for your testing application through Firefox and IDE
- Replay it ensure that cases runs alright as you recorded
- Export Test Case as JUnit4(Webdriver) Script from IDE

Selenium Webdriver/ Selenium 2.0
- Run Eclipse
- Create an new project
- Create a Class for the project without Main()
- Add the downloaded webdriver .jar files to your project in Java Build path-> Library
- Paste the JUnit4 code exported from IDE
- Hit the play button and enjoy ;)

Selenium cont.

I am listing my steps I used to configure selenium in my windows machine, in two different parts

Selenium IDE
- Add it to your Mozilla Firefox browser

Selenium Webdriver
- Download and install Java Runtime Enviroment
- Download and install Frame work you gonna use, I am using Eclipse Classic
- Download all the listed .jar files for webdriver

Move to my next post to running automation in webdriver :)

Lets start automation

So many automation application is available today but 3 most popular is Selenium, Watir and Sahi. Lets start with Selenium as it is most popular, have a very strong community for support and many many tutorial is available over the web to start. Selenium many different parts for different type of functionality. I am gonna use Selenium IDE, Selenium RC and Selenium Webdriver or Selenium 2.0 and others I am ignoring at the moment.

Selenium IDE
- An add on for Mozilla Firefox
- Used for recording activity in browser in terms of web applications
- Can export automation script of variety range of programming language to use in RC/ Webdriver/ Selenium 2.0

Selenium RC/ Selenium Webdriver / Selenium 2.0 (Java)
- Selenim RC or Webdriver or 2.0 is actually is the same application
- RC is the older version with have limited functionality and Webdriver/ Selenium 2.0 is the latest with more functionality in terms of automation scripting
- Support programming languages, I am focusing only in Java
- Exported script of IDE can be Import here

So, lets roll on my next post ;)

Monday, October 10, 2011

Jmeter for Load and Performance testing

Jmeter is a very well known tool for load and performance testing. Installed it today in my ubuntu environment and it is working fine :) Thanks to these two following links.

Installing Jmeter -> http://joysofprogramming.com/install-jmeter-java-ubuntu/

How to use Jmeter -> http://www.roseindia.net/jmeter/using-jmeter.shtml

More about Jmeter -> http://jakarta.apache.org/jmeter/

Although Jmeter is popular a lot but I guess this post is gonna be useful for some ppl, like me ;)