Home page

Thursday, December 11, 2014

Interview Questions - 1

1. Diff between junit and testNG
- Junit required @beforecalss and @afterclass
- TestNG don't required @beforeclass and @afterclass
- In Junit testcase grouping is not possible.
- In TestNG testcase grouping is possible.

2. Diff between java 1.6 and 1.7


3. Diff between interface and abstract class

- interface is not a class.
- All variables declared in interface are final by default
- Abstract class can have non-final variables
- All the members of the interface are public by default
- Abstract class's members can be public, private etc
- To use interface it is required to use "implements"
- To use abstract class it is required to use "extends"
- A single class can implements more than one interface
- A single class can extend only one abstract class

4. Diff between final and static

- Static variable can be declared only once
- Static variable/method can be used with class name only.
- Static method can use only static variable.
- Static variable can be modified.

- Final cannot have subclass
- Sub class methods cannot override final method
- Final variable can not be modified


5. Diff between assert, verify and wait for

- If verification through assert gets failed then testcase execution will be stopped.
- If verification through verify gets failed then also it will continue testcase execution.


6. Syntax of firefox driver

- Webdriver driver - new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("http://www.google.com/");

driver.manage().window().maximize();

7. Diff between webdriver and firefox driver

- WebDriver is an interfacce
- FirefoxDriver is the implementation.


8. Disable TestNG
- @Test(enabled = false) 

9. How to perform drag and drop in webdriver:
WebElement drag = driver.findElement(By.id("drag"));
webelement drop = driver.findelement(By.id("drop"));

Action builder = new Action(driver);
Action dragndrop = builder.clickAndHold(drag).movetoelement(drop).release(drop).build();
dragndrop.perform();

1. For element which need to be drag, first create variable of WebElement for that. WebElement drag = driver.findElement(By.id("drag"));

2. For element where need to be drop, first create variable of WebElement for that. webelement drop = driver.findelement(By.id("drop"));

3. Create object of the action class for driver object.[Action builder = new Action(driver);]
4. Create dragndrop object. Action dragndrop = builder.clickAndHold(drag).movetoelement(drop).release(drop).build();
5. dragndrop.perform();


10. How to take screenshot

classname = ClickScreenShot
  1.  }catch(Exception e){  
  2.   //For failure case
  3.      File shot = ((ClickScreenShot)driver).getScreenshotAs(OutputType.FILE);  
  4.      FileUtils.copyFile(shot, new File("C:\\failure.png"));  
  5.      
  6.   } 

No comments:

Post a Comment