Selenium With Java and Python For Mobile Apps & Web Apps......!

Interview Questions.

IBS Software Services Interview Questions...........

1.What is the difference between Assert and a Verify in Selenium?
Ans:Effectively an “assert” will fail the test and abort the current test case, whereas a “verify” will fail the test and continue to run the test case.

2.If a selenium function requires a script argument what would be that argument in general term?
Ans:
StoreEval(script, variable) and storeExpression(expression, variableName)

3.If a selenium function requires a pattern argument,what five prefixes might be have?
Ans:glob, regexp, exact, regexpi

4.What is the regular expression sequence that loosely translates to “anything or nothing”?
Ans:(.* i.e., dot star) This two-character sequence can be translated as “0 or more occurrences of any character” or more simply, “anything or nothing.

5. What is the globbing expression sequence that loosely translates to “anything or nothing”?
Ans:(*) which translates to “match anything,” i.e., nothing, a single character, or many characters.

6.What does a character class for all alphabetic characters and digits ?
Ans:[0-9] matches any digit
[A-Za-z0-9] matches any alphanumeric character

[A-Za-z] matches any alphabet character
? quantifier: 0 or 1 of the preceding character (or group)
{1,5} quantifier: 1 through 5 of the preceding character (or group)
Open command uses Base URL (Absolute URL) to navigate web page.
• assertAlert()
• assertAlertNotPresent()
• assertAlertPresent()
• storeAlert()
• storeAlertPresent()
• verifyAlert()
• verifyAlertNotPresent()
• verifyAlertPresent()
• waitForAlert()
• waitForAlertNotPresent()
• waitForAlertPresent()
The AlertPresent() and AlertNotPresent() functions check for the existence or not of an alert – regardless of it’s content. The Alert() functions allow the caller to specify a pattern which should be matched. The getAlert() method also exists in Selenium RC, and returns the text from the previous Alert displayed.

7.What must one set within SIDE in order to run a test from the beginning to a 
certain point within the test?
Ans:Set Toggle BreakPoint.

8.What does a right-pointing green triangle at the begging of the command in 
SIDE indicate?
Ans:Play Entire Test Suite

9.Which wildcards does SIDE support?
Ans:*, [ ]

10.What are the four types of regular expression quantifiers?
Ans:* quantifier: 0 or more of the preceding character (or group)
+ quantifier: 1 or more of the preceding character (or group)

11.What regular expression special character(s) means “any character”?
Ans:(.*)
12.What distinguishes between an absolute and relative URL in SIDE?
Ans:Absolute URL: Its is base url and this represent domain address.
Relative URL: (Absolute URL + Page Path).

13.How would one access a selenium variable named “count” from within a 
javaScript snippet?
Ans:${count}

14.What selenium command can be used to display the value of the variable in the log file which can be very valuable for debugging?
Ans:echo()

15.If one wanted to display the value of a variable named answer in the log 
file,what would the first argument to the previous commend look like?
Ans:echo()
16.Which selenium command(s) simulates selecting a link?
Ans:click, clickandWait, ClickAt, ClickAtandWait, DoubleClick, DoubleClickandWait, doubleClickAt, doubleClickAtandWait

17.Which two commends can be used to check that an alert with a particular 
message popped up?
Ans:The following commands are available within Selenium for processing Alerts:
• getAlert()

HappyestMind  & Ness

Q1. Write the syntax of drop down.
Ans:Select dropdown = new Select(driver.findElement(By.id("designation")));
To select its option say 'Programmer' you can do
dropdown.selectByVisibleText("Programmer ");
or
dropdown.selectByIndex(1);
or
 dropdown.selectByValue("prog");

Q2.What is Web driver?

Ans- Web driver  is  super most Java interface to develop Automation Script.

Q3.What is the current Version of Selenium web driver?

Ans-selenium-java-2.44.0

Q4.How to get the text value from text box

Ans: driver.findElements(By.name(“username”).sendkeys(“admin”);

String textvalue=driver.findElements(By.name(“username”).getvalue();

Q5.StrinG x="ABC";

  String x="ab"; does it create two objects?

Ans:No

Q6. write a program to compare the strings?
Ans:== compares Object reference

.equals() compares String value

Sometimes == gives illusions of comparing String values, in following cases

String a="Test";
String b="Test";
if(a==b) ===> true
This is a because when you create any String literal, JVM first searches for that literal in String pool, if it matches, same reference will be given to that new String, because of this we are getting

(a==b) ===> true

                       String Pool
     b -----------------> "test" <-----------------a
== fails in following case

String a="test";
String b=new String("test");
if (a==b) ===> false
in this case for new String("test") the statement new String will be created in heap that reference will be given to b, so b will be given reference in heap not in String Pool. Now a is pointing to String in String pool while b is pointing to String in heap, because of that we are getting

if(a==b) ===> false.

                String Pool
     "test" <-------------------- a

                   Heap
     "test" <-------------------- b
While .equals() always compares value of String so it gives true in both cases

String a="Test";
String b="Test";
if(a.equals(b)) ===> true

String a="test";
String b=new String("test");
if(a.equals(b)) ===> true
So using .equals() is awalys better.


Q7.Class a

{

}

class b extends a

{

}

A a= new A();

B b=new B();

A a= new B();

B a=new A();

Which is valid and invalid?

Ans-  B a=new A(); is invalid other all are valid.

Q8.How to handle different type of pop up.(Wnidow,Alerts,Invisible popup)

Ans- Window:

Set<String> set=driver.getWindowHandles();

Iterator<String>it=set.iterator();

String pid=it.next();

String cid=it.next();

driver.switchTo().window(cid);

Alert:

Alert alt=driver.switchTo().alert();

System.out.println(alt.getText());

ss

alt.dismiss();

//alt.accept(

Q9.How to handle DropDown.
Duplicate

Q10. How to handle SSL certificate
Ans:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);

Q11.How to handle Google search text.
Ans:import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class AutoSugesstEditBox {

public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.co.in/?gws_rd=cr");
driver.findElement(By.id("gbqfq")).sendKeys("cognizant wiki" ,Keys.ENTER);



}

}


