Informative Questions and Answers

1. How to maximize a browser in webdriver?
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();

2. How to run selenium server from command prompt?
    java –jar selenium-server-standalone.jar

3. How many test cases can be automated per day?
    No. of test cases automated per day depends upon:
  • Complexity of the test case or test scenario
  • Size of the test case to be automated.
  • Dependency of the test case
4. What challenges you have faced in selenium?
  • Handling dynamic objects
  • No event trigger from value changes: (used selenium.FireEvent(cmbCategory, “onchange”));
  • Handling Windows
  • Working with frame
5. What is latest version of selenium available?

Selenium WebDriver 3.0.0-beta2

6. What is difference between assert and verify command?
If assert fails the test will be aborted, but if verify fails then also test will be continued.

7. What is jar file?
JAR (Java Archive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file.

8. What is war file?
WAR file (or Web application ARchive) is a JAR file used to distribute a collection of JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static web pages (HTML and related files) and other resources that together constitute a web application.

10. What is difference between abstract class and interface?
1) Abstract class can have abstract and non-abstract methods while Interface can have only abstract methods.
2) Abstract class doesn't support multiple inheritance while Interface supports multiple inheritance.
3) Abstract class can have final, non-final, static and non-static variables while inInterface has only static and final variables.
4) Abstract class can have static methods, main method and constructor while Interface can't have static methods, main method or constructor.
5) Abstract class can provide the implementation of interface but Interface can't provide the implementation of abstract class.
6) The abstract keyword is used to declare abstract class and interface keyword is used to declare interface.

Example of Abstract Class:
public abstract class Shape{

public abstract void draw();

}
Example of Interface:
public interface Drawable
{
void draw();
}

Simply, abstract class achieves partial abstraction (0 to 100%) whereas interface achieves fully abstraction (100%).

Example of abstract class and interface in Java


//Creating interface that has 4 methods
interface A
{
void a();//by default, public and abstract
void b();
void c();
void d();
}

//Creating abstract class that provides the implementation of one method of A interface
abstract class B implements A
{
public void c()
{
System.out.println("I am C");
}
}

//Creating subclass of abstract class, now we need to provide the implementation of rest of the methods
class M extends B{
public void a()
{
System.out.println("I am a");
}
public void b()
{
System.out.println("I am b");
}
public void d()
{
System.out.println("I am d");
}
}

//Creating a test class that calls the methods of A interface
class Test
{
public static void main(String args[])
{
A a=new M();
a.a();
a.b();
a.c();
a.d();
}
}
Test it Now
Output:

       I am a
       I am b
       I am c
       I am d

11. What is instance variable,local variable and class variable?

Local Variable:
Declaration: Declared inside a method, constructor, or block.
Lifetime: Its created when method or constructor is entered and Destroyed on exit.
Scope/Visibility:Visible only in the method, constructor, or block in which they are declared.
Outside accessibility:Impossible. Local variable names are known only within the method.

Instance variable:
Declaration: In a class, but outside a method. Typically private.
Lifetime: Created when instance of class is created with new. Destroyed when there are no more references to enclosing object (made available for garbage collection).
Scope/Visibility:Instance (field) variables can been seen by all methods in the class.
Outside accessibility:If allowed then can be accessed but generally Instance variables should be declared private to promote information hiding, so should not be accessed from outside a class.


Class variable:
Declaration: In a class, but outside a method. Must be declared static. Typically also final.
Lifetime: Created when the program starts. Destroyed when the program stops.
Scope/Visibility:Same as instance variable, but are often declared public to make constants available to users of the class.

12. What is singleton class?
  • Singleton class is the class having only one object.
  • The Singleton's purpose is to control object creation, limiting the number of objects to one only.
  • Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields. 

13. What is object reference? 

An object reference is used to describe the pointer to the memory location where the Object resides.
class Rectangle {
  int length;
  int breadth;
}

class RectangleDemo {
  public static void main(String args[]) {

  Rectangle r1 = new Rectangle();
  Rectangle r2 = r1;

  r1.length = 10;
  r2.length = 20;

  System.out.println("Value of R1 : " + r1.length);
  System.out.println("Value of R2: " + r2.length);

  }
}

14. What is String constant pool?

As the name suggests, String Pool in java is a pool of Strings stored in Java Heap Memory. We know that String is special class in java and we can create String object using new operator as well as providing values in double quotes.

Example:

public class StringPool {

    public static void main(String[] args) {
        String s1 = "Cat";
        String s2 = "Cat";
        String s3 = new String("Cat");
        
        System.out.println("s1 == s2 :"+(s1==s2));
        System.out.println("s1 == s3 :"+(s1==s3));
    }
}

Output:
s1 == s2 :true
s1 == s3 :false

15. What is static block?

Static block is mostly used for changing the default values of static variables.This block gets executed when the class is loaded in the memory.
A class can have multiple Static blocks, which will execute in the same sequence in which they have been written into the program.

Example:

public class StaticBlock{
   static int num;
   static String str;
   static{
      num = 100;
      str = "testing static block";
   }
   public static void main(String args[])
   {
      System.out.println("Value of num="+num);
      System.out.println("Value of str="+str);
   }
}


