Showing posts with label Testing interview question. Show all posts
Showing posts with label Testing interview question. Show all posts

Sunday, August 19, 2012

Frequently Used Selenium Commands


}selenium.start() - Takes you to the location where selenium server is and runs the server.
}selenium.open() - Takes you to the provied URL/Website address.
}selenium.getTitle() - Get the title of the current browser window.
}selenium.windowFocus() - Get the focus on the current window.
}selenium.windowMaximize() - Maximizes the current window.
}selenium.close() - Close the session

Selenium Commands – “Selenese”


ActionsAccessors, and Assertions.
}Actions are commands that generally manipulate the state of the application. They do things like “click this link” and “select that option”. If an Action fails, or has an error, the execution of the current test is stopped.
Øselenium.click("id=gbztms");
Øselenium.select("id=citytravel_city", "label=Bangalore");
}Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”. They are also used to automatically generate Assertions.
ØString Google = selenium.getTitle(); 
Øselenium.type("id=gbqfq", Google);
}Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this checkbox is checked”.
ØassertTrue(selenium.isElementPresent("id=lga"));
ØassertEquals(selenium.getTitle(), "Google");

Selenium Example Using Junit: Home Page Test


Junit example Using Selenium

import static org.junit.Assert.*;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class HomePageJunitTest {

Selenium selenium;

@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexploreproxy", "https://www.google.co.in/");
selenium.start();
}

@Test
public void testJunit() throws Exception {
selenium.open("/");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (selenium.isElementPresent("id=gbqfq")) break; } catch (Exception e) {}
Thread.sleep(1000);
}

selenium.type("id=gbqfq", "selenium hq");
Thread.sleep(2000);
selenium.click("//span[@class=\"gbqfi\"]");
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (selenium.isElementPresent("link=Selenium - Web Browser Automation")) break; } catch (Exception e) {}
Thread.sleep(1000);
}

boolean res=selenium.isElementPresent("link=Selenium - Web Browser Automation");
assertEquals(res, true);
boolean res2=selenium.isTextPresent("What is Selenium? Selenium automates browsers.");
assertEquals(res2, true);
}

@After
public void tearDown() throws Exception {
selenium.stop();
}
}

Saturday, August 18, 2012

Advantages and Disadvantages of selenium automation tool


Advantages of Selenium

    1. Open Source
    2. Supports all browsers like IE, Firefox, Mozilla, Safari
    3. Supports all Operating Systems.
    4. Supports all programming languages Java,Ruby,C# and Python.
    5. Run multiple tests at a time.

Disadvantages

  1. Identifying the locators that support common attributes like id, names etc as well as XPATH, javascript DOM and others (Use firebug for finding the locators)
  2. Detailed results are not available
  3. Selenium IDE does not supports loop and data driven testing
  4. No Option to verify the images.


What is the need of Test automation for web application

  1. Frequent regression testing
  2. Rapid feedback to developers
  3. Virtually unlimited iterations of test case execution
  4. Support for Agile and extreme development methodologies
  5. Disciplined documentation of test cases
  6. Customized defect reporting
  7. Finding defects missed by manual testing