Skip to content

Commit

Permalink
DanielWagnerHall: Using iphonesim to run iphone tests without needing…
Browse files Browse the repository at this point in the history
… to manually open the simulator. ./go test_iphone should work, as should ./go //java/client/test/org/openqa/selenium/iphone:test:run (although it seems to suffer from the NoHttpResponse issue on occasion, which is awesome. Let's get using Mongoose/keepalives in this thing, eh? Only one simulator can be running at once. The build is still a bit chatty (it recompiles the objc every time), but it works... iphonesim isn't packaged in with the release jar, because the iWebDriver isn't included in the release jar, so including it doesn't make a lot of sense. Users can extend IPhoneSimulatorBinary and override getIphoneSimPath(), or package a jar containing /mac/iphonesim as a resource. Ignoring a few tests here, I doubt they're meant to fail, so I'll file an issue about them... Maybe someone will even fix them\!

r14697
  • Loading branch information
illicitonion committed Nov 12, 2011
1 parent e6bb225 commit 754a2c2
Show file tree
Hide file tree
Showing 18 changed files with 4,308 additions and 4,026 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<classpathentry kind="lib" path="third_party/java/jcip-annotations/jcip-annotations-1.0.jar"/>
<classpathentry kind="lib" path="third_party/java/commons-jxpath/commons-jxpath-1.3.jar"/>
<classpathentry kind="lib" path="third_party/java/jmock/jmock-legacy-2.5.1.jar"/>
<classpathentry kind="lib" path="third_party/java/commons-exec/commons-exec-1.1.jar" sourcepath="third_party/java/commons-exec/commons-exec-1.1-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/objenesis-1.0"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/webbit"/>
<classpathentry kind="output" path="out/production/selenium"/>
Expand Down
18 changes: 2 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ task :support => [
"//java/client/src/org/openqa/selenium/support",
]
task :iphone_client => ['//java/client/src/org/openqa/selenium/iphone']
task :iphone => [:iphone_test_setup, :iphone_server, :iphone_client]
task :iphone => [:iphone_server, :iphone_client]

desc 'Build the standalone server'
task 'selenium-server-standalone' => '//java/server/src/org/openqa/grid/selenium:selenium:uber'
Expand Down Expand Up @@ -146,8 +146,7 @@ task :test_support => [
"//java/client/test/org/openqa/selenium/support:SmallTests:run",
"//java/client/test/org/openqa/selenium/support:LargeTests:run"
]
task :test_iphone_client => [:'webdriver-iphone-client-test']
task :test_iphone => [:iphone_test_setup, :test_iphone_server, :test_iphone_client]
task :test_iphone => [:test_iphone_server, '//java/client/test/org/openqa/selenium/iphone:test:run']
task :android => [:android_client, :android_server]
task :android_client => ['//java/client/src/org/openqa/selenium/android']
task :android_server => ['//android/app:android-server']
Expand Down Expand Up @@ -533,19 +532,6 @@ task :test_selenium_py => [:'selenium-core', :'selenium-server-standalone'] do
end
end


task :iphone_test_setup do
iphone_test(:name => "webdriver-iphone-client-test",
:srcs => [ "java/client/test/org/openqa/selenium/iphone/**/*.java" ],
:deps => [
"//java/client/test/org/openqa/selenium:tests",
"//third_party/java/junit",
:iphone_server,
:iphone_client
])
end


#### iPhone ####
task :iphone_server do
sdk = iPhoneSDK?
Expand Down
7,773 changes: 3,907 additions & 3,866 deletions iphone/src/objc/atoms.h

Large diffs are not rendered by default.

60 changes: 55 additions & 5 deletions java/client/src/org/openqa/selenium/io/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

package org.openqa.selenium.io;

import com.google.common.collect.Lists;
import com.google.common.io.Closeables;

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriverException;

import java.io.BufferedReader;
Expand All @@ -34,13 +36,15 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.channels.FileChannel;
import java.util.List;

/**
* Utility methods for common filesystem activities
*/
public class FileHandler {
private static final Method JDK6_SETWRITABLE = findJdk6SetWritableMethod();
private static final File CHMOD_SETWRITABLE = findChmodCommand();
private static final Method JDK6_SETEXECUTABLE = findJdk6SetExecutableMethod();
private static final File CHMOD = findChmodCommand();

// TODO(simon): Move to using Zip class
public static File unzip(InputStream resource) throws IOException {
Expand All @@ -60,15 +64,24 @@ public static void copyResource(File outputDir, Class<?> forClassLoader, String.
try {
zip.unzipFile(outputDir, is, name);
} finally {
Closeables.closeQuietly(is);
try {
Closeables.closeQuietly(is);
} catch (Exception e) {

}
}
}
}

private static InputStream locateResource(Class<?> forClassLoader, String name)
throws IOException {
String arch = System.getProperty("os.arch").toLowerCase() + "/";
String[] alternatives = {name, "/" + name, arch + name, "/" + arch + name};
List<String> alternatives =
Lists.newArrayList(name, "/" + name, arch + name, "/" + arch + name);
if (Platform.getCurrent().is(Platform.MAC)) {
alternatives.add("mac/" + name);
alternatives.add("/mac/" + name);
}

// First look using our own classloader
for (String possibility : alternatives) {
Expand Down Expand Up @@ -113,10 +126,10 @@ public static boolean makeWritable(File file) throws IOException {
} catch (InvocationTargetException e) {
// Do nothing. We return false in the end
}
} else if (CHMOD_SETWRITABLE != null) {
} else if (CHMOD != null) {
try {
Process process = Runtime.getRuntime().exec(
new String[] {CHMOD_SETWRITABLE.getAbsolutePath(), "+x", file.getAbsolutePath()});
new String[] {CHMOD.getAbsolutePath(), "+w", file.getAbsolutePath()});
process.waitFor();
return file.canWrite();
} catch (InterruptedException e1) {
Expand All @@ -126,6 +139,32 @@ public static boolean makeWritable(File file) throws IOException {
return false;
}

public static boolean makeExecutable(File file) throws IOException {
if (file.canExecute()) {
return true;
}

if (JDK6_SETEXECUTABLE != null) {
try {
return (Boolean) JDK6_SETEXECUTABLE.invoke(file, true);
} catch (IllegalAccessException e) {
// Do nothing. We return false in the end
} catch (InvocationTargetException e) {
// Do nothing. We return false in the end
}
} else if (CHMOD != null) {
try {
Process process = Runtime.getRuntime().exec(
new String[] {CHMOD.getAbsolutePath(), "+x", file.getAbsolutePath()});
process.waitFor();
return file.canExecute();
} catch (InterruptedException e1) {
throw new WebDriverException(e1);
}
}
return false;
}

public static boolean isZipped(String fileName) {
return fileName.endsWith(".zip") || fileName.endsWith(".xpi");
}
Expand Down Expand Up @@ -212,6 +251,17 @@ private static Method findJdk6SetWritableMethod() {
}
}

/**
* File.setWritable appears in Java 6. If we find the method, we can use it
*/
private static Method findJdk6SetExecutableMethod() {
try {
return File.class.getMethod("setExecutable", Boolean.class);
} catch (NoSuchMethodException e) {
return null;
}
}

/**
* In JDK5 and earlier, we have to use a chmod command from the path.
*/
Expand Down
Loading

0 comments on commit 754a2c2

Please sign in to comment.