Pages

Sunday, January 24, 2016

Test Automation interview questions ~ Software Testing

Test Automation interview questions ~ Software Testing



http://bhanupratapcorejavaprogramming.blogspot.in/

All Kind Of locators in selenium

driver.findElement(By.xpath("(//input[@type='checkbox'])[position()=3]")).click();
driver.findElement(By.xpath("(//input[@type='checkbox'])[last()-1]")).click();
driver.findElement(By.xpath("(//span[@class='hit'])[last()]")).getText();
/**
* To locate last checkbox, You can use It as bellow.
*/

driver.findElement(By.xpath("//input[@type='checkbox'])[last()]"));
driver.findElement(By.xpath("td[contains(text(),'Dog')]/following-sibling::td/input[@type='checkbox']"));

/**
* preceding-sibling Here Is reverse condition. Checkbox comes first and
* value text comes last so concept Is same but we have to use word
* preceding-sibling In XPath as bellow.
*/
driver.findElement(By.xpath("//td[contains(text(),'Cow')]/preceding-sibling::td/input[@type='checkbox']"));

/**
* We can use window().getSize() method to get size of window.
*/

driver.manage().window().getSize().getHeight();
/**
* WebDriver getPosition method used to get window position x,y
* coordinates.
*/

System.out.println("Window position X coordinates Is -> " + driver.manage().window().getPosition().getX());
System.out.println("Window position Y coordinates Is -> " + driver.manage().window().getPosition().getY());
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.switchTo().window("windowName");
Alert alert = driver.switchTo().alert();
driver.navigate().forward();
driver.navigate().back();

/**
* Drag Drop of element
*/
WebElement element = driver.findElement(By.name("source"));
WebElement target = driver.findElement(By.name("target"));
Actions action = new Actions(driver);
action.dragAndDrop(element, target).build().perform();
(new Actions(driver)).dragAndDrop(element, target).perform();

driver.findElement(By.xpath("//a[starts-with(@href, 'mylink')]"));
driver.findElement(By.xpath("//a[contains(@href, 'key_word')]"));
driver.findElement(By.xpath("//input[starts-with(@id, 'text-')]"));
driver.findElement(By.xpath("//span[starts-with(@id, 'revit_form_Button_') and ends-with(@id, '_label']"));
driver.findElement(By.xpath("//span[starts-with(@id, 'revit_')][@class='dijitButtonText']"));
driver.findElement(By.xpath("//span[starts-with(@id, 'revit_')]"));

Set<String> windows = driver.getWindowHandles();
Iterator<String> itr = windows.iterator();

/**
* patName will provide you parent window
*/
String patName = itr.next();

/**
* chldName will provide you child window
*/
String chldName = itr.next();

/**
* Switch to child window
*/
driver.switchTo().window(chldName);

/**
* Do normal selenium code for performing action in child window
*/

/**
* To come back to parent window
*/
driver.switchTo().window(patName);

driver.findElement(By.xpath("")).getAttribute("name");
driver.findElements(By.xpath("")).get(8);

driver.findElement(By.id("")).getText();
driver.manage().getCookies();

driver.findElement(By.xpath("//*[@id='c_pass']")).sendKeys(Keys.ENTER);

Select select = new Select(driver.findElement(By.xpath("")));
List<WebElement> opt = select.getOptions();
System.out.println(opt.get(3));
select.selectByIndex(0);
select.selectByValue("test");
select.selectByVisibleText("test");

String CurrentUrl = driver.getCurrentUrl();
System.out.println(CurrentUrl);
String PageSource = driver.getPageSource();
System.out.println(PageSource);

int rowCount=driver.findElements(By.xpath("//table[@id='DataTable']/tbody/tr")).size();
        System.out.println(rowCount);
int columnCount=driver.findElements(By.xpath("//table[@id='DataTable']/tbody/tr/td")).size();
System.out.println(columnCount);

List<WebElement> oRadioButton = driver.findElements(By.name("toolsqa"));

// Create a boolean variable which will hold the value (True/False)

boolean bValue = false;

// This statement will return True, in case of first Radio button is
// selected

bValue = ((WebElement) oRadioButton.get(0)).isSelected();

// This will check that if the bValue is True means if the first radio
// button is selected

if (bValue = true) {

// This will select Second radio button, if the first radio button
// is selected by default

((WebElement) oRadioButton.get(1)).click();

} else {

// If the first radio button is not selected by default, the first
// will be selected

((WebElement) oRadioButton.get(0)).click();

}


 String sValue = "Lakshay Sharma";

 System.out.println(" What is your full name");

 Assert.assertEquals("Lakshay Sharma", sValue);
 Assert.assertTrue(true);
 Assert.assertTrue(true, "login is done");
}