Sunday, October 12, 2025

Test APIs in Playwright (Mock & Block)

   Perform following steps,

  1. Add the request listener at the very top (before going to the page)
    • page.on('request',request => {console.log(request.method(), request.url()) })
    • This step is to find out requests in the page
    • Similar to network tab in web developer tool of the browser
  2. Keep the page alive untill all requests are done
    • page.waitForLoadState('networkidle')
    • This step to see all requests in the page
    • Similar to network tab in web developer tool of the browser
  3. Need route function to mock it
    • page.route('requestURL', (route) => {

route.fulfill({     // fulfill to mock data, usually GET

status: 200,    // this is the status code the API will get

contentType: 'application/json',    // should be similar as it expected

body: JSON.stringify(mock_json_data_object)

}) 

})

    • Usefull for negative test cases
    • Usefull for testing micro-services
      4. Need route function to block it
    • page.route('**/*', (route) => { //URL is regular expression to match all

if (route.request().resourceType() === 'image'){    //request for images

return route.abort()}  //aborting image requests

return route.continue()    // continue if not image request

}) 

})

    • Usefull to speed up test process

Test APIs in Playwright (API in E2E test)

 Perform following steps,

  1. Import {APIRequestContext} from '@playwright/test'
  2. Declare a variable to get the API context
    • let apiContext: APIRequestContext;
  3. User before all to initialize the API context
    • test.beforeAll (async ({ playwright } )=> { 

      apiContext = await playwright.request.newContext({ 

      baseURL: 'api.base.URL', 

      extraHTTPHeaders: { 

      'Accept': 'application/json', 

      'Content-Type': 'application/json', 

      }) 

      })

  4. Destroy the context after all
    • test.afterAll ( async ({ }) => { 

      await apiContext.dispose(); 

      })

  5. Make request in test as required
    • await apiContext.post('URL', {data: payLoad})

Friday, October 10, 2025

Test APIs in Playwright (with E2E tests)

 Perform following steps,

  1. In playwright.cofig.ts, create a project
    • Provide test name:
    • Provide testDir:
    • In use:
      • Provide baseURL:
      • Provide extraHTTPHeaders:
        • 'Accept':
        • 'Content-Type':
  2. In test, call back request instead of page
  3. In request.METHOD('URL')
    • request.get('URL')
    • request.post('URL', {body})
  4. Get the response in a variable
    • const response = request.get('/products')
    • For status, response.status()
    • For header, response.headers()
    • For body, response.body()
    • For JSON, response.json()
    • Also others availble
  5. For assertions, use expect
    • For status, expect(response.status()).toBe(200)
    • For header content type match
      • expect(response.headers()['conten-type']).toContain('application/json')
  6. Get the response body in a variable
    • const responseBody = response.json()
  7. For assertions in the body
    • expect(responseBody).toHaveProperty('success', true)
    • expect(responseBody).toHaveProperty('data')
    • expect(Array.isArray(responseBody.data)).toBe(true)
  8. Run test project-wise, run with the following command
    • npx playwright test --project project_name_given_playwright.config

Friday, September 26, 2025

Reuse authenticated browser state for others tests in Playwright

 Perform following steps,

  1. Create folder playwright/.auth outside tests
  2. Create folder setup inside tests
  3. Create a test file inside setup folder "file_name.setup.ts"
    1. Read userID and password from a file
    2. Login and write the storage state in user.json file
      • File directory will be "playwright/.auth/user.json"
    3. await page.context().storageState({path: above_dir_path_var})
  4. Create a project in playwright.config.ts
    • { name: 'auth-setup', testMatch: 'ts_file_name_of_auth_setup' }
  5. Add dependency and storage state in working project(s)
    • use: { ..., storageState: 'directory_of_user.json' }, dependencies: ['name_of_auth_project']

Thursday, September 25, 2025

Read from file and write to file

 Perform following steps,

  1. import path from 'path';
    • Need for path of files in order to access them
  2. import fs from 'fs';
    • Need for read and write on files
  3. In order to read or write, first we need to resolve the directory of the file
    • path.resolve(__dirname, 'directoryPath')
  4. For reading, need to parse before read (reading JSON file)
    • JSON.parse(fs.readFileSync(dirVar,'utf-8'))
  5. For writing, need to join the file name with directory (writing JSON file)
    • fs.writeFileSync( join(dirVar, 'filename'), JSON.stringify(contentVar) )

Saturday, September 20, 2025

MailSlurp configuration in order to test authentication flow

 Perform following steps,

  1. Create an account in mailslurp.com
  2. Go to Dashboard -> Developers
  3. Get the API access key
  4. Install the mailslurp client in the project
    • npm i --save mailslurp-client
  5. Create an environment file (if not created already)
  6. Create a new environment varriable in the ".env" (convension is to user all uppercase letters)
  7. Assign the mailslurp API access key value for the environment varriable
  8. Add the ".env" file in ".gitignore"
  9. Playwright run extension in VSCode does not read from the ".env" file. So in order to make it work we need to do followings
    1. Create a ".vscode" folder
    2. Create a file called "settings.json" (beware of typos)
    3. In the file create a entry for playwright environment\
    4. Assign the API access key value here
  10. Create a "utils" folder inside the "tests" folder
  11. Create a file called "email-utils.ts" in the folder
  12. Paste the mailslup code (javascript) provided and save
    • In the code a inbox is created with defaults
    • Do not forget to return the inbox at last, in order to use it
  13. Create a new test in playwright
    • import from utils
    • create inbox
    • console log the inbox (to verify its working)

Sunday, September 14, 2025

Start with Playwright (TypeScript)

 Perform following steps to start,

  1. Create a new folder
  2. Open terminal in that folder
  3. Enter command "npm init playwright@latest"
  4. Go through the selection as required
  5. Remember to choose TypeScript when presented
  6. From VSCode remove test example folder
  7. Remove example spec file
  8. Update the playwright configuration file
    • base URL
    • project
    • headless
  9. Create a new test.spec.ts file inside the tests folder (if tests folder is selected)
  10. Start the spec file with import
    • import {test, expect} from '@playwright/test'
  11. Start test function with callback
test ( 'Test case name', async({ page }) => {

 // your test actions and assertions

})

Thursday, October 22, 2020

Another fun cases to automate in Wordpress

 TC1: Validate all plans in plan and pricing page

  • Go to plan and pricing page
  • Validate availability of Personal plan
  • Validate availability of Premium plan
  • Validate availability of Business plan
  • Validate availability of eCommerce plan
  • Validate availability of Configure plan

TC2: Validate login functionality
  • Go to login page
  • Read username and password from a text file
  • Enter username and password
  • Validate successful login attempt

TC3: Validate logout functionality
  • Go to profile page
  • Try to logout 
  • Validate successful logout attempt

tfw_play.robot (Robot test suite file)
  • Add resource files
  • Configure suite setup and teardown
  • Perform TC1, TC2 and TC3

tfw_initial.robot (Robot resource file)
  • Provide site URL
  • Open browser
  • Set selenium times
  • Maximize window size

tfw_header_bar.robot (Robot resource file)
  • Get all locators
  • Navigate menu links

tfw_plan_price_page.robot (Robot resource file)
  • Get all plan type locators
  • Validate presence of different types of plans in the page

tfw_login_page.robot (Robot resource file)
  • Get all locators
  • Read username and password from text files
  • Provide username and password and try to login

tfw_loggedin_page.robot (Robot resource file)
  • Get locators
  • Verify successful login attempt
  • Try to logout

tfw_loggedout_page.robot (Robot resource file)
  • Get locators
  • Verify successful logout attempt

user_name.txt (Text file to read)
  • Provide username

user_password.txt (Text file to read)
  • Provide password

Git repository link: https://github.com/wasiqul

Wednesday, October 21, 2020

A fun case to automate cont.

A few month earlier I wrote an automation script in Robot framework which will go to bongobd and navigate to a specific section and play a video. Few days ago I tried to run it and found out it is failing. Upon further investigation I realize the whole section is removed from the site thus the locator is not able to find it and the whole case is failing. I decide to fix it to run it again.

When I was fixing it I feel the need to validate all category pages first so that I can find it in advance if any sections are missing or updated. Then search for the same video and play it. While updating I feel the need to redesign the code for the ease of maintenance, reusability and better understanding. So I decided to go for page object modelling (POM).

In order to design it in POM first I investigate which parts of the website is remaining the same across all pages so I can model them as page objects. Find out header navigation bar and footer are always remaining the same. So, created headerBar.robot and footer.robot objects.

After that as I am interacting with the search result page, I created another object called searchResult.robot and all my test cases were listed in bongo.robot like before. And also make sure that all validations are done here and no where else.

Project was running fine and notice that some actions need to taken at start and writing those action in test case file does not feel right to me. So, I created another object called initial.robot and call it upon setup. And put all locators and inputs in variable so future updates will be easy.

I know that there is still room for improvement but still I am satisfied with all changes I have done. I think it is much more maintainable and reusable than before.

Here is the git hub repository link,

github.com/wasiqul/robotframework_bongobd

Wednesday, July 22, 2020

What is testing? And how I test?

Akash Saha (Software QA professional) : 


In My opinion, when a person checks the usability,functionalities and components of a product before or after using it can be referred as testing. 

I always check if the product has the utilizable features for using it without any kind complications. If the outcome is not satisfactory users will not accept it positively. So,assuring the grade and quality as per requirements is my main goal in the process of testing. 


Shounak Banik (Software QA professional):


From my point of view, testing is to find out the progress of the execution of different components of a system. 

Firstly, I gather knowledge regarding feature which I am going to be tested. Secondly, I make strategy so that any of patterns of testing the feature will not be missed. Lastly, I start testing according to the checkpoints/ strategies those I make for testing. 


Wasiqul Huq (Software QA professional): 


Testing is learning with an objective. The objective can vary depending upon goal. Sometime we test to validate, sometime we test to choose, sometime we test to take a decision. 

I conduct experiments with test environment, test data and test cases. My experiment results guide me towards my objective. If my objective is to validate than I validate against requirement or industry standards. If my objective is to choose one solution among others than i compare and choose which will fit my purpose. If my objective is to take decision than I write down case details so I and others can judge my decision taken.


Saika Shahnaj (Software QA professional): 


I think testing is the combination of some process and steps that a tester need to follow to ensure a flawless system which meets the business and system requirements to fulfill clients’ satisfaction. 

When I test any system or specific module, at the very first I try to go through the requirements and understand each of the words. Then prepare a list of test cases that I can follow for a complete testing. The team discussion also helps a lot to resolves the confusions during test run.


Imran Khaled (Software QA professional): 


To me testing is setting up a standard which a client urges the most.

First of all, when I am assigned a feature or module to test I go through the documentation to understand the requirements. Then I plan out the testing in a way so that it meets all the requirements mentioned in the documentation. After planning I discuss the plan with manager to make sure I am not missing out on any scope of the documentation. This is the process of testing I go through while testing a module.

Sunday, February 2, 2020

A fun case to automate

Github repository link: https://github.com/wasiqul/robotframework_bongobd

Test Case Descritions: User will click the free content,load the content & play it

Detail steps,
Step 1: Open the Chrome browser
Step 2: Go to https://www.bongobd.com
Step 3: Click on Classic
Step 4: Scroll till Most Watched section
Step 5: Click on Ontore Ontore film link
Step 6: Watch advertisement
Step 7: Play the movie
Step 8: Watch the movie for first 1 minute
Step 9: Close the browser

Expected result: The script that automates the flow should work without any errors


Different types of Asserts in Robot Framework

1. Builtin library:
http://robotframework.org/robotframework/latest/libraries/BuiltIn.html
2. Selenium library:
https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html
3. Collections library:
http://robotframework.org/robotframework/latest/libraries/Collections.html

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();
          
     }
 }