Q12. How to handle dynamic text box which contains the 3 numbers, get
the number and add the three number and add it other text box.
Ans:Using Following Sibiling xpath concept We identify Web elements  take reference of static part (Label) .Then Use getvalue() store any variable apply operation values then pass using sendkeys .

Q13. How to handle Ajax Objects.

Ans-Using Explicit wait and Following sibling xpath  concept.

Q8.Explain webdriver architecture
Ans:Refer this link http://advanceseleniumhelp.blogspot.in/2014/12/what-is-selenium-webdriver-architecture.html

Q9. Explain File downloading.

Ans:Change browser native setting in browser
FirefoxProfile profile = new FirefoxProfile();
        String path = "D:\\Downloads_sel";
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.dir", path);
        profile.setPreference("browser.download.alertOnEXEOpen", false);
        profile.setPreference("browser.helperApps.neverAsksaveToDisk", "application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel");
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.download.manager.focusWhenStarting", false);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
        profile.setPreference("browser.download.manager.closeWhenDone", false);
        profile.setPreference("browser.download.manager.showAlertOnComplete", false);
        profile.setPreference("browser.download.manager.useWindow", false);
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
        profile.setPreference("pdfjs.disabled", true);

        WebDriver driver = new FirefoxDriver(profile);



Q10.Explain how to get data from drive other that Auto IT

Ans-Using Appachi POI Api Lib  and Javascript

Q11.Write the syntax for finding the row count in dynamic web table

Ans-Using contains find Xpath then find  

Q12.Differnece between class and Interface
Ans:
abstract ClassesInterfaces
1 abstract class can extend only one class or one abstract class at a time interface can extend any number of interfaces at a time
2 abstract  class  can extend from a class or from an abstract class interface can extend only from an interface
3 abstract  class  can  have  both  abstract and concrete methods interface can  have only abstract methods
4 A class can extend only one abstract class A class can implement any number of interfaces
5 In abstract class keyword ‘abstract’ is mandatory to declare a method as an abstract In an interface keyword ‘abstract’ is optional to declare a method as an abstract
6 abstract  class can have  protected , public and public abstract methods Interface can have only public abstract methods i.e. by default
7 abstract class can have  static, final  or static final  variable with any access specifier interface  can  have only static final (constant) variable i.e. by default

Q13. What type of class is the string class
Ans: Immutable  
Q14.What are the different methods that are used along with Xpath

Ans; Text().Normalize-space,contains,Following-sibiling

Q15. Explain Interface
Ans:The interface in java is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java.
Java Interface also represents IS-A relationship.

Q16 Explain Abstract
Ans:A class that is declared with abstract keyword, is known as abstract class in java. It can have abstract and non-abstract methods (method with body).
Before learning java abstract class, let's understand the abstraction in java first.

Q17.What is selenium grid?

Ans: Selenium Grid

Selenium Grid is a tool used together with Selenium RC to run parallel tests across different machines and different browsers all at the same time. Parallel execution means running multiple tests at once.

Selenium grid are used to run the test scripts in remote machine 

Features:
 Enables simultaneous running of tests in multiple browsers and 
environments.
 Saves time enormously.
 Utilizes the hub-and-nodes concept. The hub acts as a central source of 

Selenium commands to each node connected to it.

Q18 What is selenium RC

Ans- RC is l  tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.
Selenium RC comes in two parts. 

  1. A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them.
  1. Client libraries for your favorite computer language.

Q19. Why is key word driven frame work only chosen?

Ans-In which  Test scripts writing in Excel files using Generic Method , Easy to 

write Test script User Friendly and For application is big

Q1. How to handle dynamic object?
Ans:Text().Normalize-space,contains,Following-sibiling

Q2. How to work with button which is in div tag and and u have to click without using xpath?
Ans:Using Java Script

Q3. JVM is dependent or independent platform

Ans-Dependent

Q4. How many Test script you write in day

Ans : 1 to 2 or depend upon page navigation

Q5. Describe your framework

Ans: I work on Hybrid Frame which is combination of Data driven and Modular 

Driven

My frame components are:

1. Controller/Driver/Run me:-XML file control all frame

2. TestNG Lib:- Actual Test Case

3. Generic Lib:-Reusable Methods for all  app

4. Data Folder:  Project  related Data

