Friday, May 16, 2014

Mobile Browser Perf Automation Android

Products which can use this:

  1. E-invoice
  2. QBO-lite
  3. Virtual Office

Tools:

  1. Google Chrome
  2. Developer Tools
  3. Using Selenium 
  4. Appium

Setup:
 

 A. On the Android Phone:

1. Unlock the developer mode on Android phone.
2. Give a name to android phone by going to
3. Download Chrome app on Android phone
4. Connect the Android phone to mac

B. On the Macbook:

1. Install Chrome browser.
2. Click on ‘Customize and Control Google chrome’ tab from the browser menu.
3. Click on ‘Inspect devices’ and check the box which says “Discover USB devices”


 Steps to Automate:


1. Launch the chrome app on the phone
2. You can use adb from mac book to do that.
3. Use selenium to launch chrome://inspect/#devices chrome developer tool inspect device section.
4. Now if you have launch chrome correctly on the device and if you have done above setup right, then you should see something like this:

5. Add your e-invoice link in “Open tab with url” text section and click on Open button. (selenium)
Right now I am trying to open "http://www.intuit.com/"
You will see something like this:

6. Now click on  inspect button. It will open up developer tool window.
You will see something like this:

7. Click on the network tab and check the box which says preserve the logs


8. Go to Audits section and on Audits tab, check Select All.
9. Check the radio button “Reload page and Audit on load”
10. Go to Network tab and Right click on the log and click on "Save as HAR with content"


11. Upload this data on server and render it using some HAR viewer





Friday, September 2, 2011

How to lauch iphone app from command prompt

If you want to launch you iOS app, iphone app from command prompt/terminal, here are the steps.

1. Download iphonesim source code from https://github.com/jhaynie/iphonesim

2. Untar the package and use xcodebuild to build the package


$unzip jhaynie-iphonesim-d930444.zip
$
$ cd jhaynie-iphonesim-d930444
$ ls
README iPhoneSimulatorRemoteClient iphonesim_Prefix.pch
Source iphonesim.xcodeproj
$
$ which xcodebuild
/usr/bin/xcodebuild
$
$ xcodebuild -project iphonesim.xcodeproj -alltargets

3. After you build iphonesim project, it will create an iphonesim binary in Release folder

$ pwd
jhaynie-iphonesim-d930444/build/Release
$ ls
iphonesim iphonesim.dSYM
$

4. You can run the application by first building your application in xcode using the xcodebuild command from the command line. You can then run it in the simulator using follwing an an example:

$ iphonesim launch ~/tmp/yourproject/build/Debug.simulator/yourproject.app

You need to point to either Debug.simulator or Release.simulator based on which build type you built with.


Wednesday, February 16, 2011

Install PHPunit and upgrading PEAR.

PhpUnit manual has all information about to install phpunit on your server.

http://www.phpunit.de/manual/3.5/en/phpunit-book.html#installation

PHPUnit 3.5 requires PHP 5.2.7 (or later) but PHP 5.3.3 (or later) is highly recommended.

sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony-project.com

This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:

sudo pear install phpunit/PHPUnit

After the installation you can find the PHPUnit source files inside your local PEAR directory; the path is usually /usr/lib/php/PHPUnit.
After installation, if you don't find phpunit utility, the please check your pear installation version.
Phpunit installation requires PEAR version >= 1.9.1
You can update PEAR version by using command,

sudo pear upgrade pear

This will upgrade pear and then if you run 'pear install phpunit/PHPUnit' this will install phpunit correctly.

If you see following error,

Failed to download pear/HTTP_Request2 within preferred state "stable", latest release is version 2.0.0RC1, stability "beta", use "channel://pear.php.net/HTTP_Request2-2.0.0RC1" to install
phpunit/PHPUnit can optionally use PHP extension "dbus"
pear/XML_RPC2 requires package "pear/HTTP_Request2" (version >= 0.6.0)
phpunit/PHPUnit requires package "pear/XML_RPC2"
No valid packages found
install failed

To install this missing HTTP_Request2 package, run following command,

sudo pear install HTTP_Request2-2.0.0RC1

If you see following error while executing above command,

Failed to download pear/Net_URL2 within preferred state "stable", latest release is version 0.3.1, stability "beta", use "channel://pear.php.net/Net_URL2-0.3.1" to install
pear/HTTP_Request2 requires package "pear/Net_URL2" (version >= 0.3.0)
pear/HTTP_Request2 can optionally use PHP extension "fileinfo"
No valid packages found
install failed

