Interview Questions


What are the benefits of Automation Testing?
Benefits of Automation testing are:
  • Supports execution of repeated test cases
  • Aids in testing a large test matrix
  • Enables parallel execution
  • Encourages unattended execution
  • Improves accuracy thereby reducing human generated errors
  • Saves time and money
why should Selenium be selected as a test tool?
Selenium:
  • is free and open source
  • have a large user base and helping communities
  • have cross Browser compatibility (Firefox, chrome, Internet Explorer, Safari etc.)
  • have great platform compatibility (Windows, Mac OS, Linux etc.)
  • supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.)
  • has fresh and regular repository developments
  • supports distributed testing
What is Selenium? What are the different Selenium components?
Selenium is one of the most popular automated testing tool. Selenium is designed in a way to support and encourage automation testing of functional aspects of web based applications and a wide range of browsers and platforms. Due to its existence in the open source community, it has become one of the most accepted tools amongst the testing professionals. Selenium is not just a single tool or a utility, rather a package of several testing tools and for the same reason it is referred to as a Suite. Each of these tools is designed to cater different testing and test environment requirements. The suite package constitutes of the following sets of tools:
Selenium Integrated Development Environment (IDE) – Selenium IDE is a record and playback tool. It is distributed as a Firefox Plugin.
Selenium Remote Control (RC) – Selenium RC is a server that allows user to create test scripts in a desired programming language. It also allows executing test scripts within the large spectrum of browsers.
Selenium WebDriver – WebDriver is a different tool altogether that has various advantages over Selenium RC. WebDriver directly communicates with the web browser and uses its native compatibility to automate.
Selenium Grid – Selenium Grid is used to distribute your test execution on multiple platforms and environments concurrently.
What are the testing types that can be supported by Selenium?
Selenium supports the following types of testing:
  • Functional Testing
  • Regression Testing
What are the limitations of Selenium?
Following are the limitations of Selenium:
  • Selenium supports testing of only web based applications
  • Mobile applications cannot be tested using Selenium
  • Captcha and Bar code readers cannot be tested using Selenium
  • Reports can only be generated using third party tools like TestNG or Junit.
  • As Selenium is a free tool, thus there is no ready vendor support though the user can find numerous helping communities.
  • User is expected to possess prior programming language knowledge.
When should I use Selenium IDE?
Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback feature makes it exceptionally easy to learn with minimal acquaintances to any programming language. Selenium IDE is an ideal tool for a naïve user.
What is Selenese?
Selenese is the language which is used to write test scripts in Selenium IDE.
What are the different types of locators in Selenium?
Locator can be termed as an address that identifies a web element uniquely within the webpage. Thus, to identify web elements accurately and precisely we have different types of locators in Selenium:
  • ID
  • ClassName
  • Name
  • TagName
  • LinkText
  • PartialLinkText
  • Xpath
  • CSS Selector
  • DOM
What is difference between assert and verify commands?
Assert: Assert command checks whether the given condition is true or false. Let’s say we assert whether the given element is present on the web page or not. If the condition is true then the program control will execute the next test step but if the condition is false, the execution would stop and no further test would be executed.
Verify: Verify command also checks whether the given condition is true or false. Irrespective of the condition being true or false, the program execution doesn’t halts i.e. any failure during verification would not stop the execution and all the test steps would be executed.
What is an Xpath?
Xpath is used to locate a web element based on its XML path. XML stands for Extensible Markup Language and is used to store, organize and transport arbitrary data. It stores data in a key-value pair which is very much similar to HTML tags. Both being markup languages and since they fall under the same umbrella, Xpath can be used to locate HTML elements.
The fundamental behind locating elements using Xpath is the traversing between various elements across the entire page and thus enabling a user to find an element with the reference of another element.
What is the difference between "/" and "//" in Xpath?
Single Slash "/" – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.
Double Slash "//" - Double slash is used to create Xpath with relative path i.e. the xpath would be created to start selection from anywhere within the document.
What is Same origin policy and how it can be handled?
The problem of same origin policy disallows to access the DOM of a document from an origin that is different from the origin we are trying to access the document.
When should I use Selenium Grid?
Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution, testing under different environments and saving execution time remarkably.
What do we mean by Selenium 1 and Selenium 2?
Selenium RC and WebDriver, in a combination are popularly known as Selenium 2. Selenium RC alone is also referred as Selenium 1.
Which is the latest Selenium tool?
WebDriver
How do I launch the browser using WebDriver?
The following syntax can be used to launch Browser:
 
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();
What are the different types of Drivers available in WebDriver?
The different drivers available in WebDriver are:
  • FirefoxDriver
  • InternetExplorerDriver
  • ChromeDriver
  • SafariDriver
  • OperaDriver
  • AndroidDriver
  • IPhoneDriver
  • HtmlUnitDriver