5. Business Lib: Project specific  Common Method

6. PageFactory Lib: Contain all web elements or xpath

7. SnapShot: In case of test failure snapshot  taken by framework easy to 

analysis  failure

8. Report :Store final Report

Q.6. How to parameterized your junit

Ans: No possible in Junit

Q.How to handle ssl security
Ans Duplicate

Q8. How to handle window pops
Ans: Window:

Set<String> set=driver.getWindowHandles();

Iterator<String>it=set.iterator();

String pid=it.next();

String cid=it.next();

driver.switchTo().window(cid);

Q9. Differentiate  between implicit and explicit

Ans:Implicit wait: wait until page load

Explicit wait: wait until  web element  present

Q10.What are the types of assertion and what are assertion you used in your project?
Ans:Assertion Basically used for validation or condition

Q11.How to handle ssl certificate?
Ans:Duplicate
Q12.What is dom concept.?
Ans:https://www.simple-talk.com/dotnet/.net-framework/xpath,-css,-dom-and-selenium-the-rosetta-stone/

Q13.What is the challenges u have faced during Automation
Ans:Selenium Open Source Not Support Available
>Compatibility issues with different-2 Tools and Version 
>Can't able to automate some complex Scenario exp: Capcha Automation
>To handle Dynamic application (Ajax Application)


Q14What is generics?
Ans: Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods or, with a single class declaration, a set of related types, respectively.
or Used in  Any data according to requirement

Q15.What is synchronization in JAVA?
Ans-It used to give access to thread single time one thread use resource in 
multi thread environment

Q1.JVM is dependent or independent platform

Q2: Differences  Between hashmap and hash set, set and linkedlist, arraylist and vector list , linkedhash set and hashset
Ans:
HashSetHashMap
HashSet class implements the Set interfaceHashMap class implements the Map interface
In HashSet we store objects(elements or values) e.g. If we have a HashSet of string elements then it could depict a set of HashSet elements: {“Hello”, “Hi”, “Bye”, “Run”}HashMap is used for storing key & value pairs. In short it maintains the mapping of key & value (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This is how you could represent HashMap elements if it has integer key and value of String type: e.g. {1->”Hello”, 2->”Hi”, 3->”Bye”, 4->”Run”}
HashSet does not allow duplicate elements that means you can not store duplicate values in HashSet.HashMap does not allow duplicate keys however it allows to have duplicate values.
HashSet permits to have a single null value.HashMap permits single null key and any number of null values.

List Vs Set

1) List is an ordered collection it maintains the insertion order, which means upon displaying the list content it will display the elements in the same order in which they got inserted into the list.

Set is an unordered collection, it doesn’t maintain any order. There are few implementations of Set which maintains the order such as LinkedHashSet (It maintains the elements in insertion order).

2) List allows duplicates while Set doesn’t allow duplicate elements. All the elements of a Set should be unique if you try to insert the duplicate element in Set it would replace the existing value.

3) List implementations: ArrayList, LinkedList etc.

Set implementations: HashSet, LinkedHashSet, TreeSet etc.

4) List allows any number of null values. Set can have only a single null value at most.

5) ListIterator can be used to traverse a List in both the directions(forward and backward) However it can not be used to traverse a Set. We can use Iterator (It works with List too) to traverse a Set.


6) List interface has one legacy class called Vector whereas Set interface does not have any legacy class.
ArrayList Vs Vector:

1) Synchronization: ArrayList is non-synchronized which means multiple threads can work on ArrayList at the same time. For e.g. if one thread is performing an add operation on ArrayList, there can be an another thread performing remove operation on ArrayList at the same time in a multithreaded environment

while Vector is synchronized. This means if one thread is working on Vector, no other thread can get a hold of it. Unlike ArrayList, only one thread can perform an operation on vector at a time.

2) Resize: Both ArrayList and Vector can grow and shrink dynamically to maintain the optimal use of storage, however the way they resized is different. ArrayList grow by half of its size when resized while Vector doubles the size of itself by default when grows.

3) Performance: ArrayList gives better performance as it is non-synchronized. Vector operations gives poor performance as they are thread-safe, the thread which works on Vector gets a lock on it which makes other thread wait till the lock is released.

4) fail-fast: First let me explain what is fail-fast: If the collection (ArrayList, vector etc) gets structurally modified by any means, except the add or remove methods of iterator, after creation of iterator then the iterator will throw ConcurrentModificationException. Structural modification refers to the addition or deletion of elements from the collection.

As per the Vector javadoc the Enumeration returned by Vector is not fail-fast. On the other side the iterator and listIterator returned by ArrayList are fail-fast.

5) Who belongs to collection framework really? The vector was not the part of collection framework, it has been included in collections later. It can be considered as Legacy code. There is nothing about Vector which List collection cannot do. Therefore Vector should be avoided. If there is a need of thread-safe operation make ArrayList synchronized as discussed in the next section of this post or use CopyOnWriteArrayList which is a thread-safe variant of ArrayList.

There are few similarities between these classes which are as follows:

