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

Browser pop-ups or file uploads can be handled using Java API Robot class

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

Thursday 1 May 2014

What is the primary feature of the Web Driver?

The primary new feature in Selenium 2.0 is the integration of the WebDriver API. WebDriver is designed to provide a simpler, more concise programming interface in addition to addressing some limitations in the Selenium-RC API. Selenium-WebDriver was developed to better support dynamic web pages where elements of a page may change without the page itself being reloaded. WebDriver’s goal is to supply a well-designed object-oriented API that provides improved support for modern advanced web-app testing problems.

What is Regression Tesing?

Regression testing is a type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes such as enhancements, patches or configuration changes, have been made to them.
The intent of regression testing is to ensure that a change such as those mentioned above has not introduced new faults. One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software
Common methods of regression testing include rerunning previously completed tests and checking whether program behaviour has changed and whether previously fixed faults have re-emerged. Regression testing can be performed to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.