java

  • 05
    Jul

    WebDriver notes

    Relationship between RemoteWebDriver and WebDriver (is not of a parent/child): =============================================================================== RemoteWebDriver implements WebDriver ChromeDriver extends RemoteWebDriver (& hence can be upcasted): ================================================================ ChromeDriver driver = new ChromeDriver(); //...

    Read More
  • 04
    Jul

    Properties parser in java

    import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; public class PropertiesParser { public static Map getProperties(final String fileName) { Properties p = new...

    Read More
  • 04
    Jul

    Browser Driver wrapper class for Selenium WebDriver

    import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.Formatter; import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import...

    Read More
  • 03
    Jul

    Selenium grid hub and nodes from command prompt

    java -jar selenium-server-standalone-2.53.0.jar -port 5002 -role hub java -Dwebdriver.ie.driver=C:\selenium\Backup_old\IEDriverServer_32.exe -jar selenium-server-standalone-2.53.0.jar -port 5001 -role node -hub http://127.0.0.1:5001/grid/register

    Read More
  • 03
    Jul

    try with resources in java

    The try-with-resources statement is a try statement that declares one or more resources. eg The try-with-resources statement ensures that each resource is closed at the end of the statement....

    Read More
  • 02
    Jul

    Memento design pattern with java

    Memento pattern is a behavioral design pattern. Memento pattern is used to rollback / restore a state of an object to a previous state. As required in application, this...

    Read More
  • 02
    Jul

    Reflection based dynamic object instantiation in java

    Step 1: ======== package AOPWithJavaReflection; public interface vehicle { public void drive1(int wheels); } Step 2: ========= package AOPWithJavaReflection; public class TwoWheeler implements vehicle { @Override public void drive1(int...

    Read More
  • 01
    Jul

    Chain of responsibility with Java

    Chain of Responsibility is behavioral design pattern that allows passing request along the chain of potential handlers until one of them handles request. The pattern allows multiple objects to...

    Read More
  • 28
    Jun

    Proxy factory example in Java Reflection

    ProxyFactory example: ====================== import java.lang.reflect.Proxy; public class ProxyFactory { public Object createWithBean(Object inBean) { Class ejbClass = inBean.getClass(); Class interfaces = ejbClass.getInterfaces(); BeanHandler handler = new BeanHandler( inBean );...

    Read More
  • 28
    Jun

    Declaring custom annotations examples

    Define your custom annotations ================ #1. Method Level ================= import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface PreDestroy { } #2. Type level ================ import...

    Read More