Both Vector and ArrayList use growable array data structure.
The iterator and listIterator returned by these classes (Vector and ArrayList) are fail-fast.
They both are ordered collection classes as they maintain the elements insertion order.
Vector & ArrayList both allows duplicate and null values.
They both grows and shrinks automatically when overflow and deletion happens.
When to use ArrayList and when to use vector?

It totally depends on the requirement. If there is a need to perform “thread-safe” operation the vector is your best bet as it ensures that only one thread access the collection at a time.


Performance: Synchronized operations consumes more time compared to non-synchronized ones so if there is no need for thread safe operation, ArrayList is a better choice as performance will be improved because of the concurrent processes.
Difference between HashSet and LinkedHashSet:
A HashSet is unordered and unsorted Set. LinkedHashSet is the ordered version of HashSet.

The only difference between HashSet and LinkedHashSet is that LinkedHashSet maintains the insertion order. When we iterate through a HashSet, the order is unpredictable while it is predictable in case of LinkedHashSet.

The reason why LinkedHashSet maintains insertion order is because the underlying data structure is a doubly-linked list.

When to use LinkedHashSet over HashSet:

LinkedHashSet should be used in preference to HashSet when we want to iterate over the elements as per the insertion order. If order does not matter, then we can go for HashSet.
Q3.abstract and interface

Q4.throw and throws
Ans:
Throw vs Throws in java

1. Throws clause in used to declare an exception and thow keyword is used to throw an exception explicitly.

2. If we see syntax wise than throw is followed by an instance variable and throws is followed by exception class names.

3. The keyword throw is used inside method body to invoke an exception and throws clause is used in method declaration (signature).



for e.g.

Throw:

....
static{
try {
throw new Exception("Something went wrong!!");
} catch (Exception exp) {
System.out.println("Error: "+exp.getMessage());
}
}
....
Throws:

public void sample() throws ArithmeticException{
 //Statements

.....

 //if (Condition : There is an error)
ArithmeticException exp = new ArithmeticException();
 throw exp;
...
}
4. By using Throw keyword in java you cannot throw more than one exception but using throws you can declare multiple exceptions. PFB the examples.

for e.g.

Throw:

throw new ArithmeticException("An integer should not be divided by zero!!")
throw new IOException("Connection failed!!")
Throws:

throws IOException, ArithmeticException, NullPointerException, 

ArrayIndexOutOfBoundsException


Q6.checked and unchecked exception

Ans:Checked and unchecked exceptions in java with examples
EXCEPTION HANDLING
There are two types of exceptions: checked exceptions and unchecked exceptions. In this tutorial we will learn both of them with the help of examples. The main difference between checked and unchecked exception is that the checked exceptions are checked at compile-time while unchecked exceptions are checked at runtime.

What are checked exceptions?

Checked exceptions are checked at compile-time. It means if a method is throwing a checked exception then it should handle the exception using try-catch block or it should declare the exception using throws keyword, otherwise the program will give a compilation error. It is named as checked exception because these exceptions are checked at Compile time.

Lets understand this with this example: In this example we are reading the file myfile.txt and displaying its content on the screen. In this program there are three places where an checked exception is thrown as mentioned in the comments below. FileInputStream which is used for specifying the file path and name, throws FileNotFoundException. The read() method which reads the file content throws IOException and the close() method which closes the file input stream also throws IOException.

import java.io.*;
class Example {  
   public static void main(String args[]) 
   {
FileInputStream fis = null;
/*This constructor FileInputStream(File filename)
* throws FileNotFoundException which is a checked
* exception*/
        fis = new FileInputStream("B:/myfile.txt"); 
int k; 

/*Method read() of FileInputStream class also throws 
* a checked exception: IOException*/
while(( k = fis.read() ) != -1) 

System.out.print((char)k); 


/*The method close() closes the file input stream
* It throws IOException*/
fis.close();
   }
}
Output:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
Unhandled exception type FileNotFoundException
Unhandled exception type IOException
Unhandled exception type IOException

Why this compilation error? As I mentioned in the beginning that checked exceptions gets checked during compile time. Since we didn’t handled/declared the exceptions, our program gave the compilation error.
How to resolve the error? There are two ways to avoid this error. We will see both the ways one by one.

Method 1: Declare the exception using throws keyword.
As we know that all three occurrences of checked exceptions are inside main() method so one way to avoid the compilation error is: Declare the exception in the method using throws keyword. You may be thinking that our code is throwing FileNotFoundException and IOException both then why we are declaring the IOException alone. Th reason is that IOException is a parent class of FileNotFoundException so it by default covers that. If you want you can declare that too like this public static void main(String args[]) throws IOException, FileNotFoundException.

import java.io.*;
class Example {  
   public static void main(String args[]) throws IOException
   {
      FileInputStream fis = null;
      fis = new FileInputStream("B:/myfile.txt"); 
      int k; 

      while(( k = fis.read() ) != -1) 
      { 
  System.out.print((char)k); 
      } 
      fis.close();
   }
}
Output:
File content is displayed on the screen.

Method 2: Handle them using try-catch blocks.

The above approach is not good at all. It is not a best exception handling practice. You should give meaningful message for each exception type so that it would be easy for someone to understand the error. The code should be like this:

import java.io.*;
class Example {  
   public static void main(String args[])
   {
FileInputStream fis = null;
try{
   fis = new FileInputStream("B:/myfile.txt"); 
}catch(FileNotFoundException fnfe){
            System.out.println("The specified file is not " +
"present at the given path");
}
int k; 
try{
   while(( k = fis.read() ) != -1) 
   { 
System.out.print((char)k); 
   } 
   fis.close(); 
}catch(IOException ioe){
   System.out.println("I/O error occurred: "+ioe);
}
   }
}
This code will run fine and will display the file content.

Here are the few other Checked Exceptions –

SQLException
IOException
DataAccessException
ClassNotFoundException
InvocationTargetException
What are Unchecked exceptions?

Unchecked exceptions are not checked at compile time. It means if your program is throwing an unchecked exception and even if you didn’t handle/declare that exception, the program won’t give a compilation error. Most of the times these exception occurs due to the bad data provided by user during the user-program interaction. It is up to the programmer to judge the conditions in advance, that can cause such exceptions and handle them appropriately. All Unchecked exceptions are direct sub classes of RuntimeException class.

Lets understand this with an example:

class Example {  
   public static void main(String args[])
   {
int num1=10;
int num2=0;
/*Since I'm dividing an integer with 0
* it should throw ArithmeticException*/
int res=num1/num2;
System.out.println(res);
   }
}
If you compile this code, it would compile successfully however when you will run it, it would throw ArithmeticException. That clearly shows that unchecked exceptions are not checked at compile-time, they are being checked at runtime. Lets see another example.

class Example {  
   public static void main(String args[])
   {
int arr[] ={1,2,3,4,5};
/*My array has only 5 elements but
* I'm trying to display the value of 
* 8th element. It should throw
* ArrayIndexOutOfBoundsException*/
System.out.println(arr[7]);
   }
}
This code would also compile successfully since ArrayIndexOutOfBoundsException is also an unchecked exception.

Note: It doesn’t mean that compiler is not checking these exceptions so we shouldn’t handle them. In fact we should handle them more carefully. For e.g. In the above example there should be a exception message to user that they are trying to display a value which doesn’t exist in array so that user would be able to correct the issue.

class Example {  
public static void main(String args[])
{
try{
int arr[] ={1,2,3,4,5};
System.out.println(arr[7]);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("The specified index does not exist " +
"in array. Please correct the error.");
}
}
}
Here are the few most frequently seen unchecked exceptions –

NullPointerException
ArrayIndexOutOfBoundsException
ArithmeticException
IllegalArgumentException

7.How to work with ajax application
Ans:Duplicate

8.Why string is immutable

AnsThere are multiple reasons that String is designed to be immutable in Java. A good answer depends on good understanding of memory, synchronization, data structures, etc. In the following, I will summarize some answers.

1. Requirement of String Pool

String pool (String intern pool) is a special storage area in Java heap. When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead of creating a new object and returning its reference.

The following code will create only one string object in the heap.

view sourceprint?
1.
String string1 = "abcd";
2.
String string2 = "abcd";
Here is how it looks:
java-string-pool

If string is not immutable, changing the string with one reference will lead to the wrong value for the other references.

2. Allow String to Cache its Hashcode

The hashcode of string is frequently used in Java. For example, in a HashMap. Being immutable guarantees that hashcode will always the same, so that it can be cashed without worrying the changes.That means, there is no need to calculate hashcode every time it is used. This is more efficient.

3. Security

String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Were String not immutable, a connection or file would be changed and lead to serious security threat. The method thought it was connecting to one machine, but was not. Mutable strings could cause security problem in Reflection too, as the parameters are strings.

Here is a code example:

view sourceprint?
1.
boolean connect(string s){

if (!isSecure(s)) {

throw new SecurityException();

}
//here will cause problem, if s is changed before this by using other references.   
causeProblem(s);

}

9.What is the return type of getwindowhandles() method?

Ans: Set

11.  Difference between interface and Abstract classes
Ans Duplicate

12.What is static variable
Ans:Static variable

syntax:

static int age;
Note: Static variable’s value is same for all the object(or instances) of the class or in other words you can say that all instances(objects) of the same class share a single copy of static variables.

lets understand this with an example:



class VariableDemo
{
   static int count=0;
   public void increment()
   {
       count++;
   }
   public static void main(String args[])
   {
       VariableDemo obj1=new VariableDemo();
       VariableDemo obj2=new VariableDemo();
       obj1.increment();
       obj2.increment();
       System.out.println("Obj1: count is="+obj1.count);
       System.out.println("Obj2: count is="+obj2.count);
   }
}
Output:

Obj1: count is=2
Obj2: count is=2
As you can see in the above example that both the objects of class, are sharing a same copy of static variable that’s why they displayed the same value of count.

Static variable initialization

Static variables are initialized when class is loaded.
Static variables in a class are initialized before any object of that class can be created.
Static variables in a class are initialized before any static method of the class runs.
Default values for declared and uninitialized static and non-static variables are same

primitive integers(long, short etc): 0
primitive floating points(float, double): 0.0
boolean: false
object references: null

Static final variables

static final variables are constants. consider below code:

