Saturday, November 30, 2013

Selenium webdriver Interview Questions & Anwser

Q 1. Can we create multiple instances with selenium web driver with same Browser?

Ans: Yes, We can Create multiple Instances with selenium web driver.

ex: package Sample Package;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Class1
 {
public static void main(String[] args) throws InterruptedException
{
//Create 1st instance for IE
System.setProperty("webdriver.ie.driver", "C:\\Selenium Automation\\IEDriverServer.exe");
InternetExplorerDriver ds1 = new InternetExplorerDriver();
ds1.get("http://google.co.in");
Thread.sleep(3000);
ds1.findElement(By.name("q")).sendKeys("software testing");
Thread.sleep(3000);
ds1.findElement(By.name("btnK")).click();
//Create 2nd instance for IE
System.setProperty("webdriver.ie.driver", "C:\\Selenium Automation\\IEDriverServer.exe");
InternetExplorerDriver ds2 = new InternetExplorerDriver();
ds2.get("http://www.flipkart.com/");
Thread.sleep(3000);
ds2.findElement(By.name("q")).sendKeys("Computers");
Thread.sleep(3000);
//Create 3rd instance for IE
System.setProperty("webdriver.ie.driver", "C:\\Selenium Automation\\IEDriverServer.exe");
InternetExplorerDriver ds3 = new InternetExplorerDriver();
ds3.get("http://google.co.in");
Thread.sleep(3000);
ds3.findElement(By.name("q")).sendKeys("software testing");
Thread.sleep(3000);

Note: Create number of instances but once we run the program it will finish the 1st instance and 2nd instance then 3rd instance . it will not open multiple browsers at a time

Q2. How can we run my application on to different browesrs ?

Ans: By Creating different instances with different browser.

package SamplePackage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

import BackUpprograms.webdriver_Reg;

public class Class1 {

public static void main(String[] args) throws InterruptedException
{
// Create an Instance for IE browser
System.setProperty("webdriver.ie.driver", "C:\\Selenium Automation\\IEDriverServer.exe");
InternetExplorerDriver ds1 = new InternetExplorerDriver();
ds1.get("http://google.co.in");
Thread.sleep(3000);
ds1.findElement(By.name("q")).sendKeys("software testing");
Thread.sleep(3000);
ds1.findElement(By.name("btnK")).click();

// Create an Instance for Firefox browser
WebDriver ds = new FirefoxDriver();
ds.get("http://google.co.in");
Thread.sleep(3000);
ds.findElement(By.name("q")).sendKeys("software testing");

}
}



No comments:

Post a Comment

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...