What are the different types of waits available in WebDriver?
There are two types of waits available in WebDriver:
  • Implicit Wait
  • Explicit Wait
Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command.
Explicit Wait: Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only.
How to type in a textbox using Selenium?
User can use sendKeys("String to be entered") to enter the string in the textbox. Syntax:
 
WebElement username = drv.findElement(By.id("Email"));
// entering username
username.sendKeys("sth");
How can you find if an element in displayed on the screen?
WebDriver facilitates the user with the following methods to check the visibility of the web elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc.
  • isDisplayed()
  • isSelected()
  • isEnabled()
Syntax:
 
isDisplayed():
boolean buttonPresence = driver.findElement(By.id("gbqfba")).isDisplayed();
isSelected():
boolean buttonSelected = driver.findElement(By.id("gbqfba")).isDisplayed();
isEnabled():
boolean searchIconEnabled = driver.findElement(By.id("gbqfb")).isEnabled();
How can we get a text of a web element?
Get command is used to retrieve the inner text of the specified web element. The command doesn’t require any parameter but returns a string value. It is also one of the extensively used commands for verification of messages, labels, errors etc displayed on the web pages.
Syntax:
String Text = driver.findElement(By.id("Text")).getText();
How to select value in a dropdown?
Value in the drop down can be selected using WebDriver’s Select class.
Syntax:
selectByValue:
Select selectByValue = new Select(driver.findElement(By.id("SelectID_One")));
selectByValue.selectByValue("greenvalue");
selectByVisibleText:
Select selectByVisibleText = new Select (driver.findElement(By.id("SelectID_Two")));
selectByVisibleText.selectByVisibleText("Lime");
selectByIndex:
Select selectByIndex = new Select(driver.findElement(By.id("SelectID_Three")));
selectByIndex.selectByIndex(2);
What are the different types of navigation commands?
Following are the navigation commands:
navigate().back() – The above command requires no parameters and takes back the user to the previous webpage in the web browser’s history.
Sample code:
driver.navigate().back();
navigate().forward() – This command lets the user to navigate to the next web page with reference to the browser’s history.
Sample code:
driver.navigate().forward();
navigate().refresh() – This command lets the user to refresh the current web page there by reloading all the web elements.
Sample code:
driver.navigate().refresh();
navigate().to() – This command lets the user to launch a new web browser window and navigate to the specified URL.
Sample code:
driver.navigate().to("https://google.com");
How to click on a hyper link using linkText?
driver.findElement(By.linkText("Google")).click();
The command finds the element using link text and then click on that element and thus the user would be re-directed to the corresponding page.
The above mentioned link can also be accessed by using the following command.
driver.findElement(By.partialLinkText("Goo")).click();
The above command find the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element with the specified substring and then clicks on it.
How to handle frame in WebDriver?
An inline frame acronym as iframe is used to insert another document with in the current HTML document or simply a web page into a web page by enabling nesting.
Select iframe by id
driver.switchTo().frame("ID of the frame");
Locating iframe using tagName
driver.switchTo().frame(driver.findElements(By.tagName("iframe").get(0));
Locating iframe using index frame(index)
driver.switchTo().frame(0);
frame(Name of Frame)
driver.switchTo().frame("name of the frame");
Select Parent Window
driver.switchTo().defaultContent();
When do we use findElement() and findElements()?
findElement(): findElement() is used to find the first element in the current web page matching to the specified locator value. Take a note that only first matching element would be fetched.
Syntax:
WebElement element = driver.findElements(By.xpath("//div[@id=’example’]//ul//li"));
findElements(): findElements() is used to find all the elements in the current web page matching to the specified locator value. Take a note that all the matching elements would be fetched and stored in the list of WebElements.
Syntax:
List <WebElement> elementList = driver.findElements(By.xpath("//div[@id=’example’]//ul//li"));
How to find more than one web element in the list?
At times, we may come across elements of same type like multiple hyperlinks, images etc arranged in an ordered or unordered list. Thus, it makes absolute sense to deal with such elements by a single piece of code and this can be done using WebElement List.
// Storing the list
List <WebElement> elementList = driver.findElements(By.xpath("//div[@id='example']//ul//li"));
// Fetching the size of the list
int listSize = elementList.size();
for (int i=0; i<listSize; i++)
{
// Clicking on each service provider link
serviceProviderLinks.get(i).click();
//Navigating back to the previous page that stores link to service providers 
driver.navigate().back();
}
What is the difference between driver.close() and driver.quit command?
close(): WebDriver’s close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver. The command neither requires any parameter nor does is return any value.
quit(): Unlike close() method, quit() method closes down all the windows that the program has opened. Same as close() method, the command neither requires any parameter nor does is return any value.
Can Selenium handle windows based pop up?
Selenium is an automation testing tool which supports only web application testing. Therefore, windows pop up cannot be handled using Selenium.
How can we handle web based pop up?
WebDriver offers the users with a very efficient way to handle these pop ups using Alert interface. There are the four methods that we would be using along with the Alert interface.
void dismiss() – The accept() method clicks on the "Cancel" button as soon as the pop up window appears.
void accept() – The accept() method clicks on the "Ok" button as soon as the pop up window appears.
String getText() – The getText() method returns the text displayed on the alert box.
void sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box.
Syntax:
// accepting javascript alert
   Alert alert = driver.switchTo().alert();
alert.accept();
How can we handle windows based pop up?
Selenium is an automation testing tool which supports only web application testing, that means, it doesn’t support testing of windows based applications. However Selenium alone can’t help the situation but along with some third party intervention, this problem can be overcome. There are several third party tools available for handling window based pop ups along with the selenium like AutoIT, Robot class etc.
How to assert title of the web page?
//verify the title of the web page
assertTrue("The title of the window is incorrect.",driver.getTitle().equals("Title of the page"));
How to mouse hover on a web element using WebDriver?
WebDriver offers a wide range of interaction utilities that the user can exploit to automate mouse and keyboard events. Action Interface is one such utility which simulates the single user interactions.
Thus, In the following scenario, we have used Action Interface to mouse hover on a drop down which then opens a list of options.
    
// Instantiating Action Interface
Actions actions=new Actions(driver);
// howering on the dropdown
actions.moveToElement(driver.findElement(By.id("id of the dropdown"))).perform();
// Clicking on one of the items in the list options
WebElement subLinkOption=driver.findElement(By.id("id of the sub link"));
subLinkOption.click();
How to retrieve css properties of an element?
The values of the css properties can be retrieved using a get() method:
Syntax:
 
driver.findElement(By.id("id")).getCssValue("name of css attribute");
driver.findElement(By.id("id")).getCssValue("font-size");
How to capture screenshot in WebDriver?
 
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class CaptureScreenshot {
  WebDriver driver;
  @Before
  public void setUp() throws Exception {
   driver = new FirefoxDriver();
   driver.get("https://google.com");
  }
  @After
  public void tearDown() throws Exception {
   driver.quit();
  }

  @Test
  public void test() throws IOException {
   // Code to capture the screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
   // Code to copy the screenshot in the desired location
FileUtils.copyFile(scrFile, new File("C:\\CaptureScreenshot\\google.jpg"));    
  }
}
What is Junit?
Junit is a unit testing framework introduced by Apache. Junit is based on Java.
What are Junit annotations?
Following are the Junit Annotations:

@Test: Annotation lets the system know that the method annotated as @Test is a test method. There can be multiple test methods in a single test script.
@Before: Method annotated as @Before lets the system know that this method shall be executed every time before each of the test method.
@After: Method annotated as @After lets the system know that this method shall be executed every time after each of the test method.
@BeforeClass: Method annotated as @BeforeClass lets the system know that this method shall be executed once before any of the test method.
@AfterClass: Method annotated as @AfterClass lets the system know that this method shall be executed once after any of the test method.
@Ignore: Method annotated as @Ignore lets the system know that this method shall not be executed.
What is TestNG and how is it better than Junit?
TestNG is an advance framework designed in a way to leverage the benefits by both the developers and testers. With the commencement of the frameworks, JUnit gained an enormous popularity across the Java applications, Java developers and Java testers with remarkably increasing the code quality. Despite being easy to use and straightforward, JUnit has its own limitations which give rise to the need of bringing TestNG into the picture. TestNG is an open source framework which is distributed under the Apache software License and is readily available for download.
TestNG with WebDriver provides an efficient and effective test result format that can in turn be shared with the stake holders to have a glimpse on the product’s/application’s health thereby eliminating the drawback of WebDriver’s incapability to generate test reports. TestNG has an inbuilt exception handling mechanism which lets the program to run without terminating unexpectedly.
There are various advantages that make TestNG superior to JUnit. Some of them are:
  • Added advance and easy annotations
  • Execution patterns can set
  • Concurrent execution of test scripts
  • Test case dependencies can be set
How to set test case priority in TestNG?
Setting Priority in TestNG
Code Snippet
    
package TestNG;
import org.testng.annotations.*;
public class SettingPriority {
  @Test(priority=0)
  public void method1() { 
  }
  @Test(priority=1)
  public void method2() { 
  }
  @Test(priority=2)
  public void method3() { 
  }
}
Test Execution Sequence:

Method1
Method2
Method3
What is a framework?
Framework is a constructive blend of various guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections etc. to pillar automation testing.
What are the advantages of Automation framework?
Advantage of Test Automation framework
  • Reusability of code
  • Maximum coverage
  • Recovery scenario
  • Low cost maintenance
  • Minimal manual intervention
  • Easy Reporting
What are the different types of frameworks?
Below are the different types of frameworks:
Module Based Testing Framework: The framework divides the entire "Application Under Test" into number of logical and isolated modules. For each module, we create a separate and independent test script. Thus, when these test scripts taken together builds a larger test script representing more than one module.

Library Architecture Testing Framework: The basic fundamental behind the framework is to determine the common steps and group them into functions under a library and call those functions in the test scripts whenever required.

Data Driven Testing Framework: Data Driven Testing Framework helps the user segregate the test script logic and the test data from each other. It lets the user store the test data into an external database. The data is conventionally stored in "Key-Value" pairs. Thus, the key can be used to access and populate the data within the test scripts.

Keyword Driven Testing Framework: The Keyword driven testing framework is an extension to Data driven Testing Framework in a sense that it not only segregates the test data from the scripts, it also keeps the certain set of code belonging to the test script into an external data file.

Hybrid Testing Framework: Hybrid Testing Framework is a combination of more than one above mentioned frameworks. The best thing about such a setup is that it leverages the benefits of all kinds of associated frameworks.

Behavior Driven Development Framework: Behavior Driven Development framework allows automation of functional validations in easily readable and understandable format to Business Analysts, Developers, Testers, etc.
How can I read test data from excels?
Test data can efficiently be read from excel using JXL or POI API. See detailed tutorial here.
What is the difference between POI and jxl jar?
  • JXL supports ".xls" format i.e. binary based format. JXL doesn’t support Excel 2007 and ".xlsx" format i.e. XML based format POI jar supports all of these formats
  • JXL API was last updated in the year 2009 POI is regularly updated and released
  • The JXL documentation is not as comprehensive as that of POI POI has a well prepared and highly comprehensive documentation
  • JXL API doesn’t support rich text formatting POI API supports rich text formatting
  • JXL API is faster than POI API POI API is slower than JXL API
What is the difference between Selenium and QTP?

Browser Compatibility: Selenium supports almost all the popular browsers like Firefox, Chrome, Safari, Internet Explorer, Opera etc QTP supports Internet Explorer, Firefox and Chrome. QTP only supports Windows Operating System
Distribution: Selenium is distributed as an open source tool and is freely available QTP is distributed as a licensed tool and is commercialized
Application under Test: Selenium supports testing of only web based applications QTP supports testing of both the web based application and windows based application
Object Repository: Object Repository needs to be created as a separate entity QTP automatically creates and maintains Object Repository
Language Support: Selenium supports multiple programming languages like Java, C#, Ruby, Python, Perl etc QTP supports only VB Script
Vendor Support: As Selenium is a free tool, user would not get the vendor’s support in troubleshooting issues Users can easily get the vendor’s support in case of any issue
Can WebDriver test Mobile applications?
WebDriver cannot test Mobile applications. WebDriver is a web based testing tool, therefore applications on the mobile browsers can be tested.
Can captcha be automated?
No, captcha and bar code reader cannot be automated.
What is Object Repository? How can we create Object Repository in Selenium?
Object Repository is a term used to refer to the collection of web elements belonging to Application Under Test (AUT) along with their locator values. Thus, whenever the element is required within the script, the locator value can be populated from the Object Repository. Object Repository is used to store locators in a centralized location instead of hard coding them within the scripts.
In Selenium, objects can be stored in an excel sheet which can be populated inside the script whenever required.
Tell me some TestNG Annotations.
@Test,@Parameters,@Listeners,@BeforeSuite,@AfterSuite,@BeforeTest,@AfterTest, @DataProvider,@BeforeGroups,@AfterGroups,@BeforeClass,@AfterClass, @BeforeMethod,@AfterMethod,@Factory
What are desired capabilities?
Desired Capabilities help to set properties for the Web Driver. A typical use case would be to set the path for the Firefox Driver if your local installation doesn't correspond to the default settings.
Difference between Selenium RC and Selenium Webdriver.

Selenium RC’s architecture is way more complicated.
Web Driver’s architecture is simpler than Selenium RC’s.
Selenium RC is slower since it uses a JavaScript program called Selenium Core. This Selenium Core is the one that directly controls the browser, not you.
Web Driver is faster than Selenium RC since it speaks directly to the browser uses the browser’s own engine to control it.
Selenium Core, just like other JavaScript codes, can access disabled elements.
Web Driver interacts with page elements in a more realistic way.
Selenium RC’s API is more matured but contains redundancies and often confusing commands.
Web Driver’s API is simpler than Selenium RC’s. It does not contain redundant and confusing commands.
Selenium RC cannot support the headless HtmlUnit browser. It needs a real, visible browser to operate on.
Web Driver can support the headless HtmlUnit browser.
Selenium RC Has Built-In Test Result Generator. Selenium RC automatically generates an HTML file of test results.
Web Driver has no built-in command that automatically generates a Test Results File.
Selenium RC needs the help of the RC Server in order to do so.
web Driver directly talks to the browser
Selenium RC can support new browsers
It cannot readily support new browsers
Difference between Web driver listener and TestNG Listener.
TestNG and Web driver Listener have different interfaces to implement and call them. They both modify respective behaviour. You can use Listeners in Annotation. Below 2 URL gives the detailed list of listener and their interfaces.
Describe your framework.
Which is the best way to locate an element?

Finding elements by ID is usually going to be the fastest option, because at its root, it eventually calls down to document.getElementById(), which is optimized by many browsers.
Finding elements by XPath is useful for finding elements using very complex selectors, and is the most flexible selection strategy, but it has the potential to be very slow, particularly in IE. In IE 6, 7, or 8, finding by XPath can be an order of magnitude slower than doing the same in Firefox. IE provides no native XPath-over-HTML solution, so the project must use a JavaScript XPath implementation, and the JavaScript engine in legacy versions of IE really is that much slower.
If you have a need to find an element using a complex selector, I usually recommend using CSS Selectors, if possible. It's not quite as flexible as XPath, but will cover many of the same cases, without exhibiting the extreme performance penalty on IE that XPath can.
Why we refer FirefoxDriver to the WebDriver inheritance.
WebDriver driver = new FireFoxDriver();
WebDriver is an interface which contain several abstract methods such as get(...), findElamentBy(...) etc.
We simply create reference of web Driver and we can assign objects (Firefox driver, CromeDriver, IEDriver, Andriod driver etc) to it.
Ex :
WebDriver driver = new FireFoxDriver();-----------(1)
If we are using (1) we can do the same thing by using
FireFoxDriver driver = new FireFoxDriver();---------(2)
We can use (1) and (2) for same purpose but if we want to switch to another browser in same program then again we have to create the object of other class as for example
CromeDriver driver = new CromeDriver();.
creating object of several class is not good. So we create the reference of WebDriver and we assign the objects of another class as for example
WebDriver driver; // it is created only one time in the program
driver = new FireFoxDriver();// any where in the program
driver = new CromeDriver(); // any where in the program
What are the features of TestNG?
TestNG is a testing framework designed to simplify a broad range of testing needs, from unit testing (testing a class in isolation of the others) to integration testing (testing entire systems made of several classes, several packages and even several external frameworks, such as application servers). You can use test suite,annotations, automatically generation of report and much more.
In what situation selenium finding element get fails?
  • Element loading issue
  • Dynamic id of web element
What is the difference between "GET" and "NAVIGATE" to open a web page in selenium web driver?
Get method will get a page to load or get page source or get text that's all whereas navigate will guide through the history like refresh, back, forward.For example if we want to move forward and do some functionality and back to the home page this can be achieved through navigate() only. driver.get will wait till the whole page gets loaded and driver.navigate will just redirect to that page and will not wait
Please tell me the difference b/w implicitly Wait and Explicit wait.
Implicit Wait sets internally a timeout that will be used for all consecutive Web Element searches. It will try lookup the element again and again for the specified amount of time before throwing a NoSuchElementException if the element could not have been found. It does only this and can't be forced into anything else - it waits for elements to show up.
Explicit Wait or just Wait is a one-timer used by you for a particular search. It is more extendible in the means that you can set it up to wait for any condition you might like. Usually, you can use some of the prebuilt Expected Conditions to wait for elements to become clickable, visible, invisible, etc., or just write your own condition that suits your needs.
How we can retrieve the dynamically changing Ids? When we login Facebook the login label's id changes dynamically thus resulting in failure.
We have a hierarchy of locators and Facebook Is dynamic in nature,so we are not able to use "id" for identification for after that we have remaining 7 locator's for that :2. xpath ().. 3. name..4. css.. 5. link text.. 6. partiallinktext...7.tag name. so u can use any one for identifying it. Most probably u can use "xpath" or "css-locator" and if there r tag then link text or partial-link text. it depend on u . But we never use id's in Ajax application because it’s not possible.
How to scroll web element?--not browser—
FirefoxProfile profile=new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver=new FirefoxDriver(profile);
driver.navigate("http://jqueryui.com/draggable/");
Thread.sleep(6000L);
WebElement element=driver.findElement(By.xpath("//div[@id='draggable']"));
Ations actn=new Actions(driver);
actn.dragAndDropBy(element, 50, 50).build().perform();
What is the basic use of Firefox profiles and how can we use them using selenium?
A profile in Firefox is a collection of bookmarks, browser settings, extensions, passwords, and history; in short, all of your personal settings.
We use them to change user agent, changing default download directory, changing versions etc.
How to handle internationalisation through web driver?
FirefoxProfile profile = new FirefoxProfile();
profile.set Preference("intl.accept_languages","jp");
Web driver driver = new FirefoxDriver(profile); 
driver.get(google.com) will open google in Japanese Lang
How can we get the font size, font color, font type used for a particular text on a web page using Selenium web driver?
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-size);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-colour);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-type);
driver.findelement(By.Xpath("Xpath ").getcssvalue("background-colour);
How to run tests in multiple browser parallel? Is there any other option other than selenium grid?
You create a class with a method something like this:
public class LaunchBrowser {

WebDriver driver=null;


// Pass parameter browser from test.xml
@Parameters("browser")
public void initiateBrowser(String browser){

// compare browser to fire fox and then open firefox driver
if(browser.equals("Firefox"))
{

driver = new FirefoxDriver();
}
else
{
// set path to the IE driver correctly here
System.setProperty("webdriver.ie.driver", "\iexploredriver.exe");
driver =new InternetExplorerDriver();
}
}
Now create YourClassName class and call extend the above class something like this
@Test
public class YourClassName extends LaunchBrowser{

public void gotoGoogle(){


driver.get("http://www.google.com");
}
}
How to prepare Customized html Report using TestNG in hybrid framework.
Below are the 3 ways:

Junit: with the help of ANT.
TestNG: using inbuilt default.html to get the HTML report. Also XST reports from ANT, Selenium, TestNG combination.
Using our own customized reports using XSL jar for converting XML content to HTML.
What’s the hierarchy of TestNG annotations? Explain me about annotation hierarchy & execution order?

org.testng.annotations.Parameters (implements java.lang.annotation.Annotation)
org.testng.annotations.Listeners (implements java.lang.annotation.Annotation)
org.testng.annotations.Test (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterMethod (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeTest (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeMethod (implements java.lang.annotation.Annotation)
org.testng.annotations.Optional (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterTest (implements java.lang.annotation.Annotation)
org.testng.annotations.Guice (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeGroups (implements java.lang.annotation.Annotation)
org.testng.annotations.ExpectedExceptions (implements java.lang.annotation.Annotation)
org.testng.annotations.TestInstance (implements java.lang.annotation.Annotation)
org.testng.annotations.NoInjection (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterSuite (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterClass (implements java.lang.annotation.Annotation)
org.testng.annotations.AfterGroups (implements java.lang.annotation.Annotation)
org.testng.annotations.DataProvider (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeSuite (implements java.lang.annotation.Annotation)
org.testng.annotations.BeforeClass (implements java.lang.annotation.Annotation)
org.testng.annotations.Factory (implements java.lang.annotation.Annotation)
org.testng.annotations.Configuration (implements java.lang.annotation.Annotation)
org.testng.annotations.ObjectFactory (implements java.lang.annotation.Annotation)
How to find broken images in a page using Selenium Web driver.

Get xpath and then using tag name; get all the links in the page

Click on each and every link in the page

In the target page title, look for 404/500 error.
How to get the name of browser using Web Driver?
public class JsExecute

{

WebDriver driver;

JavascriptExecutor js;

@Before

public void setUp() throws Exception

{

driver=new FirefoxDriver();

driver.get("http://www.google.com");

}

@Test

public void test()

{

JavascriptExecutor js = (JavascriptExecutor) driver;

System.out.println(js.executeScript("return navigator.appCodeName"));

}}
How to handle colors in web driver?
Use getCssValue(arg0) function to get the colors by sending 'color' string as an argument.
Example
String col = driver.findElement(By.id(locator)).getCssValue("color");
How to pass parameters from testng.xml into test case.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Parallelexecution {

private WebDriver driver = null;

@BeforeTest
@Parameters({ "BROWSER" })
public void setup(String BROWSER) {
System.out.println("Browser: " + BROWSER);

if (BROWSER.equals("FF")) {
System.out.println("Firefox Browser is selected");
driver = new FirefoxDriver();
} else if (BROWSER.equals("IE")) {
System.out.println("Internet Explorer Browser is selected");
driver = new InternetExplorerDriver();
} else if (BROWSER.equals("HU")) {
System.out.println("Html Unit Browser is selected");
driver = new HtmlUnitDriver();
} else if (BROWSER.equals("CH")) {
System.out.println("Google chrome Browser is selected");
driver = new ChromeDriver();
}
}

@Test
public void testParallel() throws Exception {
driver.get("http://www.google.com"");

}
}
Is there a way to click hidden LINK in web driver?
String Block1 = driver.findElement(By.id("element ID"));
JavascriptExecutor js1=(JavascriptExecutor)driver;
js1.executeScript("$("+Block1+").css({'display':'block'});");
0