public class MyClass{
   public static final int MY_VAR=27;
}
Note: Constant variable name should be in Caps! you can use underscore(_) between.
1) The above code will execute as soon as the class MyClass is loaded, before static method is called and even before any static variable can be used.
2) The above variable MY_VAR is public which means any class can use it. It is a static variable so you won’t need any object of class in order to access it. It’s final so this variable can never be changed in this or in any class.

Key points:
final variable always needs initialization, if you don’t initialize it would throw a compilation error. have a look at below example-

public class MyClass{
    public static final int MY_VAR;
}
Error: variable MY_VAR might not have been initialized

13.What is volatile
Ans:http://java.dzone.com/articles/java-volatile-keyword-0

14. What is transient
Ans:The keyword transient in Java used to indicate that the variable should not be serialized. By default all the variables in the object is converted to persistent state. In some cases, you may want to avoid persisting some variables because you don’t have the necessity to transfer across the network. So, you can declare those variables as transient. If the variable is declared as transient, then it will not be persisted. It is the main purpose of the transient keyword. - See more at: http://www.javabeat.net/what-is-transient-keyword-in-java/#sthash.OxB1eGFv.dpuf


Q:What is the difference between final, finally and finalize() in Java?
Ans

• final – a key word / access modifier to define constants.
• finally – The finally block always used in conjunction with try and catch blocks, except that, if try block uses System.exit(0) call. It is ensured that in event of an unexpected error / exception, the finally block performs the execution. Not only for exception handling, finally also even utilized for cleaning up the code, such as returning values, continue or break statement usage, closing streams etc. It is a good programming practice to use cleaning up the code in finally block, even though exceptions are not anticipated. 

• finalize() – This method is associated with garbage collection. Just before collecting the garbage by the system (discarding an object from its scope), this method is invoked automatically.

16.what is the difference between Public,private and protected
Ans:Public variables, are variables that are visible to all classes.
Private variables, are variables that are visible only to the class to which they belong.
Protected variables, are variables that are visible only to the class to which they belong, and any subclasses.

FICO

1.What is the default package in java ?
Ans:java.lang

2.: Why we use interface why not abstract class ...what if i implements same 
method in interface and abstract ....then ?? any difference??
Ans:For 100% abstraction we used interface for implementing interface we require class .

3. What are inner classes ..name them ?
Ans: Class in a class is called inner class
1.Static Nested Inner class
2.Member Inner class
3.Method Local-Inner class
4. Anonymous Inner class 

4.In public static void main(String arr[])... what if i replace public with private 

........... remove static ........replace void with string
Ans: Its change Normal method its not execute because JVM search main method syntax .

5.In hash map we have (key and value ) pair , can we store inside a value =(key, value ) again ??
Ans:Yes

5. What are variable scope in  java(in class , in method , in static block)
Ans: Private,Within Method,Execution One during class loading time

6. What  are the oops concept ? explain them each with real world examples

7.Write a program so that when ever u create a object ... u get to know how many object u have created

8. What is singleton classes ?

9.What is difference  between .equals() , (==)  and compare-to();

10. What is the difference   between hash code and equals

11.write a program to get sub string of string  ex: javaisgood ... so result : avais

12.Write a program to reverse the string

13. Write a program  for binary search

14.What is the use of package

15. Why we use interface and abstract

16.We have 2 interface both have print method , in my class i 

have implemented the print method , how u wil get to know that i 

have implemented the first interface and how u will use it .. if u want to use it

17.What is the difference between vector list and arraylist

18. Difference between hash map and hash table, what is synchronization , how it is achieved

19. What is the use of collection, when we use it

20. What is priority queue in collection , what is the use , how u have use in your project

21.Where  to use hash map and hash table

22. Where u have use the concept of interface and abstract in your framework


SPAN Info tech 

Selenium question:

How to work  with dynamic webtable ?

What is asserstion & types of asserstion ?

What to work with file attachment & file download in webdriver ?

How to file attachment with out Autoit scripts ?

How to work with weblist @ radio button in webdriver ?

What is the difference between the implicit wait & webdriver wait ?

Which repository you have used to store the test scripts ?

What is Check-in & check-out , revert ?

How to work with Radio buttun ?

How to work with weblist ?

What is the use of Actions class in webdriver?

How to work with keybord and mouse opration in java ?

How to get the text from the UI in runtime ? 

Expain the Architructure of Webdriver?

How to run the test scripts with mulitiple browser ?

Java Questions 

In parent and child class i have disp() method , using child class reference how to call parent disp() method ?

What is the use of this keyword

How many types exception available in java?

Difference between final finally , finalize?

Difference between Overriding and overload ?

Difference between map & set ?

Mind tree interview Question

Selenium

1. how to handle dynamic object 

2. how to work with button which is in div tag and and u have to click without 

using xpath

3. JVM is dependent or independent platform

4.How many Test script you write in day

5. Describe your framework

6. How to parameterized your junit

7.How to handle ssl security

8. How to handle window pops

9. Difference  between implicit and explicit

10.What are the types of assertion and what are assertion in junit

Interview Questions AltiMetrik 

1 What is inheritance?Explain the use of inheritance?

2 What is abstract class?

3 What is interface?

4 When to use inheritance and when to use abstract class?

5 What happened if i not provide abstract method in abstract class 

and interface?

6 What is method overriding java what is the use of method 