Then in that case you will need to install Net_URL2 package first, for doing so use following command,

sudo pear install NET_URL2-0.3.1

now install HTTP_Request2 and then PHPUnit.

Sunday, September 5, 2010

Java 5.0 Multithreading feature - Callable and Future

One of the very important feature of Java 5.0 is Callable Interface and Future.
The problem with Runnable interface or Thread class in multithreading was you can return any value from the thread.
But this drawback was removed in Java 5.0 with Callable Interface and Future.
In the code below, Callable<Interger> in CallableExample, the thread will return 'Integer' and this Integer value can be retrieved using Future object as shown in CallableExampleTest.

1. Callable Implementation:
----->

import java.util.concurrent.Callable;

/**
*
* @author vinitpatwa
*/
public class CallableExample implements Callable<Integer> {

private String word;

public CallableExample(String word) {

this.word = word;
}

public Integer call() {

return getWord().length();

}

public String getWord() {
return word;
}
}

<-----

2. Testing the Callable implementation
----->
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
*
* @author vinitpatwa
*/
public class CallableExampleTest {

public static void main(String args[]) throws Exception{

ExecutorService pool=Executors.newFixedThreadPool(1);
List<Future<Integer>> set=new LinkedList<Future<Integer>>();
String[] strArray={"Texas", "California", "Ohio"};
for(String word:strArray){

Callable cal=new CallableExample(word);
Future<Integer> future=pool.submit(cal);
set.add(future);

}

for(Future<Integer> future:set){
System.out.println("Length of word is : "+future.get());
}
}
}

<-----

Thursday, September 2, 2010

Design Patterns Tutorial

1. Singleton Pattern
-------------------------------------
A Singleton is a class that can be instantiated only one time in a JVM per class loader. Repeated calls always returns the same instance. Ensures that a class has only one instance, and provide a global point of access. It can be an issue if singleton class gets loaded by multiple class loader or JVMs

An example of Singleton Pattern

public class OnlyOne{

private static OnlyOne one=new OnlyOne();

//private constructory
//This class can not be instantiated from outside and prevent subclassing
private OnlyOne(){}

public static OnlyOne getInstance(){
retrun one;
}

}


2. Factory Pattern
-------------------------------------
A factory method pattern is creational pattern. The creational patterns abstract the object instantiation process by hiding how the objects are created and make the system independent of the object creational process.
Factory pattern returns one of the several product subclasses. You should use a factory pattern, if you have a super class and number of subclasses, and based on some data provided, you have to return the object of one of the subclasses, But the calling code is unaware of the actual implementation.
Factory pattern reduces the coupling or the dependencies between calling code and the called object.

The abstract factory pattern is one level of abstraction higher than factory method pattern, which means it returns the factory classes.

3. FlyWeight Design Pattern:
-------------------------------------
When we create string objects String s1="A"; String s2="A".
It will check if it is already in the string pool, if it is there, then it will get it from there. Flyweight are like Shared objects and reusing them will have considerable performance gain


4. Decorater Design Pattern:
-------------------------------------
Decorator pattern attaches responsibilities to objects at runtime.
Java.io classes uses Decorator design pattern to construct different combination of behavior at runtime based on some basic classes.

File file=new File("C:/temp");
FileInputStream f=new FileInputStream(file);
BufferredInputStream output=new BufferredInputStream(f);

Decorator design pattern add or restrict functionality of decorator object before or after forwarding the request.
At runtime 'output' which is decorator objects forward the method calls to it's decorated object 'f'

