PAGE 40 : QUESTIONS AND ANSWERS SELENIUM

Framework and java Questions& Answers

   What is keyword driven framework?
   Ans:
        Key word driven frame work can be implemented in any automation tool not
       just for seleniu  In keyword driven framework we use keyword sheets (excel file
       where  each sheet is a   script)  which contains set of keywords as per manual 
       test case steps, During run time the framework will read the keyword converts
       them to statements and executes it. This framework is useful for  large
       and stable applications.
·       
      Which framework you have used and why?
Ans:
       We have used hybrid Framework where we have designed our framework using
       POM and Data driven by extracting data from excel file.We used data driven
       framework because we have to use extensive test data like teams to create 
       events, markets, selections.
    
      What are the challenges you faced while designing framework?
   Ans:
               Choosing Framework Type
           Selecting design pattern
          Handling Exception
          Generating Summary report
      Why  automation?
    Ans:
           Simulation of any tasks using system or any tool is known as Automation.
           Automation had below advantages:
                    Saves effort
                    Reusable
                   Saves time
                   Accuracy
  What are the components you have in your framework?
 Ans:
             Object Repository
           Reporting and logging
          Configuration File
          Utils like Excel Reader/Writer, XML Reader, Database reader/writer
          Folder structure

        What is the approach you followed to design the Framework?
Answer:
-          First we will write all the common operation of a webpage e.g. highlighting an element present in a webpage, Wait for loading of complete elements of webpage, check item present in dropdown list, get element attribute, element click, whether clickable, Open Browser instance, close browser instance, get element text, mouse over, whether clicked
etc in common java file within common folder. Within common folder, methods to fetch data from excel or xml or JDBC.
-          Decide on how to store the objects(or elements)
-          How the logs with logged for each step and how reporting will work
-          Design the config file which will have details about the app url, username, pwd, mailer id, which browser to open, types of environment etc . This we have as this can be changed from xml without changing anything in code.

        Automation test life cycle?
Answer:
The ATLM represents a structured approach, which depicts a process with which to approach and execute testing. This structured approach is necessary to help steer the test team away from common mistakes.
The Automated Test Life-cycle Methodology (ATLM) comprises six primary processes or components.
Decision to Automate Testing
The decision to automate testing represents the first phase of the ATLM. This phase covers the entire process that goes into the automated testing decision. During this phase, it's important for the test team to manage automated testing expectations and to outline the potential benefits of automated testing when implemented correctly. A test tool proposal needs to be outlined, which will be helpful in acquiring management support.
Test Tool Acquisition
This is the second phase of the ATLM. This phase guides the test engineer through the entire test tool evaluation and selection process, starting with confirmation of management support.
Automated Testing Introduction Process
This phase outlines the steps necessary to successfully introduce automated testing to a new project.
Test Planning, Design and Development

Execution and Management of Tests
At this stage, the test team has addressed design and test development. Test procedures are now ready to be executed in support of exercising the application under test. Also, test environment set up planning and implementation was addressed consistent with the test requirement and guidelines provided within the test plan.
With the test plan in hand and test environment now operational, it’s time to execute the tests defined for the test program.
Test Program Review and Assessment
Test program review and assessment activities need to be conducted throughout the testing lifecycle, to allow for continuous improvement activities. Throughout the testing lifecycle and following test execution activities, metrics need to be evaluated and final review and assessment activities need to be conducted to allow process improvement.
Phase
Activities
Outcome
Planning
Create high level test plan
Test plan, Refined Specification
Analysis
Create detailed test plan, Functional Validation Matrix, test cases
Revised Test Plan, Functional validation matrix, test cases
Design
test cases are revised; select which test cases to automate
revised test cases, test data sets, sets, risk assessment sheet
Construction
scripting of test cases to automate,
test procedures/Scripts, Drivers, test results, Bug Reports.
Testing cycles
complete testing cycles
Test results, Bug Reports
Final testing
execute remaining stress and performance tests, complete documentation
Test results and different metrics on test efforts
Post implementation
Evaluate testing processes
Plan for improvement of testing process

        What are the advantages of Page Object Model?
Answer:
POM:  This is one of the Java design pattern in which we create a Java class for every webpage. Each class contains WebElements as its data members and methods which perform operation on the webelements as its member function.

