Monday, 8 February 2016

What is difference between Hybrid, Native & Web apps(Android/iPhone).



Ans : a) Native app  : Apps which does not need web connectivity. 
  b) Web app   :  App which runs in mobile web browser.
  c) Hybrid app :  App having inbuilt web browser & native app components

Write code to reverse an array(int) of 1 to 10



Ans: a) Using commons.lang java library
public static int arr[]={1,4,2,3,7,6};
public static void revAnArray(int arr[]){
ArrayUtils.reverse(arr);
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}
}

b) Reverse loop

public static void reverseByloop(int[] arr){
int length=arr.length-1;
for(int i=length;i>=0;i--){
System.out.println(arr[i]);
}

What is difference absolute & relative xpath? Write one xpath manually?



Ans:  XPATH is a language that describes how to locate specific elements, attributes, etc. in a xml document. It allows you to locate specific content within an XML document. 
1) Absolute XPath : Relative XPath starts with / ( Note : ‘/’ is used for root path)
b) html/body/div[23]/div[4]/div[1]/div[2]/div/div
2) Relative XPath : Relative XPath starts with // (Note :‘//’ is used for current path)
Syntax//element_type[@attribute_name =’value’]
e.g. a) //*[@id='gbqfba']
b)//div[4]/div[1]/div[2]/div/div
  

Thursday, 4 February 2016

How to execute testng.xml file from main() method or from class/programm



Project Folder structure:




Testng.xml code:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="methods">

  <test name="Sanity">
  
      <classes>
         <class name="interview.Auto_Suggetins_Pass"/>
         
     </classes>
  </test>
     
</suite>

My class file :  to run testng.xml file from class or main method
package interview;

import java.util.List;

import org.testng.TestListenerAdapter;
import org.testng.TestNG;
import org.testng.collections.Lists;

public class Run_TestNGxml_from_main_method {

public static void main(String[] args) {

// //working fine way 1
/*List<String> suites = Lists.newArrayList();
          TestListenerAdapter tla = new TestListenerAdapter();
            TestNG testng = new TestNG();
            Class[] classes = new Class[]{interview.Auto_Suggetins_Pass.class};
             testng.setTestClasses(classes);
            testng.addListener(tla);
             testng.run();*/
             //working fine way 2 
             
  List<String> suites = Lists.newArrayList();         
       TestListenerAdapter tla = new TestListenerAdapter();
       TestNG testng = new TestNG();
       suites.add("testng.xml");
       testng.setTestSuites(suites);
       testng.addListener(tla);
       testng.run();
}
}



Difference between list, set and map

List: List allows duplicate elements
Set : Set doen't allow duplicates.
Map : Map stored the key and value pair, map doesn't allow duplicate keys while it allows duplicate values
List : List allows any number of null values
Set : Set allows single null value at most
Map : Map can have single null key at most and any number of null values
List : List maintains the insertion order
Set : set doesn't maintain any order.
Map : Map doesn't maintain any order.

Difference between selenium RC and selenium web driver

Selenium RC doesn't support Html Unit Driver
Slenium WebDriver supports HTml unit driver
Rc interacts with server but webdriver doesn't interact with server
Rc doen't support listeners but web driver supports the implementation of listeners
Rc doesn't support to test iphone/android application ,but webdriver supports to test iphone/android appications
Web driver cannot readily support new browsers since a driver code for new browser needs to be written to provide support. Selenium RC can easily support any browser.

Wednesday, 3 February 2016

How to work on multiple windows and how to work on if child windows changes for every run

package interview;

import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Multiple_Window_Handling {
WebDriver d;

@Test
public void handlingMultipleWindows()
{
    d=new FirefoxDriver();
    d.get("http://site24.way2sms.com/content/index.html");
    d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    d.manage().window().maximize();
    String parent_window=d.getWindowHandle();
    System.out.println("parent window ID is :" + parent_window);
   
    Set<String> allWindowHandles = d.getWindowHandles();
    for (String currentWindowHandle : allWindowHandles) {
    System.out.println("all window ids: " + currentWindowHandle);
    d.switchTo().window(currentWindowHandle);
    System.out.println("now am in child window :");
    System.out.println("child window title is : "+d.getTitle());
   
    if (d.getTitle().equals("Download HolidayIQ Mobile App") ){
        d.manage().window().maximize();
        d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        System.out.println("child window is getting maximized : ");
        d.findElement(By.xpath("//*[@id='layerslider']/div[1]/div/a[2]/img")).click();
        d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        System.out.println("it is clicking image on child window :");
        String leaseChildTitle=d.getTitle();
       
       /* d.switchTo().window(currentWindowHandle);
        System.out.println("now am in middle page :");*/       
        d.switchTo().window(parent_window);
        System.out.println("now am in parent page :");
   
    }
     else if(d.getTitle().equals("Cars in India » Car Images, Prices, Reviews, Indian Cars | AutoPortal.com®"))
     {           
         System.out.println("Selected 2 Window Title : " + d.getTitle());
         d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
         d.manage().window().maximize();
         System.out.println("child window is getting maximized : ");
         d.findElement(By.xpath("//*[@id='citydetect']/div[2]/div/div/div[3]/ul/li[3]")).click();
         d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
         d.findElement(By.xpath("//*[@id='citydetect']/div[2]/div/div/div[2]/span")).click();
         System.out.println("perfomred click operarion on child window :");
         d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
         String leaseChildTitle=d.getTitle();
         d.switchTo().window(parent_window);
         System.out.println("now am in middle page :");
        
     }

}
 d.quit();


    }
   
   
}