1. What are the annotations used in TestNG?
@Test, @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeClass, @AfterClass,
@BeforeMethod, @AfterMethod
2. How do you read data from excel?
FileInputStream fis = new FileInputStream (“path of excel file”);
Workbook wb = WorkbookFactory.create (fis);
Sheet s = wb.getSheet (“sheetName”)
String value = s.getRow (rowNum).getCell (cellNum).getStringCellValue ();
3. What is the use of xpath?
It is used to find the WebElement in web page. It is very useful to identify the dynamic web elements.
4. What are different types of locators?
There are 8 types of locators and all are the static methods of the By class.
• By.id ()
• By.name ()
• By.tagName ()
• By.className ()
• By.linkText ()
• By.partialLinkText ()
• By.xpath
• By.cssSelector ()
5. What is the difference between Assert and Verify?
Assert it is used to verify the result. If the test case fails then it will stop the execution of the test case there itself and move the control to another test case.
Verify it is also used to verify the result. If the test case fails then it will not stop the execution of that test case.
SOFTWATE TESTING
Weekend / Weekday Batch
6. What is the alternate way to click on login button?
Use submit () method but it can be used only when attribute type=submit.
7. How do you verify if the checkbox/radio is checked or not?
We can use isSelected () method.
Syntax –
driver.findElement (By.xpath (“xpath of the checkbox/radio button”)).isSelected ();
If the return value of this method is true then it is checked else it is not.
8. How do you handle alert popup?
To handle alert popup, we need to 1st switch control to alert popup then click on ok or cancel then move control back to the main page.
Syntax:
String mainPage = driver.getWindowHandle ();
Alert alt = driver.switchTo ().alert (); // to move control to alert popup
alt.accept (); // to click on ok.
alt.dismiss (); // to click on cancel.
//Then move the control back to main web page
driver.switchTo ().window (mainPage); → to switch back to main page.
9. How do you launch IE/chrome browser?
Before launching IE or Chrome browser we need to set the System property.
//To open IE browser
System.setProperty (“webdriver.ie.driver”,”path of the iedriver.exe file”);
Web Driver driver = new InternetExplorerDriver ();
//To open Chrome browser → System.setProperty (“webdriver.chrome.driver”,”path of the chromeDriver.exe file”);
WebDriver driver = new ChromeDriver ();
10. How to perform right click using WebDriver?
Use Actions class
Actions act = new Actions (driver); // where driver is WebDriver type
act.moveToElement(WebElement).perform();
act.contextClick ().perform ();