1-      Avoid to write the duplicate locators for same WebElement which is the big issue in other frameworks.
2-      Maintenance of the test script which becomes very easy. I
3-      Improves readability.
4-      Code reusability.
5-      There is a clean separation between test code and page specific code such as locators (or their use if you’re using a UI map) and layout.
6-      There is a single repository for the services or operations offered by the page rather than having these services scattered throughout the tests.
For example if the login page elements get updated, you can just go to your loginPage Page Object class and update the methods identifying the elements.

Selenium Question:
        Difference between web driver listener and TestNg listener?
Answer:
TestNG Listener are triggered at test level such as before starting test after the test or when test fails etc; whereas WebDriver Listener are triggered at component level such as before click, after click etc
        Return type of data provider?
Answer:
Return type of data provider is double diamentinal Object -- Object [] [].
A DataProvider provide data to the function which depends on it. And whenever we define a DataProvider it should always return a double object array “Object[][]”. The function which calls dataprovider will be executed based on no. of array returned from the DataProvider.
        What is Absolute and Relative Xpath?
Answer:
Absolute Xpath: Writing the complete path of a specified element using single forward slah(‘/’) is known as Absolute Xpath. It is time consuming and lengthy. Here, / slash represents immediate child.
Relative Xpath: Writing the path of a specified element using double forward slah(‘//’) is known as Relative Xpath. Here, // slash represents any child also called as Descendants.
        How can we avoid Javascript errors which occur while testing web applications?
Answer:
<script type="text/javascript">
window.jsErrors = [];
window.onerror = function(errorMessage) {}
</script>
        Difference between //a and //table/a?
Answer:
//a: This will find all the links which are present in webpage.
//table/a: This will find all the links which are present inside the table.
        How do you make sure that text entered in the password field is Encrypted?
Answer: 
String elementType=driver.findElement(By.name("pwd")).getAttribute("type");
if(elementType.equals("password"))
{
S.O.P("the text is masked/encrypted");
}
else
{
S.O.P("the text is not masked/encrypted");
}

        How we can clear the cookie in selenium?
Answer:
driver.manage().deleteAllCookies();
        How we will check the cookies in selenium?
Answer:
importjava.util.Set;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class run11
{
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("https://www.google.co.in/?gfe_rd=cr...");
Cookie cookie=new Cookie("key","value");
driver.manage().addCookie(cookie);
Set<Cookie>allcookies = driver.manage().getCookies();
for (Cookie var:allcookies)
{
System.out.println(var.getName());
System.out.println(var.getValue());
}


        How to run the test cases through command prompt?
Answer:
Java –cp bin;jars/* <classNameWhichHasSeleniumCode>
        How do you execute TestNG suite from cmd?
Answer:
Java –cp bin;jars/* org.testng.TestNG testing.xml

Instead of typing the above command everytime, we use the command in batch file ex:-

        What is the use of dependson in TestNG?
Answer:
If in a TestNG class, we have multiple @Test(test method) e.g.
public void testA(){Reprter.log(“Delete Customer”)} and
public void testB(){Reprter.log(“Create Customer”)},
here, the TestNG will execute the methods in alphabetical order. In this case if we want to execute it then TestNG will execute testA() method first which is incorrect. Hence to override the alphabetical execution, we use dependsOnMethods parameter.
Syntax:
Public class Demo
{
@Test(dependsOnMethods={“c1.verifyConfig”})
      Public void testA()
      {
Reporter.log(“Delete Customer”);
      }
@Test
      Public void testB()
      {
Reporter.log(“Delete Customer”);
      }

}
        Difference between TestNG and JUnit?
Answer:
-          We have additional levels of setup/teardown level are available like: @Before/AfterSuite, @Before/AfterTest and @Before/AfterGroup
-          In TestNG, we can specify that the method is dependent on another method whereas in Junit is not possible. In Juniteact test is independent of another test.
-          Grouping of test caseses is available in TestNG whereas the same is not available in Junit.
-          TestNG has its own methods to compare result i.e. Assert.assertEquals(aresult, eresult);
-          Using TestNG we can do parallel execution whereas in Junit, we can not do.
        What is synchronization issue in selenium?
Answer:
Most of the time selenium script execution is faster than application because of which selenium will not be able to find elements and it will throw NoSuchElementException.
The mismatch in the execution speed of selenium and application is known as Synchronization issue.
        How synchronization will be resolved in automation?
Answer:
Synchronization issue can be resolved in 2 ways:
-          By using sleep() method of Thread class
-          By using ImplicitlyWait() method – It has 2 arguments, one is duration and other is unit.

If we will use sleep() method, then selenium has to sop for that duration of time even though the page is loaded completely, e.g. Thread.sleep(20000), this will stop selenium for 20 seconds even if page is loaded in 5 seconds.
Whereas, ImplicitlyWait() will be applicable for elements which we are finding using findElements and findElement, e.g. ImplicitlyWait(10, TimeUnit.SECONDS), if selenium is able to find element at 5 second, then it will perform the action and move to next step. However, while finding element selenium will wait maximum 10 seconds to find element, if element is not visible even after 10 seconds, then JVM will throw NoSuchElementPresentException.
        Write a java code to synchronize selenium without any built in synchronize method?
Answer:
publicclass Synchronize {

              publicstaticvoid main(String[] args)
              {
                     WebDriver driver = newFirefoxDriver();
                     driver.manage().window().maximize();
                     driver.get("http://demo.actitime.com/");
             
                     while(true)
                     {
                     try{
                           driver.findElement(By.id("username")).sendKeys("user");
                           driver.findElement(By.xpath("//input[@type='password']")).sendKeys("manager");
                           driver.findElement(By.id("loginButton")).click();
                     }catch(NoSuchElementException e)
                        {}
              }
              }
       }
      
        Difference between selenium RC and webdriver?
Answer:
-          Selenium RC is following same origin policy and handling dynamic element is difficult so switch to WebDriver.
-          Webdriver can support headless HtmlUnit browser where RC can’t. It is termed as ‘headless’ because it is invisible browser – it is GUI less
-          Webdriver is faster as compared to RC as webdriver directly communicates through browser where RC does not
-          To execute the code, we need to start RC server whereas in web driver need not to do so.
-          Webdriver supports mobile automation whereas RC does not.
        How many wait statements you know?
Answer:
Wait(): Wait() method will make the thread to wait till a condition is satisfied or till it is notified by another thread.
ImplicityWait(): This is used by findElement() and findElements() method, this will wait till the element is found.
ExplicitlyWait(): This is custom wait method which is designed by developer to make selenium to wait till condition is satisfied.
        Have u used constructor in WebDriver? Give Example?
Answer:
Yes, we have constructor is WebDriver. For e.g.
-          Actions class constructor will take an argument as driver i.e. Actions action = new Actions(driver);
-           
        Is it possible to write the Xpath using IE browser?
Answer:

        What exactly your file structure looks like when you are automating something by using of eclipse?
Answer:
Project ->src
                  JRE System Library
                    TestNG
                    Refrenced Libraries

                    excelFiles

    exeFiles
                    Jars
        How did you verify that given number on webpage in sorted order?
        How can i do priority based testing using web Driver?
        Write a login code using page factory?
Answer:
PageFactory class:
The PageFactory Class is an extension to the PageObject design pattern. It is used to initialize the elements of the PageObject or instantiate the PageObject itself. Annotations for elements can also be created (and recommended) as the describing properties may not always be descriptive enough to tell one object from the other.
The InitElements method of PageFactory initializes the elements of the PageObject.

PageFactory.InitElements facilitates searching for elements marked with the FindsBy attribute by using the NAME property  to find the target element.

In summary, PageFactory class can be used to initialize elements of a Page class without having to use FindElement or FindElements. Annotations can be used to supply descriptive names of target objects in the AUT to improve code readability. There are however a few differences between C# and Java implementation – Java provides greater flexibility with PageFactory
public class LoginPage
{
       public WebDriver driver;
      
       @FindBy(name="username")
       private WebElement unTextBox;
      
       @FindBy(name="pwd")
       private WebElement pwdTextBox;
      
       @FindBy(id="loginButton")
       private WebElement loginButton;
      
       @FindBy(className="errormsg")
       private WebElement errMsgElement;
      
       public LoginPage(WebDriver driver)
       {
              this.driver=driver;
              PageFactory.initElements(driver,this);
       }
      
       public void login(String un,String pwd)
       {
              unTextBox.sendKeys(un);
              pwdTextBox.sendKeys(pwd);
              loginButton.click();
}
        Write a code for screen shot?
Answer:
 EventFiringWebDriver efwd = new EventFiringWebDriver(driver);
                File src = efwd.getScreenshotAs(OutputType.FILE);
                System.out.println(src.getAbsolutePath());
                FileUtils.copyFile(src, new File("C:\\Screenshots\\one.png"));

        Why we are using some tool for reporting?
        What is TestNg?Tell me the annotations of TestNG?
Answer:
TestNG is Test Next Generation is a unit testing basically used by developers to run Java classes and get the report and based on report, if any fail test cases are there, then they can run.
Similarly, in selenium we also create TestNG class for each testcase and we need to run the tests to get the report.
@Test
@BeforeMethod
@AfterMethod
@BeforeClass
@AfterClass
@dependsOnMethods
@dataProvider
@beforeSuite
@afterSuite
@Parameter
        Can you write a sample for parallel execution in TestNG.xml file?
Answer:

        How are you maintaining the objects in your project?
AnswerXML
        Actually X-path writing a confusion task for me, is there any way to find web Element in UI?
Answer:
We can find webElelemts through javascript or jquery.
        How will you capture the dynamic object using selenium webDriver?
Answer:
Using Xpath, we can capture dynamic object.
We can also do with CSS as below: css=span[id*=”header”]/ css=span[id^=”header”]
        Tell me the syntax for Implicitly wait() and Explicitly wait()
Answer:
Wait is used to make the thread to wait till a condition is satisfied or till it is notified by another thread.
Implicitlywait() is used by findElement() method till the element is located within timeout.
driver.manage().timeout.Implicitylywait(2,TimeUnit.SECONDS);
Explicit wait any code written by the programmer to make the selenium to wait till the condition is satisfied.
Wait<WebDriver> wait = new WebDriverWait(driver, 30);
WebElement element= wait.until(visibilityOfElementLocated(By.id("some_id")));


        Assert vs Verify?
        What are the versions of Selenium?
Answer:
-          Selenium Core – 2004
-          Selenium RC – 2006
-          Selenium Web Driver – 2008 (Selenium 2.0)
        How to handle frames?
Answer:
In order to handle frames, we need to use driver.switchTo().frame(int);
driver.switchTo().frame(String);
driver.switchTo().frame(WebElements);

Using above command we can switch to child frame and perform operation. To come back to main page we use below code:
driver.switchTo().defaultContent();
        Dropdown list without select tag?
Answer:
If the listbox is developed without using select class, then it is called as custom built listbox. In order to handle it, we have to use findElement method.
        Why css selector is faster than xpath?
        Webdriver is class or an interface?
Answer:
WebDriver is an Interfae
        What are the things u stored in PageFactory ?Why ?
Answer:
WebElement variable names were enough to identify the controls.
it is not required to use the object property as the variable name
        How do you handle untrusted SSL certificate in Webdriver?
Answer:
In order to handle untrusted SSL certificate in webdriver we use Profile.setAssumeUntrustedCertificateIssuer(false);

Code:
        firefoxProfile profile=new firefoxProfile();
        profile.setAssumeUntrustedCertificateIssuer(false);
        firefoxDriver driver=new firefoxDriver(profile);

        What is the use of DesiredCapabilities in Selenium WebDriver?
Answer:
Describes a series of key/value pairs that encapsulate aspects of a browser.
Basically, the DesiredCapabilities help to set properties for the WebDriver.
-          Setting up profile for firefox
-          To set preferences for firefox browser
        How do you find out active elements?

        Is it possible to interact with MS Office Package using Java?
        How do U chk the file size (Ex if file size s 2mb)?
        How to handle download and page on load pop-ups ?
Answer:
File download pop up: Using selenium, we can’t perform operation on download pop up. In order to handle it, we need to change the setting in firefox browser programmatically, so that file download pop up is not displayed instead of that it downloaded in the back ground.
Open firefox and type about:config and accept, then type saveToDisk. Get the value and store in a key and value as application/zip.
This can be done as below:
FirefoxProfile profile = new FirefoxProfile();
              String key = "browser.helperApps.neverAsk.saveToDisk";
              String value = "application/zip";
             
              profile.setPreference(key, value);
              DesiredCapabilities dc = DesiredCapabilities.firefox();
              dc.setCapability(FirefoxDriver.PROFILE, profile);
             
       WebDriver driver = new FirefoxDriver(dc);

PageOnLoad: While accessing url itself we need to provide username and password in below format:
Driver.get(“http://admin:admin@url”);
        Xpath with wild characters(@*) and asked me explain that
        If assertion fails how do you handle that?
        How to handle dynamic Xpath?
Answer:
Using startswith and endswith.
        Write the xpath to click the check box present in fourth column of 3rd row in a table?
        How to find broken links on page using selenium webdriver?
Answer:
importjava.net.HttpURLConnection;
import java.net.URL;
importjava.util.List;
importjava.util.concurrent.TimeUnit;

importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.firefox.FirefoxDriver;
publicclassbrokenLinks
{
       publicstaticvoid main(String[] args)
       {
              WebDriver driver = newFirefoxDriver();
              driver.manage().window().maximize();
              driver.manage().timeouts().implicitlyWait(3000, TimeUnit.MILLISECONDS);
              driver.get("http://flipkart.com/");
              //Getting all the links from Fipkart.com
              List<WebElement>allLink = driver.findElements(By.tagName("a"));
              //Getting the count of links present in Flipkart.com
              System.out.println("Number of links are: "+allLink.size());
              booleanisValidLink = false;
              for(inti=0;i<allLink.size();i++)
              {
                     //validating the response from website
                     isValidLink = getResponseCode(allLink.get(i).getAttribute("href"));
                     if(isValidLink)
                     {
                           System.out.println("ValidLinks :"+allLink.get(i).getAttribute("href"));
                     }
                     else
                     {
                           System.out.println("Invalid Links :"+allLink.get(i).getAttribute("href"));
                     }
              }
       }
publicstaticbooleangetResponseCode(String Url)
       {
              booleanisValidLink = false;
              try
              {
                     //passing the url URL class
                     URL url = newURL(Url);
                     //passing the url to open the connection using Http
                     HttpURLConnectionhuc = (HttpURLConnection) url.openConnection();
                     //Hitting the web-site URL
                     huc.setRequestMethod("GET");
                     //opening the website using http
                     huc.connect();
                     //getting the response code and printing
                     System.out.println(huc.getResponseMessage());
                     //checking the response message as Not Found or Found
                     if(huc.getResponseMessage()=="Not Found")
                     {
                           isValidLink = true;
                     }
              }catch(Exception e)
              {}
              returnisValidLink;
       }
}
        There are 100 testcases i want execute only 3 test cases without using testng groups?
        What is reflection API?  With example?
        How u validate email id in selenium?(in qtp we use RegExp for validating string)?
        Stress vs load testing vs performance testing?can we use selenium for the performance testing?
        How to handle the drop down list?
Answer:
Using Actions class
Actions action = new Actions(driver);
        How to setup profile in selenium?
Answer:
First we need to create our own profile in firefox browser by using below command from run
Firefox.exe –p and use below code create your own profile.
ProfilesIni allProfile = new ProfilesIni();
              FirefoxProfile profile = allProfile.getProfile("profile name which we have created");
              DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, profile);
        How to set proxy setting using web driver?
Answer:
Yes, we can set proxy. First we need get the proxy from the proxyserver.com
String PROXY = "localhost:8080";

              Proxy proxy = new Proxy();
              proxy.setHttpProxy(PROXY).setFtpProxy(PROXY).setSslProxy(PROXY);
              DesiredCapabilities cap = new DesiredCapabilities();
              cap.setCapability(CapabilityType.PROXY, proxy);//CapabilityType is FirefoxDriver, InternetExplorerDriver, Chrom

       WebDriver driver = new FirefoxDriver(cap);

        There are 2 textbox, id and password. Something is already written in text field like "Emailid",how can you copy from emailid field and paste in password field.
Answer:
driver.findElement(By.id(“username”)).sendKeys(Keys.chord(Keys.CONTROL,”a”), Keys.chord(Keys.CONTROL,”c”));
driver.findElement(By.name(“pwd”)).sendKeys(Keys.chord(Keys.CONTROL,”v”), Keys.RETURN);
        Can we use other function behalf of get() to go on specific url.?
Answer:
driver.navigate.to(“http://www.google.com”);
        Can we open browser without selenium?
Answer:
Runtime.getRuntime().exec(path of exe file);
        When can we use contains function?
Answer:
-          When value is very lengthy
-          When value is keep changing
-          When value has a space before and after the text
        How to get fullscreen using selenium webdriver?
Answer:
importjava.awt.AWTException;
importjava.awt.Robot;
importjava.awt.event.KeyEvent;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;

public class fullscreen {
public static void main(String[] args) throws AWTException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
Robot r = new Robot();
r.keyPress(KeyEvent.VK_F11);
r.keyRelease(KeyEvent.VK_F11);
r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);
}
}
        How u will group and how u will add classes from different packages?
Answer:
@Test(groups = { "smoke"})
<packages>
<package name="com.package1" />
<package name="com.package2" />
</packages>

Java Questions:
        Difference between Hash Map, Hash Table and Array List?
Answer:
1)      First and most significant different between Hashtable and HashMap is that, HashMap is not thread-safe while Hashtable is a thread-safe collection.
2)      Second important difference between Hashtable and HashMap is performance, since HashMap is not synchronized it perform better than Hashtable.
3)      Third difference on Hashtable vs HashMap is that Hashtable is obsolete class and you should be using ConcurrentHashMap in place of Hashtable in Java.
4)      HashMap is a collection of key and value pairs similar to Hashtable. HashTable does not allow null key or value but HashMap allows null values and one null key.
5)      ArrayList is a collection of objects similar to Vector. It is growable array. It allows duplicate values and also null. It always stored in an order using an index.
        What is polymorphism?
Answer:
When an object shows different behavior at different stage of its life cycle, then it is known as Polymorphism. There are two types of polymorphism:
Compiletime Polymorphism: When an object gets to know its behavior at compile time it is known as compile time polymorphism. Method Overloading is the best example.
Runtime Polymorphism: When an object gets to know its behavior at runtime based on the reference created, then it is known as Runtime polymorphism. Method Overriding is an example.
        Write a java code to read the data through excel file?
        What is constructor? What is super ()?
Answer:
Constructor is special method in java which is used to initialize the object of a class. Constructor method name should be same as class name and should not have any return type not even void.

Super() is statement used in constructor to invoke the constructor of its immediate super class. Super() should be written as a first statement in constructor, it will be present implicitly or we have to write it explicitly.
        What is the Difference between final, finally, finalize?
Answer:
Final: Final is keyword used for variable, method or class. If we use this keyword for any of the above mentioned type, then that type will become immutable and can’t be changed.
Finally: Finally is a block used in exception, this block will be executed everytime either the code throws an exception or not.
Finalize: It is a method present in a class which is called before any of its object is reclaimed by the garbage collector. Finalize() method is used for performing code clean-up before the object is reclaimed by the garbage collector.
        What is the difference between throw, throws and throwable?
Answer:
Throwable:  Throwable is the super class of error and exceptions in Java language. Only the object that are instances of this class(or its sub-class) are thrown by JVM or can be thrown by Java throw statement.
Throw: This keyword is used to throw as object that is an instance of throwable class.
Throws: This keyword is used in method declaration, this specify what kind of exception we may expect from this method.
        What is binding(early and later binding)?
        Whether Java is 100% object oriented?
Answer:
No, because we are using primitive data type
        Can we make Java programs 100% object oriented?
Answer:
Yes, by using wrapper class.
Java provides wrapper class to convert primitive data type to object type and all wrapper class is final in nature.
        What is boxing and unboxing?
Answer:
Boxing: Converting primitive data type to an object type is known as boxing
Integer intObj = 23; //implicit boxing
Integer intObj = new Integer(23); //explicit boxing
Unboxing: Converting already boxed type to primitive type is known as unboxing
int k = intObj.intValue(); //explicit
int k = intObj; //implicit unboxing

Object obj = 25; //auto boxing and auto upcasting. First 25 converted to Integer Object and upcasted to Object
        What is singleton class and how to achieve?
Answer:
Developing a java class which allows creating only one instance at any given point of time is known as singleton class.
-          Class must have private constructor
-          Class must provide a static method which returns an instance of its own class
-          It should have a logic in such a way, so that it returns an object which is already created
        What is Encapsulation?
Answer:
The process of hiding the state of an object with the help of modifiers like private, public, protected etc.
We expose the state through public methods only if require. Encapsulation is a strategy used as part of abstraction. Encapsulation refers to the state of objects - objects encapsulate their state and hide it from the outside; whereas Abstraction refers to the implementation of object.
        What is Abstraction and how it is different from Encapsulation?
Answer:
Abstraction is another good feature of OOPS. The process of hiding the implementation of an object and only providing the functionality to use.
Example: When you change the gear of your vehicle are you really concern about the inner details of your vehicle engine? No but what matter to you is that Gear must get changed that’s it!! This is abstraction; show only the details which matter to the user.
Abstraction: The process of hiding the implementation of an object and only providing the functionality to use.
Encapsulation: The process of hiding the state of an object with the help of modifiers like private, public, protected etc.
We expose the state through public methods only if require. Encapsulation is a strategy used as part of abstraction. Encapsulation refers to the state of objects - objects encapsulate their state and hide it from the outside; whereas Abstraction refers to the implementation of object.
        What is the difference between interface and abstract class?
Answer:
Abstract class: An abstract class is a class marked as abstract and cannot be instantiated. It can have abstract and/or concrete methods in any combination. An abstract method is a method marked abstract keyword with only signature and no body, whereas a concrete method is a method with body. Even if an abstract class contains only concrete methods and no abstract methods, it cannot be instantiated.
Interface:An interface is a contract for a class and contain only abstract methods. The abstract keyword is implicit here for methods, but can also be declared explicitly. Also, variables of an interface are public, static and final; though they can be explicitly defined with these modifiers. 
        How to achieve Abstraction?
Answer:
-          Generalize the behavior of a class in a interface
-          Implement the behavior in different classes according to its specification
-          Return an object of a class by casting to interface type
-          The major advantage of abstraction is, the usage of an object is de-coupled from its implementation. Any change in implementation will have least effect on usage
        Array v Arraylist?
        What is the difference between RSM(Recovery scenario Manager) and error Resume?
Answer:
RSM is used to handle runtime error and also it is able to handle window pop-up, Object state, Application crash and test run error.
Whereas, error Resume Next will handle the particular code snippet where exactly the error occurs, it skips the line and it will take to the other code. This is useful when we have thousand lines of code and you do not want to stop execution because of one minor error.
        Explain oops concepts?
Answer:
Object-Oriented Programming (OOP) uses "objects" to model real world objects. An Object is an entity has state and some behavior. In Java, the state is the set of values of an object's variables

at any particular time and the behavior is implemented as methods. Class can be considered as the blueprint or a template for an object and describes the properties and behavior of that object, but without any actual existence.
ENCAPSULATION:
Encapsulation in java is the process of wrapping up of data (properties) and behavior (methods) of an object into a single unit; and the unit here is a Class (or interface).
Encapsulation enables data hiding, hiding irrelevant information from the users of a class and exposing only the relevant details required by the user.
INHERITANCE:
Class acquiring the property of another class is known as Inheritance.
POLYMORPHISM:
An object showing different behavior at different stage of its lifecycle is known as Polymorphism.

        What is nullpointerexception?
NullPointer exception is an unchecked exception occurs during runtime. This exception occurs when an application attempts to use null in a case where an object is required. These include:
·         Calling the instance method of a null object.
·         Accessing or modifying the field of a null object.
·         Taking the length of null as if it were an array.
·         Accessing or modifying the slots of null as if it were an array.
·         Throwing null as if it were a Throwable value.
        Write a java code for pyramid?
        What is the difference between JDBC & Hibernate?
        What is the difference between Vector and ArrayList?
Answer:
Thread Safety: Vector is a thread-safe while arraylist is not a thread safe.
Performance: Vector is slower because it is thread safe whereas arraylist is faster than vector as it is not thread safe.
Capacity: When vector crossed its threshold of storing objects, it increases its size itself by value specified in capacityIncrement whereas arraylist increased its size by calling ensureCapacity() method.
        What is the difference between Hashset, LinkedSet and TreeSet of Set collection?
Answer:
Main Feature: (All 3 are thread safe)
HashSet: It is used for storing collection of objects. It is implemented using HashMap in Java. It is the fastest in Set Interface in terms of performance. HashSet does not maintain any order of elements. It allows null to store.
LinkedHashSet: It is mainly used for insertion order. It comes after HashSet or much similar to it. LinkedSet maintains insertion order of elements. It allows to store null.
TreeSet: It is mainly used for sorting and is implemented using TreeMap in Java. TreeSet is bit slower it needs to perform sorting on each insertion. TreeSet maintains sorting order of elements. It does not allow to store null.
        What is the difference between List, Queue and Set of collections?
Answer:
List:
-          List is a collection which stores objects in sorted order i.e. indexed(first element will get index as 0)
-          List allows to stores duplicate values and Null values
Queue:
-          Queue is a collection which stores objects of same type in sorted ordered (ascending) but not indexed as List does. However, while displaying objects, the objects will be displayed in random order. We can only check the head element using peak() method.
-          Queue allows to store duplicate values but not Null values
Set:
-          Set is a collection which stores objects in random order; however object will have the address of its next element.
-          Set does not allow storing duplicate values but allows storingonly one Null value.
Map:
-          Map can have null values and at most one null key.
-          Map can have duplicate values but key should be unique.


Project Questions:
        Tell me about your project and responsibilities?
        Which module u worked on your project?
        How many bug you have found on your project?
        Can you please explain flow of your project?
        Please explain your project architecture with framework with diagram?
        What are the technical challenges you have faced?
        If dev not accepted the bug, what will you do?
        Duration of sprint?
        How do u adapt in your company if requirements keep on changing?
        How will you - Converted Manual Test Case in to Automation Test Scripts.
Answer:
1.       Ensure that it is Regression test case
2.       Ensure that it has no manual intervention like printing scaning.
3.       Identify repeating steps and develop functions/methods.
4.       Write script as per manual test case steps.
5.       Do self review.
6.       Send it for peer review.
7.       Fix review comments and verify.
8.       Send it for approve.
9.       Store it in Test Script repository after the approval
        How will you Review of test scripts?
Answer:
1. Take the Script present in Shared location to local machine
2. Run it and ensure that it executes without any error/ exception
3. Verify that all the steps of manual test case are automated
4. Ensure that proper coding conventions are followed
5. Ensure that the code is written with proper indentation (tab space & alignment)
6. Ensure that in line comments are provided
7. Ensure that functions/methods are used instead of repeating steps
8. Prepare list of review comments in a Standard Review Template
                        9. Send the review comments to Author 


/**
* Wait for locator to be invisible or not present on the DOM
* @param locator used to find the element
* @return true if element is invisible, false otherwise
* @throws Exception
*/
public boolean waitForInvisibilityofElement(String locator) throws Exception {

long timePassedinSS;
long start = clock.now();
try{
boolean isElementNotPresent = webdriverWait.until(ExpectedConditions
.invisibilityOfElementLocated(By.xpath(locator)));
timePassedinSS = (clock.now() - start) / 1000;
locator = locator.contains("@class='ui-block'")?"Spinner":locator;
if(timePassedinSS > 0){
//Reporter.log(String.valueOf(timePassedinSS) + "(s) passed waiting for invisibility of element => " + locator , true); //nsaraf: Commented the line as it was clutering the log
}
return isElementNotPresent;
}catch(Exception e){
throw new TestFrameworkException(String.valueOf((clock.now() - start) / 1000) + "(s) passed but still visible element => " + locator, e);
}
}

private final Clock clock = new org.openqa.selenium.support.ui.SystemClock(); private final int implicitWait = 5000; private final int pageloadtimeout = 30; private final int WEBDRIVER_CLIENT_EXPLICIT_DELAY = 90; public WebDriverWait webdriverWait; String POUND_SIGN_CODE_UTF8 = "\u00A3";

No comments:

About Me

My photo
Pune, Maharastra, India
You can reach me out at : jimmiamrit@gmail.com