December 30, 2017

Inheritance

Inheritance:

Inheritance is the process of acquiring all the properties and behaviors of parent object.
When you inherit from an existing class, you can reuse methods and fields of parent class, and you can add new methods and fields to the new class.
Inheritance represents the IS-A relationship, also known as parent-child relationship.
In general, we call Parent class as Super class and the child class as Sub Class

Syntax of Java Inheritance

class Sub_Class extends Super_Class 
//methods and fields
 The extends keyword indicates that we are creating new class(childClass) that derives from an existing class(parentClass). The meaning of "extends" is to increase the functionality.
Ex:
class Phone{
            int memory=4;
            float screenSize=5.5; 
class iPhone extends Phone{ 
            String manufacturer = "Apple";
            public static void main(String args[]){ 
                        iPhone ip=new iPhone(); 
                        System.out.println("iPhone Memeory is: "+ip.memory);
                        System.out.println("iPhone Screen size is: "+ip.screenSize);
                        System.out.println("iPhone Manufacturer is: "+ip.manufacturer);
            }
}

 Pictorial Representation:

In the above the diagram, iPhone is a subclass of a super Class Phone. Which means iPhone Is A type of Phone.
It means here we created IS-A relation between super class and sub class using inheritance.

Types of inheritance in java

On the basis of class, there can be three types of inheritance in java: single, multilevel and hierarchical.
In java programming, multiple and hybrid inheritance is supported through interface only. We will learn about interfaces later.
Note: Multiple Inheritance is not supported in java through class.

Single Inheritance:

In single inheritance, subclasses inherit the features of one superclass. In program below, the class Phone serves as a base class for the derived iPhone
            int memory=4;
            float screenSize=5.5; 
class iPhone extends Phone{ 
            String manufacturer = "Apple";
            public static void main(String args[]){ 
                        iPhone ip=new iPhone(); 
                        System.out.println("iPhone Memeory is: "+ip.memory);
                        System.out.println("iPhone Screen size is: "+ip.screenSize);
                        System.out.println("iPhone Manufacturer is: "+ip.manufacturer);
            }
}

Multilevel Inheritance:

In Multilevel Inheritance, a derived class will be inheriting a base class and as well as the derived class also act as the base class to other class. In Program image, the class Phone serves as a base class for the derived class SmartPhone, which in turn serves as a base class for the derived class iPhone. In Java, a class cannot directly access the grandparent’s members.
class Phone{
            void call();
            void message();
class SmartPhone extends Phone{ 
            void toggleWifi();
            void toggleBluetooth();
}
class iPhone extends SmartPhone{
            void connectToMAC();
            void siri();
}

Hierarchical Inheritance:

In Hierarchical Inheritance, one class serves as a superclass (base class) for more than one sub class. In below image, the class Phone serves as a base class for the derived class iPhone and AnroidPhone
class Phone{
            void call();
            void message();
class SmartPhone extends Phone{ 
            void call();
void message();
void toggleWifi();
            void toggleBluetooth();
}
class iPhone extends SmartPhone{
            void connectToMAC();
            void siri();
}
class AnroidPhone extends SmartPhone{
void connectToPC();
}

Why multiple inheritance is not supported in java?

To reduce the complexity and simplify the language, multiple inheritance is not supported in java.
Consider a scenario where Java, Test and JavaTest are three classes. The JavaTest class inherits Java and Test classes. If Java and Test classes have same method and you call it from child class object, there will be ambiguity to call method of Java or Test class.
Since compile time errors are better than runtime errors, java renders compile time error if you inherit 2 classes. So whether you have same method or different, there will be compile time error now.
class Java{
void print(){System.out.println("Java");} 
class Test{ 
void print(){System.out.println("Test");} 
class JavaTest extends Java,Test{       //suppose if it were
public Static void main(String args[]){
JavaTest obj=new JavaTest ();
obj.print();      //Now which print() method would be invoked?

December 17, 2017

Classes and Objects

Here in this chapter, we will look into the concepts of Classes and Objects.

Class:
  • Class is used to create our own data type
  • Class is a blue print which has only template
  • Class will describe the behavior and state of the objects
  • Class is a logical entity which will occupy any space in the memory
Syntax:
Class <className>
{
<datatype 1 > <variable 1>;
<datatype 2 > <variable 2>;
<datatype 3 > <variable 3>;

void method1(){}
void method2(){}
}
In the above syntax, variables/fields represent the states and methods represents the behavior

Ex:
Class Phone
{
int memory;
String manufacturer;
double screenSize;

void call(){}
void message(){}
}

In the above example Phone is a User defined data type. Memory, manufacturer and screenSize are the fields which represents the state of the Phone. Call and message are the two features of the phone which represents the behavior of the phone.
Objects:
  • Objects have the states and behavior
  • Objects will be created the class and the
  • Objects will have state and behavior
  • As the Objects are physical entities they will stored in the memory
How to create the Objects?
Syntax:
<Class Name> <variable Name> = new <Class Name>();
In the above Syntax, we have 3 steps
1.        Declaration - <Class Name> <variable Name>
2.       Instantiation – new keyword is used to create the objects
3.       Initialization – new keyword followed by <class name>()
Ex:
                Phone lPhone =new Phone();

The following program shows the implementation of CLASS & OBJECTS

Class Phone
{
// Fields/Class Variables Declaration
                int memory; //1,2,3,4
                String Manfacturer; //"Sansung", "Sony", "Apple", "Windows"
                float dimention; //5,5.5,4.5
               
// Behavior/Methods Declaration
                void call()
                {
                }
                void message()
                {
                }
               
                void tuggleWifi()
                {
                }

Public static void main(String args[])
{
// Object Creation
Phone IPhone=new Phone();
}
}

March 7, 2017

Selenium Grid

What is Selenium Grid:

Selenium-Grid allows you run your tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems

Selenium-Grid support distributed test execution. It allows for running your tests in a distributed test execution environment.


When to use Selenium Grid:

  1. To test the UI of you page across the browsers - CROSS BROWSER TESTING
  2. If you have a suite of 100 flows devide them logically and start the execution on the differet Nodes at the same time. Make sure No tests are dependent on the tests of the other group - SAVE TIME
  3. When your application has feature which supports mulitple languages, then create the seperate test data for each language and run those tests in parallel

Advantages Of Selenium Grid?

  1. Run your tests against different browsers, operating systems, and machines all at the same time. This will ensure that the application you are testing is fully compatible with a wide range of browser-O.S combinations.
  2. Selenium-Grid is used to speed up the execution of a test pass by using multiple machines to run tests in parallel. For example, if you have a suite of 100 tests, but you set up Selenium-Grid to support 4 different machines to run those tests, your test suite will complete in approx one-fourth the time as it would if you ran your tests sequentially on a single machine.
Selenium Grid uses a hub-node concept. A grid consists of a single hub, and one or more nodes. Both are started using the selenium-server.jar executable.

What is HUB?
The hub receives a test to be executed along with information on which 'browser' and ‘platform’ where the test should be run. It ‘knows’ the configuration of each node that has been ‘registered’ to the hub. Using this information it selects an available node that has the requested browser-platform combination. Once a node has been selected, Selenium commands initiated by the test are sent to the hub, which passes them to the node assigned to that test.

What is a NODE?
The node runs the browser, and executes the Selenium commands within that browser against the application under test.

How to Install Selenium Grid:

Download the Selenium-Server jar file from the SeleniumHq website’s download page.

You’ll need to be sure the java executable is on your execution path so you can run it from the command-line. If it does not run correcly, verify your system’s 'path' variable includes the path to the java.exe.

Hub configuration:
To start a hub with default parameters, run the following command from a command-line shell. This will work on all the supported platforms like Windows, Linux or Mac.

java -jar <selenium-server-standalone-2.xx.x.jar> -role hub

This starts a hub using default parameter values ad the the default port number will be 4444.

You should see the following logging output after running the above command.
<month> <date>, <year> <hh>:<mm>:<ss> AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid server
<year>-<month> <date> <hh>:<mm>:<ss>.082:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
<year>-<month> <date> <hh>:<mm>:<ss>.151:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
<year>-<month> <date> <hh>:<mm>:<ss>.185:INFO:osjs.AbstractConnector:Started SocketConnector@0.0.0.0:4444

Specifying the Port
AS we discussed, the default port used by the hub is 4444. If another application on your computer is already using this port, or if, you already have a Selenium-Server started, you’ll see the following message in the log output.

<hh>:<mm>:<ss>.490 WARN - Failed to start: SocketListener0@0.0.0.0:4444
Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.

If this occurs you can either shutdown the other process that is using port 4444, or you can tell Selenium-Grid to use a different port for its hub. Use the -port option for changing the port used by the hub.

java -jar selenium-server-standalone-2.<xx>.<x>.jar -role hub -port 4441

This will work even if another hub is already running on the same machine, that is, as long as they’re both not using port 4441.

Starting Node:
To start a node using default parameters, run the following command from a command-line.

java -jar selenium-server-standalone-2.<xx>.<x>.jar -role node  -hub http://localhost:4444/grid/register

This assumes the hub has been started above using default parameters. The use of ‘localhost’ assumes your node is running on the same machine as your hub and 4444 specifies the port number of your hub. If running the hub and node on separate machines, simply replace ‘localhost’ with the hostname of the remote machine running the hub.

WARNING: Be sure to turn off the firewalls on the machine running your hub and nodes. Otherwise you may get connection errors.

Configure Node:
For running the tests with selenium grid, selenium webdriver tests needs to use the instance of RemoteWebDriver and DesiredCapabilities classes to define which Browser version and platform the tests will be executed on.

Based on the preferences set in the DesiredCapabilities instance, the hub will point the test to a node that matches these preferences.

Configure Node for Firefox:
The Script Level:
DesiredCapabilities ffcap = new DesiredCapabilities();
ffcap.setBrowserName("firefox");
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),ffcap);

Command level while registering the Node:
java -jar selenium-server-standalone-2.<xx>.<x>.jar -role node  -hub http://localhost:4444/grid/register -browser "browserName = firefox" -port 5555

Configure Node for Internet Explorer:
The Script Level:
DesiredCapabilities iecap = new DesiredCapabilities.internetExplorer();
iecap.setCapability(InteretExplorerDriver.INTRODUCE_FLAKIESS_B_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),iecap);

Command level while registering the Node:
java -jar selenium-server-standalone-2.<xx>.<x>.jar -role node  -hub http://localhost:4444/grid/register -maxSession 10 -browser "browserName = interet explorer, platform=WINDOWS" -port 5556


Common Errors

Unable to access jar file selenium-server-standalone-2.<xx>.<x>.jar

This error can occur when starting up either a hub or node. This means Java cannot find the selenium-server jar file. Either run the command from the directory where the selenium-server-standalone-2.<xx>.<x>.jar file is stored, or specify an explicit path to the jar.


Points to be careful when run the tests in parallel:

  1. Only those tests which are independent of each should be run in parallel
  2. When working with browsers, there should not be manual intervention like 'Do you want to set this browser as your default browser' dialog

Selenium Interview Questions

How to load the Mobile mode for Chrome at Run Time?
Chrome allows users to emulate Chrome on a mobile device (e.g. a “Google Nexus 7” tablet, or an “Apple iPhone 5”) from the desktop version of Chrome allows developers to quickly test how a website will render in a mobile device, without requiring a real device. ChromeDriver can also enable Mobile Emulation, via the “mobileEmulation” capability, specified with a dictionary value.
Specifying a Known Mobile Device
To enable Mobile Emulation with a specific device name, the “mobileEmulation” dictionary must contain a “deviceName.” Use a valid device name from the DevTools Emulation panel as the value for “deviceName.”

//Creating a mapper object to set the device Name
Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Google Nexus 5");

//Creating a mapper object to set the Emulation type
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);

//Creating DesiredCapabilities to set the mobile emulation to the driver object
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

//Creating driver object with the above created Capability
WebDriver driver = new ChromeDriver(capabilities);

What are WebDriver Supported Browsers?
Selenium WebDriver API has a many different drivers to test your web application in different browsers.
  1. Firefox Driver - For Mozilla Firefox browser
  2. Internet Explorer Driver - For Internet Explorer browser
  3. Chrome Driver - For Google Chrome browser
  4. htmlUnit Driver - GUI-Less(Headless) browser for Java programs
  5. Opera Driver - For Opera browser
What are locators Supported by Selenium WebDriver?
 Locator
 Usage
 xPath
By.xpath("<xpath of the Element>") 
 cssSelector 
By.cssSelector ("<css Selector of the Element>") 
className  
By.className("<Class Name of the Element>") 
id 
By.id("<id of the Element>") 
 name 
 By.name ("<name of the Element>")
 linkText 
 By.linkText ("<Link Text of the Element>")
 partialLinkText 
 By.partialLinkText ("<Partial Link Text of the Element>")
 tagName 
 By.tagName ("<Tag Name of the Element>")

Selenium WebDriver is Paid or Open Source Tool? Why you prefer?
Selenium WebDriver is an open source tool; it will be available in the market at no cost
  1. Open Source.
  2. It has multi-browser support.
  3. Multi-platform support.
  4. Multiple ways to spy/identify the object/element (id, className, xpath, cssSelector etc.,).
  5. Web as well mobile application testing support.
How many types of waits available in selenium WebDriver
There are two types of waits available in selenium WebDriver
  1. Implicit Wait
  2. Explicit Wait
What is implicitlyWait and explicitWait in Selenium WebDriver?
ImplicitlyWait: Sometimes, Elements are taking time to be appearing on web application page. Using implicit wait in Selenium WebDriver, we can poll the DOM for certain amount of time when some element or elements are not available immediately on webpage.
Example:
Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
If you will write above syntax in your test, your WebDriver test will wait 10 seconds for appearing element on page.
ExplicitWait: Using explicit wait code In selenium WebDriver software automation testing tool, You can define to wait for a certain condition to occur before proceeding further test code execution.
Example:
WebDriverWait wait = new WebDriverWait(driver, 20);
Wait.until(expectedconditions.elementtobeclickable(By.xpath("//input[@id='gbqfq']")));

I want to suspend my test execution for 10 seconds at specific point. How can I do it?
You can use java.lang.Thread.sleep(long milliseconds) method to pause the software test execution for specific time.
Example:
Thread.sleep(10);

How does the browser driven in Selenium RC and Selenium WebDriver?
Selenium RC: When browser loaded In Selenium RC, It ‘injects’ JavaScript functions into the browser and then it will use JavaScript to drive the browser for the application under test.
Selenium WebDriver: Selenium WebDriver works like real user interacting with the application and its elements. It will use each browser's native support to make direct calls with browser for your software application under test. There is not any Intermediate thing in selenium WebDriver to interact with web browsers.

Do you need Selenium Server to run your tests in selenium WebDriver?
It depends. If you are using only selenium WebDriver API to run your tests and you are running all your tests on same machine then you do not need selenium server because In this case, WebDriver can directly interact with browser using browser's native support.
You need selenium server with WebDriver when you have to perform bellow given operations with selenium WebDriver.
  1. When you are using remote or virtual machine to run WebDriver tests for software web application and that machine have specific browser version that is not on your current machine.
  2. When you are using selenium-grid to distribute your WebDriver's test execution on different remote or virtual machines.
Bellow given syntax will work to navigate to specified URL in WebDriver? Why?
Driver.get("www.google.com");
No. It will not work and show you an exception like: "Exception in thread "main" org.openqa.selenium.WebDriverException: f.queryinterface is not a function" when you run your test.
You need to provide http:// protocol with URL In driver.get method as bellow.
Driver.get("http://www.google.com");

What is the reason behind bellow given WebDriver exception and how will you resolve it?
"Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element"
We will get this exception when WebDriver is not able to locate element on the page of software web application using whatever locator you have used in your test. To resolve this Issue, I will check bellow given things.
  • First of all I will check that I have placed implicitlyWait code in my test or not. If you have not placed implicitlyWait in your test and any element is taking some time to appear on page then you can get this exception. So I will add bellow given line at beginning of my test case code to wait for 15 seconds for element to be present on page. In 70% cases, this step will resolve Issue.
Driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
  • Another reason behind this Issue is element's ID Is generated dynamically every time when reloading the page. If I have used element's ID as an element locator or used it in xpath to locate the element then I need to verify that ID of element remains same every time or It Is changing? If it is changing every time then I have to use alternative element locating method. In 20% cases, this step will resolve your Issue.
  • If implicitlyWait is already added and element locator is fine then you need to verify that how much time it (element) is taking to appear on page. If It Is taking more than 15 seconds then you have to put explicitWait condition with 20 or more seconds wait period as bellow. In 5 to 10% cases, this step will resolve your Issue. View Example.
WebDriverWait wait = new WebDriverWait(driver, 25);
Wait.until(expectedconditions.elementtobeclickable(By.cssselector("#input")));

Can we automate desktop application's testing using selenium WebDriver?
No. This is the biggest disadvantage of selenium WebDriver API. We can automate only web and mobile software application's testing using selenium WebDriver. If we want to automate desktop applications we have to use third party tools like Sikuli or AutoIT

Can you tell me the alternative driver.get() method to open URL in browser? What is the difference between them?
We can use anyone from below methods to open URL:
  1. driver.get()
  2. driver.navigate().to()
driver.get() method is generally used for Open URL of web application and it will wait till the whole page gets loaded.
driver.navigate() method is generally used for navigate to URL of software web application, navigate back, navigate forward, refresh the page. It will just navigate to the page but it will not wait till the whole page gets loaded.

WebDriver has built in Object Repository. Correct me if I am wrong?
No. WebDriver do not have any built in object repository. But we can use .properties/.java file to store all the page objects / Locators as follows.
In .properties file:
    <variable Name> = <value>
    btn_Login = //input[@class = ‘submit’]
In .java file:
    <Access Modifier> final String <Variable Name> = “<Locator Value>”;
    public final String btn_Login = “//input[@class = ‘submit’]”;

How will you set browser window size?
We can set browser window size using setSize method of selenium.
driver.manage().window().setSize(new Dimension(width, height));

What is the syntax to type value In prompt dialog box's Input field using selenium WebDriver?
Prompt dialog is just like confirmation alert dialog but with option of Input text box
To Input value in that text box of prompt dialog, you can use bellow given syntax.
    driver.switchTo().alert().sendKeys("Input text in the dialog box");

When I am running software web application's tests in Firefox Browser using selenium webDriver, It is not showing me any bookmarks, add-ons, saved passwords etc. in that browser. Do you know why?
Yes. It is because all those bookmarks, add-ons, passwords etc., are saved in your regular browser's profile folder so when you launch browser manually, It will use existing profile settings so it will show you all those stuffs. But when you run your software web application's tests in selenium webDriver, it is opening new browser instance with blank/new profile. So It will not show you bookmarks and all those things in that browser instance.
You can create custom Firefox profile and then you can use it in selenium webDriver test. in your custom profile, you can set all required bookmarks, add-ons etc..

Suppose we have 3 browsers namely FirefoxDriver. HtmlUnitDriver and InternetExpolorerDriver. Arrange them in fastest to slowest sequence?
HtmlUnitDriver is faster than all other drivers because it is not using any UI to execute test cases of software web application and InternetExplorerDriver is slower than Firefox and HtmlUnitDriver.
So, Fastest to slowest driver sequence is as bellow.
  1. HtmlUnitDriver
  2. FirefoxDriver
  3. InternetExplorerDriver
What is Ajax?
Asynchronous JavaScript And XML is full form of AJAX which is used for creating dynamic web pages very fast for software web applications. Using ajax, We can update page behind the scene by exchanging small amounts of data with server asynchronously. That means, Using ajax we can update page data Without reloading page.

How to handle Ajax in selenium webDriver?
Generally we are using ImplicitlyWait in selenium webDriver software automation tests to wait for some element to be present on page. But Ajax call cannot be handled using only Implicit wait
in your test because page not get reloaded when Ajax call sent and received from server and we cannot assume how much time It will take to receive Ajax call from server.
To handle Ajax call in selenium webDriver software automation tests, We needs to use webDriver’s ExplicitWait which can wait for specific amount of time with specific condition.

On Google search page, I want to search for some words without clicking on Google Search button. Is It possible in webDriver? How?
Yes we can do it using webDriver sendKeys method where we do not need to use Google Search button. Syntax is as bellow.
driver.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys("Search Syntax",Keys.ENTER);
In above syntax, //input[@id='gbqfq'] is xPath of Google search text field. First it will enter "Search Syntax" text in text box and then it will press Enter key on same text box to search for words on Google.

Can we perform drag and drop operation in Selenium webDriver? Tell me a syntax to drag X element and drop It on Y element.
Yes, we can perform drag and drop operation using selenium webDriver software testing tool's Advanced User interactions API. Syntax is like below.
new Actions(driver).dragAndDrop(X, Y).build().perform();

Do you have faced any technical challenges with Selenium webDriver software test automation?
Yes, I have faced many technical challenges during selenium webDriver test cases development and few of them are listed below.
  1. Sometimes, Some elements like text box, buttons etc. are taking more time(more than given Implicit wait time) to appear on page or to get enabled on page. In such situation, if I have used only Implicit wait then my test case can run fine on first run but it may fail to find element on second run. So we need provide special treatment for such elements so that webDriver script waits for element to be present or get enabled on page of software web application during test execution. We can use ExplicitWait to handle this situation.
  2. Handling dynamic changing ID to locate element is tricky. if element's ID is changing every time when you reload the application and you have to use that ID in XPath to locate element then you have to use functions like starts-with(@id, ‘post-body-') or contains(@id, ‘post-body-') in xPath.
  3. Clicking on sub menus which are getting rendered on mouse hover of main menu is somewhat tricky. You need to use webDriver's Actions class to perform mouse hover operation.
  4. If you have to execute your test cases in multiple browsers then one test case can run successfully in Firefox browser but same test case may fail in IE browser due to the timing related issues (NoSuchElementException) because test execution in Firefox browser is faster than IE browser. You can resolve this issue by increasing Implicit wait time when you run your test in IE browser.
  5. Above issue can arise due to the unsupported XPath in IE browser. In this case, you need to you other locating methods (ID, Name etc.,) to locate element.
  6. Handling JQuery elements like moving pricing slider, date picker, drag and drop etc., is tricky. You should have knowledge of webDriver's Advanced User interactions API to perform all these actions.
  7. Working with multiple Windows, Frames, and some tasks like Extracting data from web table, Extracting data from dynamic web table, Extracting all Links from page, Extracting all text box from page are also tricky and time consuming during test case preparation.
  8. There is not any direct command to upload or download files from web page using selenium webDriver. For downloading files using selenium webDriver, you need to create and set Firefox browser profile with webDriver test case.
  9. WebDriver do not have any built in object repository facility. You can do it using java .properties or .java files to create object repository.
  10. webDriver do not have any built in framework or facility using which we can achieve below given tasks directly :
    1. Capturing screenshots
    2. Generating test execution log
    3. Reading data from files
    4. Generating test result reports, Manage test case execution sequence.
  11. To achieve all these tasks, we have to use external services with webDriver like Log4J to generate log, Apache POI API to read data from excel files, TestNG XSLT reports to generate test result reports. TestNG to manage test case execution, .properties file to create object repository. All these tasks are very time consuming.
Can you tell me syntax to close current webDriver instance and to close all opened webDriver instances?
driver.close(); To close current WebDriver instance
driver.quit(); To close all of them then we can use webDriver’s quit() method

Is it possible to execute JavaScript directly during software test execution? If Yes then tell me how to generate alert by executing JavaScript in webDriver script?
Yes, we can execute JavaScript during webDriver software test execution. To generate alert, you can write bellow given code in your script.
JavascriptExecutor JavaScript = (JavascriptExecutor) driver;
javascript.executeScript("alert('JavaScript Executed.');");

Give me syntax to read JavaScript alert message string, clicking on OK button and clicking on Cancel button.
String alrtmsg = driver.switchTo().alert().getText(); //To Read the message from the alert dialog
driver.switchTo().alert().accept(); //To click on OK button of alert dialog
driver.switchTo().alert().dismiss(); //To click on CANCEL button of alert dialog

Tell me a scenario which we cannot automate in selenium WebDriver?

  1. Desktop Applications we can't automate. Need to user 3rd party tools to achieve this.
  2. Bitmap comparison is not possible using selenium webDriver software testing tool.
  3. Automating captcha is not possible. (Few peoples say we can automate captcha but I am telling you if you can automate any captcha then it is not a captcha).
  4. We cannot read bar code using selenium webDriver software testing tool.

OTHER INTERVIEW QUESTIONS
I’m posting list of interview questions. Please answer them if you know.
1.        How do Check whether two string are Equal or not in Java?
2.       Can you write the internal logic of the following String functions in Java
§  String.equals()
§  String.equalsIgnoreCase()
§  String.split()
§  String.strCat()
3.       What is a Singleton Class?
4.       What is a Collection? What are the collection concepts you have used in your Selenium? Which situation and Why?
5.       We have the following DOM, how can you enter the value in the PASSWORD/2nd text box field? And what are all the different approaches?
§  “<idiv id=”login_page“>
§  <iinput id=”user_name123“/>
§  <iinput/>
§  </idiv>”
6.      Is the following statement true for the above DOM
§  List<WebElement> inputTags = driver.findElements(By.tagName(“//idiv[@id=’login_page’/iinput”));
7.       What are different frameworks and which one will you prefer and why?
8.      Small Program which will represent your framework?
9.      What are the difference between Keyword driven and POM approach
10.    What are APIs will you use for reading from excel and why jxl and POI?
11.     Handling Web Table?
12.    How will connect to the Database?
13.    Write the SQL query to modify the employee salary whose department name contains letter ‘a’.
§  Employee Table:
§  Eno
§  Ename
§  Salary
§  Dept ID
§  Department Table:
§  Dept No
§  Dept Name
14.    Tell me the scenario where you have used any one of Oops concept in your functionality not in your framework?
15.    What is the difference between FindElement and FindElements
16.    What is the difference between the following statements
§  WebDriver driver=new FirefoxDriver()
§  FirefoxDriver driver = new FirefoxDriver()
17.    Keyword Driven Framework Structure?
18.    How do you maintain the Object Repository in Selenium? And what are the different ways? (ex: Situation where the application UI got changed)
19.    How will you read the values from configuration.properties file
20.   What is Grid and Why it is used?
21.    Why JUNIT and TestNG? how if we not use JUNIT or TestNG?
22.    ** We have executed 100 Test cases out of which 10 Test cases are failed. So how can you run the failed test cases in TestNG and what are the different approaches to achieve this?
23.   Why do you use Xpath instead of cssSelector?
24.   How many ways can you select the value from the dropdown?
25.   How do you handle windows?
26.   How do you handle Alerts?
27.    How do you handle the Desktop alerts?
28.   How do you upload a file?
29.   How will you handle different browser (IE and Chrome especially)
30.   What are the different Locators you have used and why are you not using remaining?
31.    Can we achieve parallel execution without using Grid?
32.   What is a constructor? What are the different Constructors? what you have used?