Sunday, 5 July 2015

Time in seconds to execute scripts, IP Address and environment detials - JAVA

package test;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;



public class SystemEg {

    public static void main(String[] args) throws UnknownHostException, InterruptedException {
        System.out.println(System.getProperty("os.name"));
        System.out.println(System.getProperty("os.version"));
        System.out.println(System.getProperty("os.arch"));
       
        InetAddress addr = InetAddress.getLocalHost();
        String hostname = addr.getHostName();
        System.out.println("Hostname: "+hostname);
        System.out.println("IP Address: "+addr.getHostAddress());
        System.out.println("Local Host: "+addr.getLocalHost());
       
       
        Date todaysDate = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss a");
        String formattedDate = formatter.format(todaysDate);
        System.out.println(formattedDate);
       
//        Calculate execution time in seconds..
        long iStartTime = 0;
        long iEndTime = 0;
        iStartTime = System.currentTimeMillis();
        Thread.sleep(3000);
        iEndTime = System.currentTimeMillis();   
        System.out.println(TimeUnit.MILLISECONDS.toSeconds(iEndTime-iStartTime));       
    }
}

/*
Output:
Windows 7
6.1
amd64
Hostname: IN22222
IP Address: xxx.xxx.x.x
12:23:46 PM
3
*/

Tuesday, 12 May 2015

Java - Abstract methods and class

package com.cig.java;

public abstract class MyAbstract {
//Abstract method
public abstract void good();
protected abstract void bad();
//Concrete method
public void superBoy(){
System.out.println("Welcome Super boy!");
}
}

--------------------------------------------

package com.cig.java;

public class ExtendAbstract extends MyAbstract{

public static void main(String[] args) {
MyAbstract my = new ExtendAbstract(); 
my.superBoy();
}

@Override
public void good() {
}

@Override
protected void bad() {
}
}


Java- Interface implements example




package com.cig.java;

public interface MyInter {
void sayHi();
public abstract void sayBye();
public static final double PI = 3.14;
}

-----------------------------
package com.cig.java;

public interface MyInterTwo {
public String connect();
}

-------------------------------
package com.cig.java;

public class Test implements MyInter{

@Override
public void sayHi() {
System.out.println("Hi! PI Value is : "+ MyInter.PI);
}

@Override
public void sayBye() {
System.out.println("Bye!");
}
public static void main(String a[]) {
Test ts = new Test();
ts.sayHi();
ts.sayBye();
}
}
--------------------------------------
package com.cig.java;

import java.io.Serializable;

public class TestThree extends Test implements MyInter,MyInterTwo, Serializable{

@Override
public String connect() {
return "";
}
}

----------------------------

Friday, 1 May 2015

Git Bash to check-in code to Bit-bucket

Install Git
Configure Git-Bash

Navigate to path: CD c:

Command to Pull the code from Bitbucket:
git pull

Command to push the code to Bitbucket:

to check the status:
git status

To add the code:
git add -A

To commit the changes:
git commit -m 'your message'

git push... to committ..



To switch to another branch:
git checkout venu

Tuesday, 28 April 2015

Auto IT and Selenium Webdriver

Install AutoIT tool
Goto C:\Program Files (x86)\AutoIt3\Extras\Au3Record and launch "Au3Record.exe"
Click on the Icon to start recording.
Record the operation and save the steps to "test.au3".
Now go to the location where the above test.au3 is saved.
Right click and then click on "Compile Script". Test.exe executor file will be generated.

Call this exe file in the script when required.