Output:
Value of num=100
Value of str=testing static block

16. What is final variable, final method and final class?

Final variable

If you make any variable as final, you cannot change the value of final variable(It will be constant).

Example:

class FinalVariable{  
 final int v=90;//final variable  
 void test(){  
  v=400;  
 }  
 public static void main(String args[]){  
 FinalVariable obj=new  FinalVariable();  
 obj.test();  
 }  
}
Output:Compile Time Error

Final method

If you make any method as final, you cannot override it.

Example:

class FinalMethod{
    final void test()
    {
        System.out.println("testing final method");
    }
}

class FinalMethod1 extends FinalMethod{

    void test()
    {
        System.out.println("testing final method again");
    }

    public static void main(String args[]){
        FinalMethod1 fm= new FinalMethod1();
        fm.test();
    }
}  

Output:Compile Time Error

Final class

If you make any class as final, you cannot extend it.

Example of final class

final class Car{}

class I10 extends Car{
    void show()
    {
        System.out.println("this is i10");
    }

    public static void main(String args[]){
        I10 i= new I10();
        i.show();
    }
}  
Output:Compile Time Error

17. What is Null Pointer exception error?
 Null Pointer exception is a Java Runtime Exception that signals an attempt to access a field or invoke a method of a null object. It is thrown when an application attempts to use an object reference that has the null value. These include:

  • Calling an instance method on the object referred by a null reference.
  • Accessing or modifying an instance field of the object referred by a null reference.
  • If the reference type is an array type, taking the length of a null reference.
  • If the reference type is an array type, accessing or modifying the slots of a null reference.
  • If the reference type is a subtype of Throwable, throwing a null reference.

18. What is thread?
A thread is an independent path of execution within a program. Many threads can run concurrently within a program.Every thread in Java is created and controlled by the java.lang.Thread class.

19. Can we call a class as a datatype?
Yes class is also a data type- a non primitive reference data type.

20. What is finalize method?

finalize() method is a protected and non-static method of java.lang.Object class.
This method will be available in all objects we create in java. This method is used to perform some final operations or clean up operations on an object before it is removed from the memory. 
We can override the finalize() method to keep those operations we want to perform before an object is destroyed.

Ex:

protected void finalize() throws Throwable
{
    //Keep some resource closing operations here
}

21. On which memory arrays are created in java?
It will be stored on the heap(because array is an object in java).

22. Can we call main() method from another class?

Yes,See below code:

package packA;
class A{
public static void main(String args[])
{
  System.out.println("Hello");
}
}

class B
{
    public static void main(String args[])
    {
    A.main(null);
 
    }
}

23. How much time we can save in automation?
It depends on the complexity and nature of the test case.

For ex: If we are executing BAT and manual effort use to take 6hrs then using automation we can accomplish the same in 1hr.
And if its regression suite consisting of 1000 test case which may take 1 month or more for a group of tester to execute may take only less than a day.

Also for some test case the automation is a tedious job rather than the manual effort is preferred.But if they are automated then they don't save much time in automation.

24. What is automation life cycle?

a. Automation feasibility analysis

  • Identify automable and not automable test cases/scenarios
  • Identify tools best suitable in our project.
  • Identify team size,effort and cost involved for tools which we will use.



b. Test Plan/Test Design
Create a Test plan by considering below points:

  • Fetch  all the manual test case from test management tool that which TC has to automate.
  • Which framework to use and what will be advantage and disadvantage  of the framework which we will use.
  • Create a test suite for Automation test case in Test Management tool.
  • Limitation, risk and dependency between application and tools.
  • Approval from client/ Stack holders.


c. Environment Setup/Test lab setup 
Setup machine or remote machine where our test case will execute.

  • How many machines do you want.
  • What should be the configuration in terms of hardware and software.


d. Test Script development/ Automation test case development
Start developing automation script and make sure all test script is running fine and should be stable enough.

  • Create test script based on your requirement
  • Create some common method or function that you can reuse throughout your script
  • Make your script easy, reusable,well structured and well documented so if third person check your script then he/she can understand your scripts easily.
  • Use better reporting so in case of failing you can trace your code
  • Finally review your script and your script should be ready before consumption.


e. Test script execution

Execute all your test script.

Some points to remember while execution
  • Your script should cover all the functional requirement as per testcase.
  • Your script should be stable so it should run in multiple environment and multiple browsers (depends on your requirement)
  • You can do batch execution also if possible so it will save time and effort.
  • In case of failure your script should take screen shots.
  • If test case is failing due to functionality, you have to raise a bug/defect.


f. Generate test result / Analyses of  result
Gather test result and will share with team/client/stack holders.

  • Analyze the output and calculate how much time it take to complete the testcase.
  • Should have good report generation like XSLT report, TestNG report, ReporterNG etc.
Can we overload main method?

Yes, we can have multiple methods with name “main” in a single class. However if we run the class, java runtime environment will look for main method with syntax as public static void main(String args[]).