diff --git a/.gitignore b/.gitignore
index 2a3dcbd..3b2cda6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,13 @@
-bin/
-browserstack-api/target
-*.class
+target/**
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
.DS_Store
+*.class
*.swp
.project
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..7ae573f
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,51 @@
+
+ 4.0.0
+ com.BS
+ BrowserStack-local-java
+ jar
+ 1.0-SNAPSHOT
+ BrowserStack-local-java
+ http://maven.apache.org
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ org.seleniumhq.selenium
+ selenium-java
+ 2.45.0
+
+
+ org.seleniumhq.selenium
+ selenium-server
+ 2.45.0
+
+
+ net.lingala.zip4j
+ zip4j
+ 1.3.2
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.4.2
+
+
+
+
diff --git a/src/main/java/com/BS/App.java b/src/main/java/com/BS/App.java
new file mode 100644
index 0000000..aeef838
--- /dev/null
+++ b/src/main/java/com/BS/App.java
@@ -0,0 +1,13 @@
+package com.BS;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
diff --git a/src/main/java/com/BS/BrowserStackLocalException.java b/src/main/java/com/BS/BrowserStackLocalException.java
new file mode 100644
index 0000000..35e44f3
--- /dev/null
+++ b/src/main/java/com/BS/BrowserStackLocalException.java
@@ -0,0 +1,10 @@
+package com.BS;
+
+class BrowserStackLocalException extends Exception
+
+{
+ BrowserStackLocalException(String message)
+ {
+ super(message);
+ }
+}
diff --git a/src/main/java/com/BS/Local.java b/src/main/java/com/BS/Local.java
new file mode 100644
index 0000000..cdb5913
--- /dev/null
+++ b/src/main/java/com/BS/Local.java
@@ -0,0 +1,122 @@
+package com.BS;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+class Local{
+
+ Process BrowserStackLocal = null;
+ List command;
+ HashMap parameters;
+
+ void start(HashMap options) throws Exception
+ {
+ LocalBinary lb = new LocalBinary();
+ command = new ArrayList();
+ command.add(lb.binary_path);
+ command.add(options.get("key"));
+
+ makeCommand(options);
+
+ if (BrowserStackLocal == null)
+ {
+ ProcessBuilder processBuilder = new ProcessBuilder(command);
+
+ System.out.println("Setting up Local Testing connection...");
+ BrowserStackLocal = processBuilder.start();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(BrowserStackLocal.getInputStream()));
+ String string;
+ int j = 0;
+ while ((string = reader.readLine()) != null)
+ {
+ if (string.equalsIgnoreCase("Press Ctrl-C to exit"))
+ {
+ System.out.println("Local Testing connection has been established.");
+ break;
+ }
+
+ if (string.contains("*** Error"))
+ {
+ throw new BrowserStackLocalException(string);
+ }
+ if (j++ > 20)
+ {
+ throw new BrowserStackLocalException("Could not start BrowserStackLocal");
+ }
+ }
+
+ }
+
+ }
+
+ void stop()
+ {
+ if (BrowserStackLocal != null)
+ {
+ BrowserStackLocal.destroy();
+ System.out.println("Disconnected successfully");
+ }
+ }
+
+ boolean isRunning()
+ {
+ try
+ {
+ BrowserStackLocal.exitValue();
+ return false;
+ }
+ catch (Exception e)
+ {
+ return true;
+ }
+ }
+
+ void init()
+ {
+ parameters = new HashMap();
+ parameters.put("v","-v");
+ parameters.put("f","-f");
+ parameters.put("h","-h");
+ parameters.put("version", "-version");
+ parameters.put("force", "-force");
+ parameters.put("only", "-only");
+ parameters.put("forcelocal", "-forcelocal");
+ parameters.put("onlyAutomate", "-onlyAutomate");
+ parameters.put("proxyHost", "-proxyHost");
+ parameters.put("proxyPort", "-proxyPort");
+ parameters.put("proxyUser", "-proxyUser");
+ parameters.put("proxyPass", "-proxyPass");
+ parameters.put("hosts", "-hosts");
+ parameters.put("logfile", "-logfile");
+ }
+
+ Local() throws Exception
+ {
+ init();
+ }
+
+ void makeCommand(HashMap options)
+ {
+ Set set = options.entrySet();
+ Iterator i = set.iterator();
+ while(i.hasNext())
+ {
+ Map.Entry me = (Map.Entry)i.next();
+ String parameter = me.getKey().toString().trim();
+ if(parameters.get(parameter)!=null)
+ if(me.getValue()!=null)
+ {
+ command.add(parameters.get(parameter));
+ command.add((String) me.getValue());
+ }
+ else
+ command.add(parameters.get(parameter));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/BS/LocalBinary.java b/src/main/java/com/BS/LocalBinary.java
new file mode 100644
index 0000000..66f409e
--- /dev/null
+++ b/src/main/java/com/BS/LocalBinary.java
@@ -0,0 +1,136 @@
+package com.BS;
+
+import java.io.File;
+import java.net.URL;
+import org.apache.commons.io.FileUtils;
+
+import net.lingala.zip4j.core.ZipFile;
+import net.lingala.zip4j.exception.ZipException;
+
+class LocalBinary {
+
+ String http_path;
+ String dest_parent_dir;
+ String binary_path;
+ String osname;
+ String arch;
+ String orderedPaths[] = {System.getProperty("user.home")+"/browserstack", System.getProperty("user.dir"),System.getProperty("java.io.tmpdir")};
+
+ LocalBinary() throws Exception
+ {
+ initialize();
+ getBinary();
+ }
+
+ void initialize()
+ {
+ osname = System.getProperty("os.name");
+ arch = System.getProperty("os.arch");
+
+ if(osname.contains("Mac") || osname.contains("Darwin"))
+ http_path="https://www.browserstack.com/browserstack-local/BrowserStackLocal-darwin-x64.zip";
+
+ else if(osname.contains("Windows"))
+ http_path="https://www.browserstack.com/browserstack-local/BrowserStackLocal-win32.zip";
+
+ else if (osname.contains("Linux") && arch.contains("64"))
+ http_path="https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-x64.zip";
+
+ else
+ http_path="https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-ia32.zip";
+ }
+
+ Boolean getBinary() throws Exception
+ {
+ dest_parent_dir = getAvailableDirectory();
+
+ if (osname.contains("Windows"))
+ binary_path = dest_parent_dir + "/BrowserStackLocal.exe";
+ else
+ binary_path = dest_parent_dir + "/BrowserStackLocal";
+
+ if (new File(binary_path).exists())
+ return true;
+ else
+ return downloadBinary(dest_parent_dir);
+
+ }
+
+ String getAvailableDirectory() throws Exception
+ {
+ int i=0;
+ while(i options = new HashMap();
+ options.put("key", "");
+ options.put("only", "localhost,80,0");
+ options.put("forcelocal", "");
+ options.put("proxyHost", "127.0.0.1");
+ options.put("proxyPort", "8118");
+ options.put("xyz", "qwerty");
+ l.start(options);
+
+ driver = new RemoteWebDriver(
+ new URL("http://:@hub.browserstack.com/wd/hub"),caps);
+ }
+
+ @Test
+ public void testSimple() throws Exception {
+ driver.get("http://localhost");
+ System.out.println("Process is running : " + l.isRunning());
+ System.out.println("Page title is: " + driver.getTitle());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ driver.quit();
+ l.stop();
+ }
+}
\ No newline at end of file