5. Observer Pattern (publisher - subscriber design pattern)
-------------------------------------
(one publisher - one / multiple subscriber)
Intent of this design pattern is to define one to many dependency so that when one object(i.e. Publisher changes it's state, all it's dependents(i.e. all it's subscribers) are notified and updated successfully.

6. Reactor Design pattern
-------------------------------------
Unlike Observer pattern, Reactor design pattern handles multiple even sources (multiple publisher - one / multiple subscriber)
NIO(New I/O API) uses this, which demultiplexes events(separating single stream into multiple stream) and dispatches them to registered object handlers.

Friday, July 9, 2010

Using SQLite with SQLiteJDBC driver.

1. SQLite is serverless. With SQLiteJDBC driver, we can write programs to access SQLite using JAVA.
This tutorial will have step by step description about how to do it.

2. We will use Netbeans, but it will work in the same manner with eclipse too.

3. Download SQLiteJDBC driver jar, 'sqlitejdbc-v056.jar' from website: http://www.zentus.com/sqlitejdbc/

4. Create a java project named 'SQLite' in Netbeans.(You can give any name

5. Create a class called 'Test' in that project.

6. Add 'sqlitejdbc-v056.jar' in the class path of 'SQLite' project in Netbeans.

7. Paste following code in Test class


--->
import java.sql.*;

public class Test {

public static void main(String[] args) throws Exception {
Class.forName("org.sqlite.JDBC");
Connection conn =
DriverManager.getConnection("jdbc:sqlite:Vinit");
Statement stat = conn.createStatement();
stat.executeUpdate("drop table if exists school;");
stat.executeUpdate("create table school (name, state);");
PreparedStatement prep = conn.prepareStatement(
"insert into school values (?, ?);");

prep.setString(1, "UTD");
prep.setString(2, "texas");
prep.addBatch();
prep.setString(1, "USC");
prep.setString(2, "california");
prep.addBatch();
prep.setString(1, "MIT");
prep.setString(2, "massachusetts");
prep.addBatch();

conn.setAutoCommit(false);
prep.executeBatch();
conn.setAutoCommit(true);

ResultSet rs = stat.executeQuery("select * from school;");
while (rs.next()) {
System.out.print("Name of School = " + rs.getString("name") + " ");
System.out.println("state = " + rs.getString("state"));
}
rs.close();
conn.close();
}
}


--->

8. Run the project as java application.

9. It will create database file by name 'Vinit' in the Netbeans 'SQLite' project folder.

10. Here is in above code, we are creating sqlite database 'Vinit'.

I hope it will be helpful.

source:
http://www.zentus.com/sqlitejdbc/
http://www.sqlite.org/download.html

Thursday, May 6, 2010

How to run command on Karaf command prompt from other java program

I wanted to uninstall 'clock_3.0' bundle which is running in karaf. So I can do it by typing 'features:uninstall clock_3.0' command on karaf command prompt.
But Now I wanted to run this command from some other Java program.

We can do this by running following command:

Process ls_proc1;
ls_proc1 = Runtime.getRuntime().exec("cmd.exe /C java -jar C:\\apache-felix-karaf-1.2.0\\lib\\karaf-client.jar features:uninstall clock_3.0");

where apache-felix-karaf-1.2.0 is installed at C: on my computer.

We can even display the output of this command:

try {
BufferedReader br = new BufferedReader(new InputStreamReader(ls_in));
while ((ls_str1 = br.readLine()) != null) {
System.out.println(ls_str1);
}
} catch (IOException e1) {
e1.printStackTrace();
}

Wednesday, April 21, 2010

How to display HTML tags, code in blogs

When you try displaying HTML tags in blogs, it as disappear when you try publishing it.

So if you want to display something like

<html>
Hello World
</html>

When you will try publishing the post, it will only show,

Hello World

All the HTML tags won't be displayed.

If you want to do that, there is an easy way around.

Just Replace

And you can display all your HTML tags in your blog.

Maven build lifecycle

I came across this really good article which talks about Maven build life cycle.


A Build Lifecycle is Made Up of Phases

Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.

For example, the default lifecycle has the following build phases (for a complete list of the build phases, refer to the Lifecycle Reference):

  • validate - validate the project is correct and all necessary information is available
  • compile - compile the source code of the project
  • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package - take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test - process and deploy the package if necessary into an environment where integration tests can be run
  • verify - run any checks to verify the package is valid and meets quality criteria
  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

These build phases (plus the other build phases not shown here) are executed sequentially to complete the default lifecycle. Given the build phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the package, install the verifed package to the local repository, then deploy the installed package in a specified environment.

To do all those, you only need to call the last build phase to be executed, in this case, deploy:

mvn deploy

That is because if you call a build phase, it will execute not only that build phase, but also every build phase prior to the called build phase.

source:http://stackoverflow.com/questions/1544619/if-i-run-mvn-deploy-does-it-build-new-artifacts-or-it-just-deploy-the-already-exi

How can we turn on the display of folders/directories in web browser which present under tomcat ROOT directory.

I downloaded apache tomcat server and added a folder repository in 'apache-tomcat-6.0.26\webapps\ROOT' directory which contains many subfolders/subdirectories and html pages, jars inside those folders/directories.
I can go index page in 'apache-tomcat-6.0.26\webapps\ROOT' folder by typing the URL as 'http://localhost:8080'

But now if I want to download any jar present in some subfolder of repository directory, I can do it by typing the relative path of the jar file and adding the URL.

Suppose x.jar is present in the directory 'repository\xx\yy\x.jar', then I can download it by accessing following URL : 'http://localhost:8080/repository/xx/yy/x.jar'

But I type something like 'http://localhost:8080/repository/xx/yy' it will give me error page.

If you want to turn on the display of directories/folders in the web browser in case the default file like index.html is not present, then it should display the list of files and directories present under that directory mentioned in the URL.

For enabling this, you have to set 'listings' parameter in the default servlet to true. You have to edit the web.xml flie present at location: 'apache-tomcat-6.0.26\conf' directory.

Set it as shown below:

<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>


Once you do this, You can see web browser will display the directory structure, the list of files and sub-directories present the directory mentioned in URL

Friday, March 26, 2010

Linear Search Java Example

Below is linear Searching Algorithm implemented in Java.



import java.util.Scanner;

//##################################################
// Linear Search
//##################################################
//Program has list of integers saved in an array and
//program will take inputs from user and search that
//if that input is present in Array of Integers.

public class linearSearch {

public static void main(String args[]) {

int[] listOfIntegers = { 1, 34, 53, 23, 77, 98, 101, 20, 45, 66, 84 };
int inputTobeSearch;

Scanner sn = new Scanner(System.in);
inputTobeSearch = sn.nextInt();
int token = -1;

for (int i = 0; i < listOfIntegers.length; i++) {

if (listOfIntegers[i] == inputTobeSearch) {
token = i;
}
}

if (token != (-1)) {
System.out
.println("Input integer " + inputTobeSearch
+ " is present at " + (token + 1)
+ "th place in the Array");
} else
System.out.println("Input integer " + inputTobeSearch
+ " is not present in the Array");

}

}

Thursday, March 25, 2010

Execute a command from Java Program on Windows Mac or *nix System

I was working on some project and I wanted to write a code which will execute command from Java Program and it should run irrespective of Operating system.

So wrote a code and thought it will be nice to share, or may be it will be good for me, if I want to look at it after a while :)

The code below will run command from Java file even if it is Windows or Mac OS or Unix





//Package name is of the package
package finalgui;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author Vinit Patwa
*/
public class RunCommand {

private static String ls_str;

public static void main(String args[]) {

try {
Process ls_proc;

//we want to run command "mvn clean install"
//It is expected that "mvn" is in your PATH
String mvnClean = "mvn clean install";

//We are storing the OS on system in String OS
String OS = System.getProperty("os.name");
System.out.println("OS is: " + OS);


if (OS.contains("Windows")) {
ls_proc = Runtime.getRuntime().exec("cmd.exe /C mvn clean install");
} else {
ls_proc = Runtime.getRuntime().exec(mvnClean);
}


//We can also display the output of the command Here
DataInputStream ls_in = new DataInputStream(
ls_proc.getInputStream());
try {
BufferedReader br = new BufferedReader(new InputStreamReader(ls_in));
while ((ls_str = br.readLine()) != null) {
System.out.println(ls_str);
}
} catch (IOException e1) {
System.exit(0);
}
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();

}
}
}

Friday, March 5, 2010

1. Tutorials on Socket:

C/C++

JAVA

2. Tutorials on Threads

Pthreads

JAVA

Source: http://vinitpatwa.wordpress.com/2009/09/01/socket-programming-and-multithreading-resources/

JBPM new web based BPMN editor


The jBPM Modeller is an advanced web based BPMN editor aimed at non technical business users. No software needs to be installed on the user's machine, a plain web browser is enough to get the job done. Business analysts can easiliy produce complex process models with the tool, which then later can be imported by developers in their Eclipse environment without any conversion needed.

The jBPM Modeller is based on the fantasic web based modeling tool by Signavio. In less than a minute, every stakeholder involved can view, edit and collaborate on process models through their own brower. source: www.jboss.org

Wednesday, March 3, 2010

java.io.IOException: CreateProcess: ... error=193

When I tried running an executable from from Java Jar file, while executing following code -

Runtime.getRuntime().exec("C:\\maven\\apache-maven-2.2.1\\bin\\mvn pax:provision");

I got following Exception -

java.io.IOException: Cannot run program "C:\maven\apache-maven-2.2.1\bin\mvn": CreateProcess error=193, %1 is not a valid Win32 application

To resolve this problem, the command should be invoked as:

Runtime.getRuntime().exec("cmd.exe /C C:\\maven\\apache-maven-2.2.1\\bin\\mvn pax:provision");

And it worked.

(Running executable from Java Jar file)

Tuesday, March 2, 2010

Install Maven Pax Plugin

MAVEN PAX PLUGIN:

The Pax Plugin is a "Swiss Army(tm) knife" for OSGi that provides goals to create, build, manage and deploy many types of OSGi bundles. While the easiest way to install and use this plugin is by using the Pax-Construct scripts, its goals can also be used directly on the Maven command line, or inside other Maven POMs.

Steps for installing Maven Pax Construct Plugin:

1. Get the pax zip and unzip it to temp (or any other directory you prefer):

http://repo1.maven.org/maven2/org/ops4j/pax/construct/scripts/1.4/scripts-1.4.zip

2. Open up the command prompt and enter the command:

set PATH=C:\temp\pax-construct-1.4\bin;%PATH%

Saturday, August 29, 2009

How to increase Netbeans IDE heapsize

It's always good to keep a copy of netbeans.conf file before starting this process.

  1. From the etc directory in the NetBeans IDE installation directory, copy the netbeans.conf file into your NetBeans IDE user directory, for example: $HOME/ .netbeans/caps/etc directory.

    Note - You may need to create the etc directory in the NetBeans IDE user directory.

  2. In your NetBeans IDE user directory, edit the —J-Xmx command line Java startup switch in the netbeans.conf file, for example:
    # command line switches
    netbeans_default_options=" -J-Xms32m -J-Xmx128m -J-XX:PermSize=32m
    -J-XX:MaxPermSize=96m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true"
  3. Restart NetBeans IDE.
source: http://developers.sun.com

Wednesday, August 26, 2009

Apple is coming up with Mac OS X Snow Leopard on Aug 28 '09

Snow Leopard Server includes dozens more new features, enhancements, and improvements. For example, Mail Server now includes push email support and runs on a new engine that scales to handle tens of thousands of users at a time. With the new 64-bit kernel, Snow Leopard Server can fully utilize more physical memory, dramatically increasing the total number of simultaneous system processes, threads, and network connections the server can handle.
Apart from this, finder is updated, apple has made it more powerful. I will discuss couple of it's features today.

iCal Server 2

With iCal Server 2, Apple claims that sharing calendars, scheduling meetings and co-ordinating meetings will be easy within a workgroup. One good thing I liked about it is, iCal Server 2 allows you to invite your colleagues for a meeting over email if they aren't using iCal, iCal Server 2.

Wiki Server 2

Mac OS X Server makes it easy for groups to collaborate and communicate through their own wiki-powered intranet website. Wiki Server 2 now includes one of the most useful features in Mac OS X: Quick Look. Just click the Quick Look icon next to an uploaded document and you can view it without downloading the file. Quick Look supports all standard file formats, including text, Word, Excel, PowerPoint, Pages, Numbers, Keynote, QuickTime, and PDF.

source: apple.com

Monday, August 24, 2009

Java Server Faces

One of the greatest advantages of JavaServer Faces technology is that it offers a clean separation between behavior and presentation. Web applications built using JSP technology achieve this separation in part. However, a JSP application cannot map HTTP requests to component-specific event handling nor manage UI elements as stateful objects on the server, as a JavaServer Faces application can. JavaServer Faces technology allows you to build web applications that implement the finer-grained separation of behavior and presentation that is traditionally offered by client-side UI architectures.
The separation of logic from presentation also allows each member of a web application development team to focus on his or her piece of the development process, and it provides a simple programming model to link the pieces. For example, page authors with no programming expertise can use JavaServer Faces technology UI component tags to link to server-side objects from within a web page without writing any scripts.
Another important goal of JavaServer Faces technology is to leverage familiar UI-component and web-tier concepts without limiting you to a particular scripting technology or markup language. Although JavaServer Faces technology includes a JSP custom tag library for representing components on a JSP page, the JavaServer Faces technology APIs are layered directly on top of the Servlet API. This layering of APIs enables several important application use cases, such as using another presentation technology instead of JSP pages, creating your own custom components directly from the component classes, and generating output for various client devices.
Most importantly, JavaServer Faces technology provides a rich architecture for managing component state, processing component data, validating user input, and handling events.