Monday, January 27, 2020

Different types of Waits in Robot Framework (Selenium Library)

1. Sleep
Waits for a specific given time.

2. Set Selenium Speed
Waits given specific time before each Selenium actions performed.

3. Set Selenium Timeout
Waits given specific time before throwing exception for each Selenium Waits.


4. Set Selenium Implicit Wait
Waits given specific time before throwing exception for each Selenium action's locator not found (only when locator is not found, if found it will wait default time).

Sunday, January 19, 2020

Configure Continuous Integration System Jenkins to build Robot projects

1. Download Jenkins

Go to https://jenkins.io/download/ and download it for your system.

2. Start and Setup Jenkins in you system

After download open command line window.

Write from command line
cd location_of_jenkins.war_file

Write from command line to run Jenkins in 8080 port
java -jar jenkins.war

Write from command line to run Jenkins in a specific port
java -jar jenkins.war --httpPort=port_number

Output will show Jenkins running status.

From browser, browse to localhost:specific_port_number (if specific port is given otherwise only localhost which will select port 8080 by default).

3. Add plugins and start

When Jenkins start select plugins and setup them after that restart Jenkins. Make sure Robot Framework plugin is installed.

4. Create and configure a new job in Jenkins

Select a Freestyle project and click on OK button. Enter Description from General tab. Select Git in Source Code Management tab, provide Repository URL and test it. In Build tab select Execute Windows batch command if you are running in Windows. Provide commands in Command box and Save it.

Windows batch command
robot_project_folder_location_drive:
cd robot_project_folder_location
robot -t test_name test_suite_name
echo BuildCompleted

5. Build - Robot Framework

From Jenkins project, select Build Now from drop down list, automation script should run when Robot project is building. Also robot reports should be available after successful build.

6. Robot Framework Reports

From Jenkins project configuration and navigate to Post Build Actions tab, click on Add post-build action button drop down list select Publish Robot Framework test results. Than provide location of robot test results file location in Directory of Robot Framework test results field and Save it. Build again to validate robot test results.

7. To overcome Opening Robot Framework report failed error in HTML reports

Search for Jenkins security policy. Go to JENKINS wiki/Configuring Content Security Policy navigate to Implementation section and copy code given in Unset the header: section. Than move to Jenkins > Manage Jenkins > Script Console > Paste copied code and click on Run button. If Result shown below than it is successful. Build again and click on robot results html links and observe that instead of error reports are shown.

Configure Version Control System Git in Eclipse for Robot projects

1. Create an account in Github

Go to https://github.com/ signup for an account. If you already have account than sign in.

2. Sign in and create a new repository

Create a new repository for your Robot project and remember the repository URI.

3. Git Perspective in Eclipse

Open Eclipse and navigate to Window -> Open Perspective -> Git.

4. Clone Repository in Eclipse

From Git Repository select Clone Repository, provide git repository URI and credential information in Source Repository window. Specify Branch and save it.

5. Share Project in Eclipse

In Eclipse, navigate to Project > Team > Share Project and share newly added repository.

6. Commit and Push from Eclipse

In Eclipse from Git Perspective select files for Staging, provide commit message and click on Commit and Push button.

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.

Install Robot Framework

1. Check prerequisite of Robot Framework

Write from command line
    python --version

Output showed installed python version.

Write from command line
    pip --version

Output showed installed pip version.


2. Install Robot Framework

Go to https://robotframework.org/ and read instructions.

Write from command line
pip install robotframework

It will download and install Robot Framework.


If required to uninstall already installed Robot Framework.

Write from command line
pip uninstall robotframework


If reinstalled right after uninstalling it than it will be installed from cache library.

To install a fresh copy write from command line
pip install --no-cache-dir robotframework


In order to upgrade installed Robot Framework, write from command line
pip install --upgrade robotframework


In order to install a specific version of Robot Framework, write from command line
pip install robotframework==2.9.2


3. Check installed Robot Framework

Write from command line
pip freeze

Output will show all python library installed list.

Write from command line
pip list

Output will show all python library installed list in a tabular form.

Write from command line
pip show robotframework

Output will show Robot Framework details.

Write from command line
pip check robotframework

Output will show Robot Framework requirement status.

Install Python on Windows

1. Check if Python is already installed

Write from command line
python --version

Shown warning will be, 'python' is not recognized as internal or external command

2. Download Python

From browser got to https://www.python.org/downloads/ and download it.

3. Install Python

Click Install now after successfully download the exe file. When installing it make sure to select Add Python to PATH checkbox.

4. Validate if Python is installed properly

Exit from current command window and open a new one. Write from command line,
python --version

Output should show python installed version.

If python version not shown than check environment variables in PC.

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

5. Validate if pip is installed properly

Write from command line
pip --version

Output should show pip installed version (it is automatically installed with python).

If pip version not shown than go to https://pip.pypa.io/en/stable/installing/ and check instructions given there. From command line
          python get-pip.py

6. Test installed python

Write from command line write
         python

Than enter
         2+2

Output should show summation result. To get out python window press Ctrl + z.

7. If required to Uninstall, Repair or Modify installed python

Navigate to previously downloaded python exe file and run it. It should provide three options to Modify, Repair and Uninstall.

Tuesday, December 10, 2019

Robot Framework skeleton

  • Variable
    • scalar
    • array type
    • array with item name
  • Keywords (method or function like)
  • Settings 
    • Setup (test suite and test case)
    • Teardown (test suite and test case)
  • Tag
    • Default Tag
    • Set Tag
    • Remove Tag

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.

Tuesday, May 20, 2014

Usability hack

User introduction:
I am a facebook user, I spend quality time here. I really enjoy reading blog posts. My friends have same habits like me. I and my friends share share blog posts from various famous blogs to share common interests and interact with each other. Its a regular practice of my to read posts in blogs and share them in facebook for my friends.

User story:
As an user I should be able to view posts which are shared by my facebook friends, in my facebook news feed. When I click on post link it take me to browser which navigate me to that blog post page.

User expectation:
After I click on post link in my facebook news feed I expect it to open in respected application installed in my phone. For example, Business insider blog post should open in installed application of BI android in my phone. But it takes me to browser and then to that link.


User experience findings:
- User uses an Android smart phone
- User have facebook, browser, business insider android applications installed in his/ her phone
- He/ she is a frequent user of internet, smart phone, facebook and business insider
- User goes to blog post from Facebook
- User share posts in Facebook from BI
- User expect better communications between installed applications of his/ her Android phone

User experience report:
- User performing a flow as follows,
  1. Browsing facebook news feed
  2. Going to browse blog post shared in facebook
  3. After reading the post in BI user want to share it in facebook
- User don't like to log in between as its his/ her own phone
- If user performing the full flow in browser with all logged in scenario than user is satisfied
- User finding a bottle neck to perform the full flow within installed applications
- The communication between applications in Android phone need to be improved
- Browser is successful to satisfy the user