Friday, February 14, 2025

Picocontainer library in cucumber framework

 PicoContainer is a lightweight, open-source dependency injection container for Java. Like other dependency injection containers, PicoContainer helps manage the dependencies between components in your application. It allows you to define how different parts of your application are connected and then automatically resolves these dependencies at runtime.


With PicoContainer, you can define components (objects) and their dependencies, and then let the container handle the creation and wiring of these components. This makes your code more modular and easier to maintain, as you can change dependencies without modifying the classes themselves. PicoContainer is known for its simplicity and small footprint, making it suitable for small to medium-sized projects.


Certainly! Here's an example of how PicoContainer can be used with Selenium for dependency injection in a test automation scenario:


```java

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.picocontainer.DefaultPicoContainer;

import org.picocontainer.MutablePicoContainer;


public class SeleniumTest {

    public static void main(String[] args) {

        MutablePicoContainer container = new DefaultPicoContainer();

        

        // Register WebDriver in the container

        container.addComponent(WebDriver.class, new ChromeDriver());

        

        // Register PageObject class

        container.addComponent(LoginPage.class);

        

        // Obtain an instance of the PageObject class from the container

        LoginPage loginPage = container.getComponent(LoginPage.class);

        

        // Use the PageObject in the test

        loginPage.open();

        loginPage.login("username", "password");

    }

}


class LoginPage {

    private WebDriver driver;

    

    public LoginPage(WebDriver driver) {

        this.driver = driver;

    }

    

    public void open() {

        driver.get("https://www.example.com/login");

    }

    

    public void login(String username, String password) {

        // Find and interact with login elements using the WebDriver

        driver.findElement(By.id("username")).sendKeys(username);

        driver.findElement(By.id("password")).sendKeys(password);

        driver.findElement(By.id("loginButton")).click();

    }

}

```


In this example, we are using PicoContainer to manage the WebDriver dependency in the `LoginPage` class. 

We register the WebDriver instance (in this case, a ChromeDriver) in the container, and then obtain an instance of the 

`LoginPage` class from the container. The `LoginPage` class depends on the WebDriver, and PicoContainer takes care of inje

cting this dependency when creating an instance of the `LoginPage` class. This approach promotes a cleaner and more maintainable

 codebase and allows for easy integration of the Selenium WebDriver with the Page Object pattern.

AI Tools for daily work

AI Tools for daily work


S.NO.

Tool

Uses

1.       

Aiease.ai

Free ai photo editor

 

2.       

Usestyle.ai

SEO

3.       

Lovo.ai

Voice

4.       

Numerous.ai

Excel

5.       

Dante.ai

Chatbots

6.       

Syllaby.io

Videos

7.       

10web.io

websites

8.       

1.      Decktopus.io, https://chatslide.ai/,

2.      Eraser.ai,

3.      Gamma.ai (this is amazing) ,

4.      https://app.pitch.com/ (this is amazing)

Slides, PPT

9.       

Rendernet.ai

Images

10.   

Questflow.ai

Automation

 

11.   

Vizard.ai

Vizard.ai is an AI-powered online video editor that helps users create social media videos from long-form videos. It uses AI to automatically identify engaging parts of a video and generate short clips. 

12.   

Vidyo.ai

Not free in India. Video to reel maker.

13.   

1.      Canva

2.      https://designer.microsoft.com

Image editing


Monday, June 13, 2022

Banking transactions terms in banking domain

 Banking transactions terms in banking domain

1. SEPA (Simplifying European Payment, IBAN is required for this).

2. SWIFT (International transfer)

3. BACS (A long-established UK Payment system Bacs stands for Banker’s Automated Clearing Services)

4. CHAPS (Clearing House Automated Payment System) - Same day UK payment (People usually use this for 10000+ British Pound transfer).



Sunday, February 14, 2021

Create a maven project in eclipse

1. Open eclipse tool->File->Other.







2. Click on Other->Select Maven->Click Next button.






3. Select the first checkbox (Skip archetype) What is an archetype






4. Enter Group id and Artificate id.





5. Your Maven project is created.








Saturday, January 2, 2021

Java 8 - Date and Time API

1. Get the Local Date 

package Java8;

import java.time.LocalDate;

public class DateTime {


public static void main(String[] args) {

dateTime dt = new dateTime();

LocalDate date = LocalDate.now();

LocalDate yesterday = date.minusDays(1);

LocalDate tomorrow = yesterday.plusDays(2);

System.out.println("Today date is : " + date);

System.out.println("Yesterday date is : " + yesterday);

System.out.println("Tomorrow date is: " + tomorrow);

}


}


output: 

Today date is: 2021-01-02

Yesterday date is: 2021-01-01

Tomorrow date is: 2021-01-03

Thursday, April 16, 2015

TestNG Annotations

This blog explains the execution procedure of methods in TestNG. It explains the order of the methods called. Here is the execution procedure of the TestNG test API methods with an example.

@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite


Tuesday, April 14, 2015

Read data from excel file-Sample Java code by using jxl.jar

Here i am sharing the sample java code for reading the data from cell values of MS Excel.

Prerequisite:

1.  Download jxl.jar, and add that your java build path. 
2.  Download testng.jar and add that your java build path. (not necessary)
3. Prepare excel sheet with your data. 

Below program is for login to the gmail.com by using username and password given in the sheet.

Here i am displaying sample format of excel sheet. 



Code:
import java.io.FileInputStream;

import jxl.Sheet;
import jxl.Workbook;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Data {
    private WebDriver driver;

    @BeforeClass
    public void setup()
    {
        driver = new FirefoxDriver();
    }

    @Test(description = "Read Gmail account")
    public void Login() throws Exception
    {
        FileInputStream fi = new FileInputStream("E:\\testemail.xls");
        Workbook w = Workbook.getWorkbook(fi);
        Sheet s = w.getSheet(0);
        System.out.println(s.getRows());
        driver.get("http://www.gmail.com");
        try {
            for (int i = 1; i < s.getRows(); i++) {
                // Read data from excel sheet
                String s1 = s.getCell(0, i).getContents();
                String s2 = s.getCell(1, i).getContents();
                driver.findElement(By.name("Email")).sendKeys(s1);
                driver.findElement(By.name("Passwd")).sendKeys(s2);
                driver.findElement(By.name("signIn")).click();
                driver.findElement(By.name("signout")).click();

            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    @AfterClass
    public void teardown()
    {
        driver.quit();
    }

}