Wednesday, 21 May 2014

Alert handling in Selenium WebDriver

try {
        Alert alert = webDriver.switchTo().alert();

        // check if alert exists
        // TODO find better way
        alert.getText();

        // alert handling
        log().info("Alert detected: {}" + alert.getText());
        alert.accept();
    } catch (Exception e) {
    }

The problem is that if there is no alert on the current state of the web page, it waits for a specific amount of time until the timeout is reached, then throws an exception and therefore the performance is really bad.
 public void checkAlert() {
    try {
        WebDriverWait wait = new WebDriverWait(driver, 2);
        wait.until(ExpectedConditions.alertIsPresent());
        Alert alert = driver.switchTo().alert();
        alert.accept();
    } catch (Exception e) {
        //exception handling
    }
}

Saturday, 10 May 2014

What is the difference between Thread.Sleep() and Selenium.setSpeed()?

Selenium.setSpeed:
1. takes a single argument in string format
ex: selenium.setSpeed(“2000″) – will wait for 2 seconds
2. Runs each command in after setSpeed delay by the number of milliseconds mentioned in setSpeed.
Thread.sleep:
1. takes a single argument in integer format
ex: thread.sleep(2000) – will wait for 2 seconds
2. Waits for only once at the command given at sleep.

Is it possible to use Selenium for multi-user Load Testing?

Yes, but it requires a LOT of hardware. We recommend you check out BrowserMob, which does load testing with real browsers and is powered by Selenium.

Thursday, 8 May 2014

What are the features of TestNG?

 What are the features of TestNG?
TestNG is a testing framework designed to simplify a broad range of testing needs, from unit testing (testing a class in isolation of the others) to integration testing (testing entire systems made of several classes, several packages and even several external frameworks, such as application servers). You can use test suite,annotations, automatically generation of report and much more.

What are desired capabilities of Selenium-WebDriver?

What are desired capabilities?

Desired Capabilities help to set properties for the Web Driver. A typical use case would be to 
set the path for the Firefox Driver if your local installation doesn't correspond to the default 
settings.

Click here read In detailed about desired capabilities

Saturday, 3 May 2014

Downloading files can be automated by using a simple java program with Selenium as well

Selenium is not a tool for saving attachments etc. But  you can  solve your problem. Simple example:

    @Test
    public void downloadFromIbmlalala() throws AWTException {   
        driver = new FirefoxDriver();
        driver.get(baseUrl);
        try {
        WebElement buttonFromPage = driver.findElement(By.name("verify"));
        buttonFromPage.click();
        (new Robot()).keyPress(java.awt.event.KeyEvent.VK_ENTER);
    } catch (AWTException e) {
        e.printStackTrace();
    }
    }

and attachment is saved in default location. If it’s a good idea to save attachments in automations testing? Don’t think so… But it can be done