What are the different
exceptions you get when working with WebDriver?
·
InvalidSwitchToTargetException [The
frame or window target to be switched doesn’t exist.]
·
NoSuchElementException
·
NoSuchFrameException
·
TimeoutException
SessionNotFoundException
how to launch Default browser through
WebDriver?
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class Demo {
public static void main(String[] args) {
ProfilesIni prof = new ProfilesIni();
FirefoxProfile p = prof.getProfile("default");
WebDriver driver = new FirefoxDriver(p);
driver.get("http://demo.actitime.com/login.do");
}
}
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class Demo {
public static void main(String[] args) {
ProfilesIni prof = new ProfilesIni();
FirefoxProfile p = prof.getProfile("default");
WebDriver driver = new FirefoxDriver(p);
driver.get("http://demo.actitime.com/login.do");
}
}
Diff
waits in Selenium?
driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);
Thread.sleep(3000);
WebDriverWait w=new
WebDriverWait(driver,1);
w.until(ExpectedConditions.titleContains("actiTIME - Enter Time-Track"));
How
do you take screen shot?
FileUtils.copyFile(((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE),new
File("d:/abcd.png"));
How to add it in to result window
WebDriver
driver= new FirefoxDriver();
driver.get("http://www.gmail.com");
FileUtils.copyFile(((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE),new File("d:/abcd.png"));
Reporter.log("<img src='d:/abcd.png'></img>");
driver.get("http://www.gmail.com");
FileUtils.copyFile(((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE),new File("d:/abcd.png"));
Reporter.log("<img src='d:/abcd.png'></img>");
in eclipse Goto Run->Run ->Run Configurations-> Argument
tab -> VM arguments
type following code
-Dorg.uncommons.reportng.escape-output=false
-Dorg.uncommons.reportng.escape-output=false
How
to enter date in date field using java script in web Driver?
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.get("http://www.yatra.com/");
JavascriptExecutor
js=(JavascriptExecutor)driver;
js.executeScript("document.getElementById('datePickerDepart_dom1').value='18/07/2013'");
How
to take complete screen shot of the application and screen shot of required
element?
WebDriver driver=new
FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.get("http://www.yatra.com/");
File
f=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(f,new File("d:/FullImage.png"));
//photo of which element?
WebElement flights=driver.findElement(By.id("btnFindFlights"));
int
x=flights.getLocation().getX();
int
y=flights.getLocation().getY();
int
width=flights.getSize().width;
int
height=flights.getSize().height;
ImageIO.write(ImageIO.read(f).getSubimage(x,y,width,height),"png",f);
FileUtils.copyFile(f,new File("d:/flight.png"));
1. Suppose we have multiple tabs like in
TestNG(Failed Tests,Run Last-test etc..)how will u handle it?
if a tab is inside a page then it will be
like clicking on Link, but web driver cant handle tabbed browser
2. How to check whether the check-box or
radio is checked or not?What is the method?
isSelected
3. In a drop-down we have many options out of
which i want to write xpath for particular option,How will u write?
//select[@name='somename]/options[1]
4. We have two similar hidden elements with
same attribute how can u write xpath?
we
should use style attribute
contains(@style,'display: none') --> for invisible elements
contains(@style,'display: block') --> for
visible elements
5. How to handle untrusted connection in
selenium-2?
it is automatically suppressed in Mozilla,
for other we can use java script
6. Using AND,OR operation how can u write
xpath for dynamic elements?
//a[text()>6 and text()<9]
//a[text()>6 or text()<9]
7. How to invoke JDBC in selenium-2?
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ) ;
Connection conn = DriverManager.getConnection(
"jdbc:mysql://server","un","pwd" ) ;
Statement stmt = conn.createStatement() ;
ResultSet
rs = stmt.executeQuery( "SELECT * FROM lk_ask_queries" ) ;
String res=rs.getString(1) - FIRST COLUMN
rs.close() ;
stmt.close() ;
conn.close() ;
8. How to automate windows or android mobile
devices?
its big story..
9. How many test cases u automate per day?
4 to 5
10. Explain Automation Test life cycle?
Please see the class notes
11. I have a server message(Report generated
successfully) but i need only report,how u write the script?
String
sMsg=driver.findElement(By.id()).getText();
System.out.println(sMsg.split("
")[0]);
12. Why u call it as IDE?What actually mean
IDE?
Its Integrated development environment
because it conatins
Editor,Debugger,Intelli-sense coding features
13. How to handle Default Browser in
Selenium-2?
you mean opening Browser with default
profile?
ProfilesIni prof = new ProfilesIni();
FirefoxProfile p =
prof.getProfile("default");
WebDriver driver = new FirefoxDriver(p);
14. What is bitmap Comparison?why we use it?
use to compare expected and actual images
15. will we use regular expressions?if so
why?if not why?
we can use * in xpath for dynamic element
1. How do u compare bitmap in selenium
webdriver?
We use "TakesScreenshot" and ImageIO classto comapare bitmap
2. How do u find whether checkbok is there or
not?
findelement with try catch
3. Write a code to connect to a database?
Class.forName(
"sun.jdbc.odbc.JdbcOdbcDriver" ) ;
Connection conn = DriverManager.getConnection(
"jdbc:mysql://server","un","pwd" ) ;
Statement stmt = conn.createStatement() ;
ResultSet rs = stmt.executeQuery( "SELECT * FROM
lk_ask_queries" ) ;
String res=rs.getString(1) - FIRST COLUMN
rs.close() ;
stmt.close() ;
conn.close() ;
4. What is Agile method?
its
a type of SDLC and it is based on iterative and incremental development
5. What is scrum in agile method?
its a meeting
6. What are the templates of webdriver?
NO
7. How to capture the images in selenium
webdriver?
We use "TakesScreenshot"
8. Why not regular expressions in selenium-2?
xpath is powerfull
1. How to get the partial server message
using selenium webdriver?
it depends on how the server message is
displayed,need more info on server message
2. I want to scroll the webpage?(30%,80%)
import
org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test1 {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("http://news.google.co.in/nwshp?hl=en&tab=wn");
JavascriptExecutor js = (JavascriptExecutor)driver;
Object o=js.executeScript("return document.body.scrollHeight");
int i=Integer.parseInt(o.toString());
System.out.println("Total height of the page:"+i+" pixels");
int percentage=30;
i=(i*percentage)/100;
js.executeScript("javascript:window.scrollTo(0,"+i+")");
System.out.println("Scrolling to "+percentage+"%");
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test1 {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("http://news.google.co.in/nwshp?hl=en&tab=wn");
JavascriptExecutor js = (JavascriptExecutor)driver;
Object o=js.executeScript("return document.body.scrollHeight");
int i=Integer.parseInt(o.toString());
System.out.println("Total height of the page:"+i+" pixels");
int percentage=30;
i=(i*percentage)/100;
js.executeScript("javascript:window.scrollTo(0,"+i+")");
System.out.println("Scrolling to "+percentage+"%");
}
}
3. Want to take screenshot in a webpage?(Full or Part of it in a page)
WebDriver driver=new FirefoxDriver();
driver.get("http://news.google.co.in/nwshp?hl=en&tab=wn");
File f = ((TakesScreenshot)driver).
driver.get("http://news.google.co.in/nwshp?hl=en&tab=wn");
File f = ((TakesScreenshot)driver).
getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(f, new File("d:/abc.jpg"));
FileUtils.copyFile(f, new File("d:/abc.jpg"));
4. When do we go for automation?
For long term project having more
regression cycle and app is stable
5. I have 50 testcases,out of which are all u go for automating it?
regression
6. What is Jmeter?where do u use it?
its a load testing tooll, can be used to
test JDBC database connections, FTP, LDAP, Webservices, JMS, HTTP, generic TCP
connections and OS Native processes
7. Suppose i have RFE in an existing application,How do u automate it?
NO
8. What is the difference between QTP and Selenium?
QTP is proprietary software of HP, can
automate any type of app, uses VBS
Selenium open source, only for web app, uses java/python/ruby/C#
Selenium open source, only for web app, uses java/python/ruby/C#
9. Technical challenges in Selenium?
Cant work on existing browser, handling
window popups, cant handle tab browser....
10. What is the difference that Selenium do extra than QTP?
parallel execution (GRID), supports all
browsers, platform independent...
11. Difference between REaltive and Absolute Xpath?
relative is xpath by
attribute (//)
absolute is xpath by position(/)
12. Types of locators?
8 types...id,name....
absolute is xpath by position(/)
12. Types of locators?
8 types...id,name....
13. All the popups u taught in the class.
14. DIfference between Xpather and Xpath Checker?
they are just diff tools to check the xpath
1. How to get the partial server message
using selenium webdriver?
what is server message? how it displ
2. I want to scroll the webpage?(30%,80%)
3. Want to take screenshot in a webpage?(Full
or Part of it in a page)
4. When do we go for automation?
5. I have 50 testcases,out of which are all u
go for automating it?
6. What is Jmeter?where do u use it?
7. Suppose i have RFE in an existing
application,How do u automate it?
8. What is the difference between QTP and
Selenium?
9. Technical challenges in Selenium?
10. What is the difference that Selenium do
extra than QTP?
11. Difference between REaltive and Absolute
Xpath?
12. Types of locators?
13. All the popups u taught in the class.
14. DIfference between Xpather and Xpath
Checker?
15. How to identify 2 buttons (every thing
same) but one is invisible?
xpath =>
//input[@style="display:none;"]
//display:block
//input[@style="visibility:hidden"] //visibility:visible
Star mark
Selenium WebDriver
------------------
1)How to specify some delay in loading
WebPage?
2)How to handle Confirmation Pop-Up?
3)What is the difference between TestNG and
Junit?
4)Give the overview of your frame-work?
5)What is your role in your current project?
6)What is the benefit of using TestNG?
7)What is Selenium IDE and Selenium RC?
8)What is WebDriver?
9)Can you inspect an WebElement with FireBug
if the Browser is opened by WebDriver?
10)Can you open CMD using WebDriver?