Click a link

  • 29
    Aug

    Click a link

    private void clickLink(String element, int wait) throws Exception { WebElement myLink = (new WebDriverWait(driver, wait)).until(ExpectedConditions.presenceOfElementLocated(By.linkText(element))); driver.findElement(By.linkText(element)).click(); }

    Read More
  • 29
    Aug

    handling WebDriver exceptions before test execution with TestNG

    One can use static initialization block to catch exception like this: public class A { static final WebDriver wd; static { try { wd = new FirefoxDriver(); } catch...

    Read More
  • 29
    Aug

    Softasserts in TestNG

    There are two types of Assert: 1. Hard Assert => script execution stops (on failure of such asserts) 2. Soft Assert => script execution continues (on failure of such...

    Read More
  • 28
    Aug

    Set functions in Java

    package Set; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.Spliterator; public class SetsExamples { static Set initSet1() { Set set1 = new HashSet(Arrays.asList(11,12,13,14,15)); return set1; } static...

    Read More
  • 24
    Aug

    Get free disk space from Java program

    Following code snippet can be used to find the free disk space on local file system import java.io.File; public class FreediskspaceinGB { public static void main(String args) { File...

    Read More
  • 24
    Aug

    kill a running process from your java program (in Windows)

    Following code snippet can be used to kill a process on windows system package practice; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class WindowsProcessKiller { // command used to...

    Read More
  • 23
    Aug

    Code snippet to execute dos command and process it’s result – (Find open TCP Ports on local system)

    package practice; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class freeport { public static void main(String args) { try { Runtime rt = Runtime.getRuntime(); String command = “netstat -an”;...

    Read More
  • 22
    Aug

    Generate HTML / XML logs with log4j

    In order to generate log4j logs in XML or HTML format one can configure log4j.properties file with following properties: log4j.rootLogger=DEBUG, CA log4j.appender.CA=org.apache.log4j.ConsoleAppender log4j.appender.CA.layout=org.apache.log4j.HTMLLayout log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x –...

    Read More
  • 22
    Aug

    Configure log4j to write logs to local filesystem – FileAppender

    Three main components that needs to be configured in log4j.properties file are: 1. logger => log messages. 2. appender => specifies the output destination like console or a file....

    Read More
  • 21
    Aug

    How to configure your log4j.properties file in Eclipse

    Step 1: Create a log4j.properties file (eg.) # Set root category priority to INFO and its only appender to CONSOLE. log4j.rootCategory=INFO, CONSOLE #log4j.rootCategory=INFO, CONSOLE, LOGFILE # Set the enterprise...

    Read More