Wednesday, 15 October 2014

Selenium XPath locators examples:

1.

div id="submenu_electronics" class="submenu" data-submenu-key="electronics">
    <div class="line shopby allow-overflow">
    <div class="line main-section" data-tracking-id="nmenu_sub_electronics">
        <div id="menu-electronics-tab-0-content" class="tab-content " data-tracking-id="Categories">
            <ul class="unit size1of5 menu-column even ">
                <li class="heading">


Xpath in firebug console:
$x("//div[@id='submenu_electronics' and @class='submenu']/div[2]/div/ul[1]")
or
$x("//div[@id='submenu_electronics' and @class='submenu']//../ul[1]")

@col_linesheet_ref = Element.new(:xpath,
                                 "//table[contains(@id,'channelSubTable')]/thead/tr/th[1]")
@col_linesheet_name = Element.new(:xpath,
                                  "//table[contains(@id,'channelSubTable')]/thead/tr/th[2]")
@col_linesheet_season = Element.new(:xpath,
                                  "//table[contains(@id,'channelSubTable')]/thead/tr/th[3]")
@col_mapping_errs = Element.new(:xpath,
                                    "//table[contains(@id,'channelSubTable')]/thead/tr/th[4]")
@col_new_lines = Element.new(:xpath,
                                "//table[contains(@id,'channelSubTable')]/thead/tr/th[5]")

@link_channel = Link.new(:xpath,"//a[@data-test='menuHeaderChannels']")
@eleh1 = Element.new(:xpath, "//div[@id='page-heading']")
@combo_retailer = ComboBox.new(:xpath, "//select[@id='retailerId']")

@tbl_channels = Element.new(:xpath, "//table[@id='channels-list']")

@tbl_subtable=Element.new(:xpath, "//table//table")
@tbl_subtbl_lines_ref = Element.new(:xpath, "//table//table/tbody/tr/td[1]")
@table_channels = Element.new(:xpath, "//table/tbody/tr/td[2]")
 
@ele_overview = Element.new(:xpath, "//h4[contains(text(), 'Overview')]") 

Tuesday, 7 October 2014

System Details and convert milliseconds to seconds

package pack;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class OSDetails {
public static void main(String[] args) throws InterruptedException {
DateFormat dateFormat = new SimpleDateFormat();
Date date = new Date();
System.out.println(dateFormat.format(date).substring(0,7));  
System.out.println("OS Name: "+ System.getProperty("os.name"));
System.out.println("OS Version: "+ System.getProperty("os.version"));
System.out.println("OS Arch: "+ System.getProperty("os.arch"));
System.out.println("Host: "+ System.getProperty("hostname"));
System.out.println("user.home: "+ System.getProperty("user.home"));
System.out.println("user.name: "+ System.getProperty("user.name"));
System.out.println("path.separator: "+ System.getProperty("path.separator"));
System.out.println("user.dir: "+ System.getProperty("user.dir"));
long i1= System.currentTimeMillis();
Thread.sleep(10000);
long i2= System.currentTimeMillis();
System.out.println("Elapsed time in milli seconds: "+ (i2-i1));
System.out.println("Elapsed time in seconds: "+ TimeUnit.MILLISECONDS.toSeconds(i2-i1));
}
}


/* Output:
7/10/14
OS Name: Windows 7
OS Version: 6.1
OS Arch: amd64
Host: null
user.home: C:\Users\IN00739
user.name: IN00739
path.separator: ;
user.dir: C:\Users\IN00739\workspace\RnD
Elapsed time in milli seconds: 10001
Elapsed time in seconds: 10

*/

Sunday, 28 September 2014

Java- Extends Eg



package basics;

class SuperClass
{
    int x, y, z;   
    SuperClass()
    {
        System.out.println("Im in main super class--Default Empty!!");
    }
    SuperClass(int ia, int ib)
    {
        x= ia;
        y= ib;       
    }
   
    public int area()
    {
        return x*y;
    }
}

class Super2 extends SuperClass
{
    Super2()
    {       
        super();
        System.out.println("Im in sub class- Super2");
    }
    Super2(int ip, int iq, int ir)
    {
        super(ip, iq);
        z=ir;
    }
    public double volume()
    {
        return x*y*z;
    }
}
public class ExtendsTest {
    public static void main(String[] args) {
        System.out.println("From Main method-Empty class testing..");
        Super2 s2= new Super2();
       
        System.out.println("Constructor having parameters test...");
        Super2 s3= new Super2(10, 20,30);
        System.out.println("Area is = "+ s3.area());
        System.out.println("Volume is = "+ s3.volume());
       
        int[] arr={1,2,3,4,5};
        System.out.println("Array Length is = "+ arr.length);
        System.out.println("Looping through array elements");
        for (int i=0; i<arr.length; i++)
        {
            System.out.println("array element is = "+ arr[i] + " at index= "+ i);
        }
        String s= "\n";
        System.out.println("Length of the string is : "+ s.trim().length());
               
    }
}

Sunday, 10 August 2014