overriding?

7 What is constructor ?use of constructor and can i override the 

constructor?

8 how to call the super class method in subclass?

9 what is the base class for all java class?tell me the methods?

10 What is hash code method explain grammatically(asked 

implementation of hash code method)?

11 What is toString method ?what happens when i use in the program 

explain? 

12 What is String builder?

13 What is String tokenizer?

14 What is the difference between string and String Buffer?

15 What is the capacity of String Buffer?

16 What is collection ?

17 What is list?

18 What is Array list Explain?

19 Write logic for Array to Array list?

20 Write logic for Array list to Array?

21 Why vector class is defined Synchronized ?

22 What is exception ?

22 Difference between Throw And Throws?

23 What is custom Exception explain?

24 What is finally block?Use of Finally block?explain

25 What happens if exception not found in try catch block?

Then finally block will be Executed or not

Questions from Infinite

if u have multiple alerts, how do you handle it.

if you have two password/Re-enter password

assert equals/assert same

navigate() and switch to

one webdriver driver is opened, what to do to make addons to work

how to join two sets/answer: by using addon method....

what are all the collections you used

india/all states, need to select the last value of the dropdown list

Software AG

How to work with ajax application, flash, frame, log files, 

log file will generated, for each action u do...ex: for gmail, compose mail;> there 

would be some log generated....so how to capture that log...

if you have a .bat file, how do you call that...

what exactly you call for this..

how you will make sure that page has been loaded...

StarMark Interview Questions

1. Diff between static and non static

2. What is multiple inheritance 

3. Write program for prime no.

4.How to run build.xml through command prompt

5. Diff b/w overloading and overriding

6. how many wait methods you are using in webdriver

7. Difference between assertion and verification 

8. What are the roles and responsibilities.

9. Why TestNG is better than JUNIT

HCL interview Questions:

1. difference between string and string buffer?

2. difference between linked list and arraylist?

3. thread concepts?

4. why string class is immutable?

5. Singleton class?

Adobe Interview Questions:

1. Retrieve the test data from excel sheet, put in in google search bar, click on 

search button and click on the first link opened in google search.

2. Write a program to check whether the string can be a palindrome. for example if 

the string aab(it is not a palindrom string). replace the characters in a string like 

aba, baa etc. and check that can be a palindrome string.

3. How will you Identify the webelement that has same property values?

4. write a pgm to return the no.of rows and columns in a webtable?

5. Write a prm to return the row and colum value like(3,4) for a given data in web 

table?

interview question fro  m companies(happest minds,emids and adobe)

1) how to create a folder in build.xml

2) describe about your framework.

3) difference between selenium rc and selenium webdriver

4) explain the architecture of your project

5) draw ur framework

6) write a code for fetching the data from excel sheet

7) write a code for palindrome

Explain about jenkins

9) Explain about ur control version tool

10) How to handle with drop down

11) How to handle window id

12) How to handle with google search text box

13) How to handle alert and window pop up

14) How u will get the frame id

15) How to handle dynamic webtable

16) Why we are using follwing siblings

17) Create a pagefactory for login page

18) How u will group,how u will add classes from different packages

EBAY  InterView Questions

TESTNG QUESTIONS ASKED IN EBAY

1. What is the use of TestNG/Junit ?

2. What is parameterized testing?

3. How can u achieve parameterized testing using TestNG?

With the help of 2 annotations @Parameters and @Dataprovider.

4. Can you map test method names in XML file along with class names?

Yes, we can do it please see below ex:

<classes>

<class name="test.IndividualMethodsTest">

<methods>

<include name="testMethod" />

</methods>

</class>

</classes>

5. Sequence of execution of below annotations:

@Test

@BeforeGroups

@AfterGroups

@BeforeSuite

@AfterSuite

@BeforeMethod

@AfterMethod

@BeforeClass

@AfterClass

6. What is Yaml file?

TestNG supports YAML as an alternate way of specifying your suite file.You 

might find the YAML file format easier to read and to maintain. YAML files are 

also recognized by the TestNG Eclipse plug-in. 

7. How will you execute only selected test methods in particular Test class?

8. How do you fail test cases in TestNg?

9. Can we execute test cases parallely in TestNg?

10. How can we control the order of test method invocation?

We need to create Dependency.

TestNG allows you to specify dependencies either with annotations or in XML.: 

You can use the attributes dependsOnMethods or dependsOnGroups, found on the 

@Test annotation.

Alternatively, you can specify your group dependencies in the testng.xml file. You 

use the <dependencies> tag to achieve this: 

11. How can you make sure test methods which are run in a certain order doesn't 

really depend on the success of others ?

By adding "alwaysRun=true" in your @Test annotation.

ACCOLITE INTERVIEW QUESTIONS:

1.What is the use of static keyword in Main()?

2.Can a class without main() gets compilation successful?

3.Difference between abstract and interface.

4.Example of function overloading in Selenium Webdriver

5.Can we private access specifier inside interface?

6.Is there any way to De Allocate memory in JAVA?

7.What is the use of finalize method? whether implementation is already available.

8.How do you handle drop down list box.

9.Write a Program  for removing white spaces in a String?

10.Write five critical test cases for the above written Program.

