Common tricks

  • 14
    Oct

    Inversion of control / Dependency injection — what is it?

    Assume you depend on two or objects to create a functional representation of “Add to cart” implementation.  This can be achieved traditionally via: create objects of all dependencies and...

    Read More
  • 05
    Sep

    AtomicInteger in Java

    Let’s create a simple multi-threaded program where every thread increments the shared count variable 4 times. So if there are two threads, after they finish count value should be...

    Read More
  • 04
    Sep

    How to select an option from “AutoComplete” text field

    Following code snippet demonstrates how to select an option from “AutoComplete” text field import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class...

    Read More
  • 04
    Sep

    How to automate with “ExpectedConditions” in Selenium WebDriver

    Return type for “ExpectedConditions.xxxx()” is generally falls under following categories: Alert Boolean WebElement List WebDriver Object Following code snippet demonstrates usage and validation based on return type. (ExpectedCondition testing...

    Read More
  • 04
    Sep

    kill a process via java program

    Following code snippet can be used to kill all running instances of Internet Explorer import java.io.IOException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class RerunAttemp { @Test public void...

    Read More
  • 03
    Sep

    find broken links on a webpage

    Following code snippet can be used to details of link and their working / not working (broken) details on a page package practice; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL;...

    Read More
  • 03
    Sep

    Running a TestNG case multiple time in a batch of two

    In order to execute a script via two threads and three times total, we can use following code snippet import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Assert; import org.testng.annotations.Test; public class...

    Read More
  • 03
    Sep

    dependsOnMethods() example in TestNG

    following code snippet shows example of dependsOnMethods function import org.testng.annotations.Test; public class TestNGExample { @Test(groups = { “Automation” }) public void driver() { System.out.println(“Initialize Browser”); } @Test(dependsOnMethods = {...

    Read More
  • 03
    Sep

    Resize window with Selenium WebDriver

    Following code snippet can be used to resize a browser window in selenium import org.openqa.selenium.Dimension;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;import org.testng.annotations.Test; public class testJavaScriptErrors { @Testpublic void testForFramesCount() throws InterruptedException {WebDriver driver...

    Read More
  • 03
    Sep

    Functions to execute javascript during WebDriver script execution

    Following generic code can be used to execute a JavaScript with Selenium WebdDriver import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class testJavaScriptErrors { @Test public void testForFramesCount()...

    Read More