Java DateTime example_SimpleDateFormat


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class first {
public static void main(String ap[])
    {
       
        Calendar cal=Calendar.getInstance();
        System.out.println("Calender getTime: "+cal.getTime());
        System.out.println("Calender getTimeZone: "+cal.getTimeZone());
        System.out.println("Hour of the day: "+ (String.valueOf(cal.get(Calendar.HOUR_OF_DAY))));  //output= 17 // at 5pm
       
        Date today = new Date();          
        SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM"); 
        String monthName = dateFormat.format(today);
        System.out.println("Month full Name: "+ monthName);   //July
       
        dateFormat= new SimpleDateFormat("MMM");
        System.out.println("Month Name in short: "+ dateFormat.format(today)); //Jul
       
        dateFormat= new SimpleDateFormat("MM");
        System.out.println("Month in Numeric: "+ dateFormat.format(today));  //07
       
        //Now Day and Day name
        dateFormat= new SimpleDateFormat("EE");
        System.out.println("Day name in short: "+ dateFormat.format(today));  //Sat
       
        dateFormat= new SimpleDateFormat("EEEE");
        System.out.println("Day name in full: "+ dateFormat.format(today));   //Saturday
       
        dateFormat= new SimpleDateFormat("d");
        System.out.println("Day number in a month: "+ dateFormat.format(today));   //12  --12/July/14 is Saturday
        //***********Now DateTime
       
        dateFormat= new SimpleDateFormat();
        System.out.println("Date and Time: "+ dateFormat.format(today));
       
        dateFormat= new SimpleDateFormat("MM/dd/YYYY HH:mm:ss");
        System.out.println("MM/dd/YYYY HH:MM:ss-            "+ dateFormat.format(today));
       
        dateFormat= new SimpleDateFormat("dd/MM/YYYY HH:mm:ss:SSSS");  //including milliseconds
        System.out.println("dd/MM/YYYY HH:MM:ss:SSSS-           "+ dateFormat.format(today));
       
        dateFormat= new SimpleDateFormat("MMM/dd/YYYY HH:mm:sss");
        System.out.println("MMM/dd/YYYY HH:mm:sss-           "+ dateFormat.format(today));
       
        dateFormat= new SimpleDateFormat("MMM/dd/YYYY HH:mm:ss:SSSS");
        System.out.println("MMM/dd/YYYY HH:mm:ss:SSSS-           "+ dateFormat.format(today));
       
        dateFormat= new SimpleDateFormat("dd/MMM/YYYY hh:mm:ss a");
        System.out.println("Indian Time Format: dd/MMM/YYYY hh:mm:ss a-           "+ dateFormat.format(today));
       
        //time hour, minute, sec
        dateFormat= new SimpleDateFormat("hh");
        System.out.println("hh 1-12 clock: "+ dateFormat.format(today));
        //h    Hour (1-12, AM/PM)    Number
       
        dateFormat= new SimpleDateFormat("HH");
        System.out.println("HH 24 hour format: "+ dateFormat.format(today));
        //H    Hour (0-23)    Number
       
        dateFormat= new SimpleDateFormat("mm");
        System.out.println("Minutes: "+ dateFormat.format(today));

        dateFormat= new SimpleDateFormat("ss");
        System.out.println("Seconds: "+ dateFormat.format(today));

        dateFormat= new SimpleDateFormat("SSSS");
        System.out.println("MilliSeconds: "+ dateFormat.format(today));
       
        // http://javatechniques.com/blog/dateformat-and-simpledateformat-examples/
        dateFormat= new SimpleDateFormat("a");   //    am/pm
        System.out.println("am/pm: "+ dateFormat.format(today));
       
        dateFormat= new SimpleDateFormat("z");   //    am/pm
        System.out.println("Zone: "+ dateFormat.format(today));
       
//        Outputs:
/*    

Calender getTime: Sun Aug 10 22:19:00 IST 2014
Calender getTimeZone: sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null]
Hour of the day: 22
Month full Name: August
Month Name in short: Aug
Month in Numeric: 08
Day name in short: Sun
Day name in full: Sunday
Day number in a month: 10
Date and Time: 8/10/14 10:19 PM
MM/dd/YYYY HH:MM:ss-            08/10/2014 22:19:00
dd/MM/YYYY HH:MM:ss:SSSS-           10/08/2014 22:19:00:0997
MMM/dd/YYYY HH:mm:sss-           Aug/10/2014 22:19:000
MMM/dd/YYYY HH:mm:ss:SSSS-           Aug/10/2014 22:19:00:0997
Indian Time Format: dd/MMM/YYYY hh:mm:ss a-           10/Aug/2014 10:19:00 PM
hh 1-12 clock: 10
HH 24 hour format: 22
Minutes: 19
Seconds: 00
MilliSeconds: 0997
am/pm: PM
Zone: IST
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook
Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:"C:\Program Files (x86)\HP\Unified Functional Testing\bin\java_shared\classes";"C:\Program Files (x86)\HP\Unified Functional Testing\bin\java_shared\classes\jasmine.jar"

 */
    }
}