11.What is missing in Selenium Webdriver compared to Selenium RC?

12.You have a parametrized constructor, whether it will call default constructor 

first? or directly it will call parametrized contructor?

13.What is the difference between Webdriver Wait(Explicit Wait) and Implicit 
wait?
14.Write a xpath using following-sibling?

15.How will you analyze the failures after giving a run in the TestNG framework?

16.Explain the Selenium Webdriver Architecture?

17.Explain The framework you were using ?

18.What is Object class?

19.Jenkins Tool - Scheduled Batch Run - any idea

20.What is the current version of Selenium Webdriver ? What are the other 

languages do Selenium Support?

21.How are you writing log files in your framework?Using Log4J Jars or any other 

methods.

22.How to handle SSL certificate?

23.What is the latest version of selenium webdriver?

All interview Qustions

HeadStronginterview qustions

1.Explain framework

2.Page factory model code?diffrence between pagefactory and page object model?

3.What is object repository?

4.How to overwrite a data in excel sheet?

5.Explain different frame works.

6.What are property files?

7.How grouping is done in testng xml.

8.How to run tests in different browser.

9.How to handle alerts.

10.jdbc connections?

11.How to report ?

12.common method for reverse a string?

13.challenges faced during last project and Automation using selenium?

14.String s=”AABBBCFFDD” Count the presence of each letter.

15 WAP for print triangle .

16.Class and interface difference?

17 Interface and inheritance difference?

18.What is polymorphism?

19.Difference between string and string builder?

20.what is static variable,

21.what is null pointer exception .

22.What are the exception you found?

23.Bug lifecycle?

24.Web driver waits and implicit wait?

25.Can we write multiple CATCH in webdriver code?

26.If we close the driver in try block then,FINALLY will execute or not?

27.What are the different types of framework ?

28.Why we go for hybrid frame work?

29.Diffrence between data driven and modular f/w?

Exlliant Interview qustions

1.What is testng?why we go for testng?

2.Can we run a test without testng?

3.What is the difference between verification and valiation?

4.What are the different locators in selenium?

5.What is xpath?

6. Diffrence between absolute and relative path?

7.What is difference between abstract class and interface?

8.hat in diff between method overloading and constructor overloading?with 

example?

9. Difference between string and string buffer?

10.what is overriding ?

11.how to handle dynamic elements?

12.how to get the no of emp getting same salary?

CalSoft labs interview qustions?

1.Explain your framework?

2.How to do grouping?with code?

3.How to handle different pop ups?

4.Difference between string and string buffer?

5.What is difference between abstract class and interface?

6. Difference between final,finally,finalize?

7. Difference between normal class and final class?

8.How to handle frames without having any attributes?

9. Difference between smoke and sanity testing?

10. QA process you follows?

11.Adapter design in java?

Bosch interview Questions

1.Reverse a string without using inbuilt functions?

2.Sorting of numbers?

3.Generic method for select drop down?

4.generic code for fetching data from xl sheet?

5.What is testNg?

6.What is selenium grid?write the code?

7.How to do parallel execution?

8.How to handle ssl certification in ie?

9.How to handle popup’s?

10.How to fetch all the options in auto suggest?

11.How to upload a file ?write the code?

12.How to generate daily execution report?

13.Explain frame work?

14.Difference between junit and testng?

Techmetric interview 

1.What is webdriver?

2.Where all of abstract methods of webdriver are implemented?

3.How to handle dynamics webelement?

5.How to fetch data from excel sheet?

6.How to write xpath,css?

7.How to connect to the database?

HappiestMind interview questions

1.What is collection in java.

2.Play with any of the collections.

3.Search a letter in string?

4.reverse a number?

5. sorting an array?

6 .What is page object model?

7 Difference between css and xpath which one is faster?

8.What is exception.tell some exception.

9.Tell some exception you get while writing code.

10.How to handle exception ?

11.Is it a good approach to than exception?

14.How to generate a report?

15.How many test case you have automated.

16.How many test case you run in a batch execution?

17.What is the minimum time to run a batch execution?

18.Tell me complex scenario of your application?

19.Challenges you faced in automation.

20.how to upload file other than Autoit?

21.Negative test case for a pen?

22.How to run a test 3 times if the test fail ?

Happiest Minds Technologies

1. What is the diff between STRING and STRING BUFFER.

2. WAP For String Reverse.

3. Find how many duplicate values in Array List.

4. String [] str={"abc","efg","fgh"};
convert array to string.

5. About file downloading and uploading.

6. What is Page Factory explain?.

7. Explain method overloading and overriding .. how practically 
implemented in your project.

8. What are the challenges of SELENIUM.

9. Explain the features of JAVA.

10. How do u say JAVA is platform independent.

11. Is JVM platform independent.

12. Write code for data fetch of excel Sheet.

13. Explain how do u access DB in selenium.

14. Explain ANT and what are the pros and cons. 

15. How do u achieve parallel execution in TestNG.

16. What is the dictionary meaning of SELENIUM.


4 comments:

  1. thanks very soon you will get website...

    ReplyDelete
  2. "Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.php jobs in hyderabad.
    "

    ReplyDelete

Translate

Popular Posts

Total Pageviews