diff --git a/README.md b/README.md
index 5b9efccc1..ab11c13d2 100644
--- a/README.md
+++ b/README.md
@@ -113,6 +113,8 @@ If you are using the Eclipse IDE, make sure you are using verison Luna or later.
- bug fix and enhancements of io.appium.java_client.service.local.AppiumDriverLocalService
- FIXED bug which was found and reproduced with Eclipse for Mac OS X. Please read about details here: [#252](https://github.com/appium/java-client/issues/252)
Thanks to [saikrishna321](https://github.com/saikrishna321) for the bug report
+ - FIXED bug which was found out by [Jonahss](https://github.com/Jonahss). Thanks for the reporting. Details: [#272](https://github.com/appium/java-client/issues/272)
+ and [#273](https://github.com/appium/java-client/issues/273)
- The ability to set additional output streams was provided
- The additional __startActivity()__ method was added to AndroidDriver. It allows to start activities without the stopping of a target app
Thanks to [deadmoto](https://github.com/deadmoto) for the contribution
diff --git a/pom.xml b/pom.xml
index 9263dafd7..25575045a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,8 +16,8 @@
-->
- 4.0.0
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
io.appium
java-client
@@ -65,97 +65,102 @@
Java client for Appium Mobile Webdriver
http://appium.io
-
-
- Apache License, Version 2.0
- http://www.apache.org/licenses/LICENSE-2.0.txt
- repo
-
-
+
+
+ Apache License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+ repo
+
+
-
- https://github.com/appium/java-client
- scm:git:git://github.com/appium/java-client.git
- scm:git:git@github.com:appium/java-client.git
-
+
+ https://github.com/appium/java-client
+ scm:git:git://github.com/appium/java-client.git
+ scm:git:git@github.com:appium/java-client.git
+
-
-
- jonahss@gmail.com
- Jonah Stiennon
- https://github.com/jonahss
- jonahss
-
+
+
+ jonahss@gmail.com
+ Jonah Stiennon
+ https://github.com/jonahss
+ jonahss
+
tichomirovsergey@gmail.com
Sergey Tikhomirov
https://github.com/TikhomirovSergey
TikhomirovSergey
-
+
-
-
- ossrh
- https://oss.sonatype.org/content/repositories/snapshots
-
-
- ossrh
- https://oss.sonatype.org/service/local/staging/deploy/maven2/
-
-
+
+
+ ossrh
+ https://oss.sonatype.org/content/repositories/snapshots
+
+
+ ossrh
+ https://oss.sonatype.org/service/local/staging/deploy/maven2/
+
+
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.2.1
-
-
- attach-sources
-
- jar-no-fork
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.9.1
-
-
- attach-javadocs
-
- jar
-
-
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 1.5
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.3
-
- 1.7
- 1.7
+
+
+
+ src/main/resources
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.2.1
+
+
+ attach-sources
+
+ jar-no-fork
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.9.1
+
+
+ attach-javadocs
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+ 1.5
+
+
+ sign-artifacts
+ verify
+
+ sign
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.3
+
+ 1.7
+ 1.7
eclipse
-
+
org.codehaus.plexus
@@ -163,32 +168,32 @@
2.5
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 2.18.1
-
-
- org.apache.maven.surefire
- surefire-junit47
- 2.18.1
-
-
-
-
-
- test
-
- integration-test
-
-
- **/*Test.java
-
-
-
-
-
-
-
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.18.1
+
+
+ org.apache.maven.surefire
+ surefire-junit47
+ 2.18.1
+
+
+
+
+
+ test
+
+ integration-test
+
+
+ **/*Test.java
+
+
+
+
+
+
+
diff --git a/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java b/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java
index 46504a9fd..91f180401 100644
--- a/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java
+++ b/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java
@@ -82,8 +82,13 @@ public URL getUrl() {
@Override
public boolean isRunning() {
lock.lock();
- if (process == null)
+ if (process == null) {
return false;
+ }
+
+ if (!process.isRunning()) {
+ return false;
+ }
try {
ping(500, TimeUnit.MILLISECONDS);
@@ -126,9 +131,11 @@ public void start() throws AppiumServerHasNotBeenStartedLocallyException {
destroyProcess();
String msgTxt = "The local appium server has not been started. " +
"The given Node.js executable: " + this.nodeJSExec.getAbsolutePath() + " Arguments: " + nodeJSArgs.toString() + " " + "\n";
- String processStream = process.getStdOut();
- if (!StringUtils.isBlank(processStream))
- msgTxt = msgTxt + "Process output: " + processStream + "\n";
+ if (process != null) {
+ String processStream = process.getStdOut();
+ if (!StringUtils.isBlank(processStream))
+ msgTxt = msgTxt + "Process output: " + processStream + "\n";
+ }
throw new AppiumServerHasNotBeenStartedLocallyException(msgTxt,
e);
diff --git a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java
index 3a9131d0e..91697db1c 100644
--- a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java
+++ b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java
@@ -19,9 +19,11 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.appium.java_client.service.local.flags.ServerArgument;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.InetAddressValidator;
import org.openqa.selenium.Platform;
+import org.openqa.selenium.os.CommandLine;
import org.openqa.selenium.remote.service.DriverService;
import java.io.*;
@@ -34,121 +36,98 @@
public final class AppiumServiceBuilder extends DriverService.Builder {
- private static final String NODE_MODULES_FOLDER = "node_modules";
+ public static final String APPIUM_NODE_PROPERTY = "appium.node.path";
+ public static final String APPIUM_NODE_JS_EXEC_PATH = "appium.node.js.exec.path";
+
private static final String APPIUM_FOLDER = "appium";
private static final String BIN_FOLDER = "bin";
private static final String APPIUM_JS = "appium.js";
private static final String APPIUM_NODE_MASK = File.separator +
APPIUM_FOLDER + File.separator + BIN_FOLDER + File.separator + APPIUM_JS;
- public static final String APPIUM_NODE_PROPERTY = "appium.node.path";
public static final String DEFAULT_LOCAL_IP_ADDRESS = "0.0.0.0";
private static final int DEFAULT_APPIUM_PORT = 4723;
-
- private static final String NODE_COMMAND_PREFIX = defineNodeCommandPrefix();
-
- private final static String COMMAND_WHICH_EXTRACTS_DEFAULT_PATH_TO_APPIUM = NODE_COMMAND_PREFIX +
- " npm -g ls --depth=0";
- private final static String COMMAND_WHICH_EXTRACTS_DEFAULT_PATH_TO_APPIUM_WIN = NODE_COMMAND_PREFIX +
- " npm.cmd -g ls --depth=0";
-
- private static final int REQUIRED_MAJOR_NODE_JS = 0;
- private static final int REQUIRED_MINOR_NODE_JS = 0;
-
+ private final static String BASH = "bash";
+ private final static String CMD_EXE = "cmd.exe";
+ private final static String NODE = "node";
final Map serverArguments = new HashMap<>();
private File appiumJS;
private String ipAddress = DEFAULT_LOCAL_IP_ADDRESS;
+ private File npmScript;
+ private File getNodeJSExecutable;
//The first starting is slow sometimes on some
//environment
private long startupTimeout = 120;
private TimeUnit timeUnit = TimeUnit.SECONDS;
+ private void setUpNPMScript(){
+ if (npmScript != null) {
+ return;
+ }
- private static String returnCommandThatSearchesForDefaultNode(){
- if (Platform.getCurrent().is(Platform.WINDOWS))
- return COMMAND_WHICH_EXTRACTS_DEFAULT_PATH_TO_APPIUM_WIN;
- return COMMAND_WHICH_EXTRACTS_DEFAULT_PATH_TO_APPIUM;
- }
-
- private static String getProcessOutput(InputStream stream ) throws IOException {
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(stream));
- String result = reader.readLine();
- reader.close();
- return result;
+ if (!Platform.getCurrent().is(Platform.WINDOWS)) {
+ npmScript = Scripts.GET_PATH_TO_DEFAULT_NODE_UNIX.getScriptFile();
+ }
}
- private static void validateNodeJSVersion(){
- Runtime rt = Runtime.getRuntime();
- String result = null;
- Process p = null;
- try {
- p = rt.exec(NODE_COMMAND_PREFIX + " node -v");
- p.waitFor();
- result = getProcessOutput(p.getInputStream());
- } catch (Exception e) {
- throw new InvalidNodeJSInstance("Node.js is not installed", e);
- }
- finally {
- if (p != null)
- p.destroy();
+ private void setUpGetNodeJSExecutableScript() {
+ if (getNodeJSExecutable != null) {
+ return;
}
- String versionNum = result.replace("v","");
- String[] tokens = versionNum.split("\\.");
- if (Integer.parseInt(tokens[0]) < REQUIRED_MAJOR_NODE_JS ||
- Integer.parseInt(tokens[1]) < REQUIRED_MINOR_NODE_JS)
- throw new InvalidNodeJSInstance("Current node.js version " + versionNum + "is lower than " +
- "required (" + REQUIRED_MAJOR_NODE_JS + "." + REQUIRED_MINOR_NODE_JS + " or greater)");
+ getNodeJSExecutable = Scripts.GET_NODE_JS_EXECUTABLE.getScriptFile();
}
- private static File findNodeInCurrentFileSystem(){
- Runtime rt = Runtime.getRuntime();
+ private File findNodeInCurrentFileSystem(){
+ setUpNPMScript();
+
String instancePath;
- Process p = null;
+ CommandLine commandLine;
try {
- p = rt.exec(returnCommandThatSearchesForDefaultNode());
- p.waitFor();
- instancePath = getProcessOutput(p.getInputStream());
- } catch (Exception e) {
+ if (Platform.getCurrent().is(Platform.WINDOWS)) {
+ commandLine = new CommandLine(CMD_EXE, "/C", "npm root -g");
+ }
+ else {
+ commandLine = new CommandLine(BASH, "-l", npmScript.getAbsolutePath());
+ }
+ commandLine.execute();
+ } catch (Throwable e) {
throw new RuntimeException(e);
}
+
+ instancePath = (commandLine.getStdOut()).trim();
+ try {
+ File result;
+ if (StringUtils.isBlank(instancePath) || !(result = new File(instancePath + File.separator +
+ APPIUM_NODE_MASK)).exists()) {
+ String errorOutput = commandLine.getStdOut();
+ throw new InvalidServerInstanceException("There is no installed nodes! Please install " +
+ " node via NPM (https://www.npmjs.com/package/appium#using-node-js) or download and " +
+ "install Appium app (http://appium.io/downloads.html)",
+ new IOException(errorOutput));
+ }
+ return result;
+ }
finally {
- if (p != null)
- p.destroy();
+ commandLine.destroy();
}
-
- File result;
- if (StringUtils.isBlank(instancePath) || !(result = new File(instancePath + File.separator + NODE_MODULES_FOLDER +
- APPIUM_NODE_MASK)).exists())
- throw new InvalidServerInstanceException( "There is no installed nodes! Please install " +
- " node via NPM (https://www.npmjs.com/package/appium#using-node-js) or download and " +
- "install Appium app (http://appium.io/downloads.html)",
- new IOException("The installed appium node package has not been found."));
-
- return result;
}
private static void validateNodeStructure(File node){
String absoluteNodePath = node.getAbsolutePath();
- if (!node.exists())
+ if (!node.exists()) {
throw new InvalidServerInstanceException("The invalid appium node " + absoluteNodePath + " has been defined",
new IOException("The node " + absoluteNodePath + "doesn't exist"));
+ }
- if (!absoluteNodePath.endsWith(APPIUM_NODE_MASK))
+ if (!absoluteNodePath.endsWith(APPIUM_NODE_MASK)) {
throw new InvalidServerInstanceException("It is probably there is the corrupted appium server installation. Path " +
absoluteNodePath + "doesn't match " + APPIUM_NODE_MASK);
- }
-
- private static String defineNodeCommandPrefix() {
- if (Platform.getCurrent().is(Platform.WINDOWS))
- return "cmd.exe /C";
- else
- return "/bin/bash -l -c";
+ }
}
public AppiumServiceBuilder() {
@@ -157,28 +136,45 @@ public AppiumServiceBuilder() {
@Override
protected File findDefaultExecutable() {
- validateNodeJSVersion();
- Runtime rt = Runtime.getRuntime();
- Process p;
- try {
- p = rt.exec(NODE_COMMAND_PREFIX + " node");
- } catch (IOException e) {
- throw new RuntimeException(e);
+
+ String nodeJSExec = System.getProperty(APPIUM_NODE_JS_EXEC_PATH);
+ if (StringUtils.isBlank(nodeJSExec)) {
+ nodeJSExec = System.getenv(APPIUM_NODE_JS_EXEC_PATH);
+ }
+ if (!StringUtils.isBlank(nodeJSExec)) {
+ File result = new File(nodeJSExec);
+ if (result.exists()) {
+ return result;
+ }
}
+ CommandLine commandLine;
+ setUpGetNodeJSExecutableScript();
try {
- OutputStream outputStream = p.getOutputStream();
- PrintStream out = new PrintStream(outputStream) ;
- out.println("console.log(process.execPath);") ;
- out.close();
-
- return new File(getProcessOutput(p.getInputStream()));
+ if (Platform.getCurrent().is(Platform.WINDOWS)) {
+ commandLine = new CommandLine(NODE + ".exe", getNodeJSExecutable.getAbsolutePath());
+ }
+ else {
+ commandLine = new CommandLine(NODE, getNodeJSExecutable.getAbsolutePath());
+ }
+ commandLine.execute();
+ } catch (Throwable t) {
+ throw new InvalidNodeJSInstance("Node.js is not installed!", t);
}
- catch (Throwable t){
- throw new RuntimeException(t);
+
+
+ String filePath = (commandLine.getStdOut()).trim();
+
+ try {
+ if (StringUtils.isBlank(filePath) || !new File(filePath).exists()) {
+ String errorOutput = commandLine.getStdOut();
+ String errorMessage = "Can't get a path to the default Node.js instance";
+ throw new InvalidNodeJSInstance(errorMessage, new IOException(errorOutput));
+ }
+ return new File(filePath);
}
finally {
- p.destroy();
+ commandLine.destroy();
}
}
@@ -217,6 +213,11 @@ public AppiumServiceBuilder withIPAddress(String ipAddress){
return this;
}
+ /**
+ * @param time a time value for the service starting up
+ * @param timeUnit a time unit for the service starting up
+ * @return self-reference
+ */
public AppiumServiceBuilder withStartUpTimeOut(long time, TimeUnit timeUnit){
checkNotNull(timeUnit);
checkArgument(time > 0, "Time value should be greater than zero", time);
@@ -233,7 +234,10 @@ void checkAppiumJS(){
}
String appiumJS = System.getProperty(APPIUM_NODE_PROPERTY);
- if (appiumJS !=null){
+ if (StringUtils.isBlank(appiumJS)) {
+ appiumJS = System.getenv(APPIUM_NODE_PROPERTY);
+ }
+ if (!StringUtils.isBlank(appiumJS)){
File node = new File(appiumJS);
validateNodeStructure(node);
this.appiumJS = node;
@@ -251,8 +255,9 @@ protected ImmutableList createArgs() {
argList.add("--port");
argList.add(String.valueOf(getPort()));
- if (StringUtils.isBlank(ipAddress))
+ if (StringUtils.isBlank(ipAddress)) {
ipAddress = DEFAULT_LOCAL_IP_ADDRESS;
+ }
else {
InetAddressValidator validator = InetAddressValidator.getInstance();
if (!validator.isValid(ipAddress) && !validator.isValidInet4Address(ipAddress) &&
@@ -269,9 +274,7 @@ protected ImmutableList createArgs() {
}
Set> entries = serverArguments.entrySet();
- Iterator> iterator = entries.iterator();
- while (iterator.hasNext()){
- Map.Entry entry = iterator.next();
+ for (Map.Entry entry : entries) {
String argument = entry.getKey();
String value = entry.getValue();
if (StringUtils.isBlank(argument) || value == null)
@@ -282,8 +285,7 @@ protected ImmutableList createArgs() {
argList.add(value);
}
- ImmutableList result = new ImmutableList.Builder().addAll(argList).build();
- return result;
+ return new ImmutableList.Builder().addAll(argList).build();
}
/**
@@ -348,4 +350,20 @@ protected AppiumDriverLocalService createDriverService(File nodeJSExecutable, in
throw new RuntimeException(e);
}
}
-}
+
+ private static void disposeCachedFile(File file) {
+ if (file != null) {
+ try {
+ FileUtils.forceDelete(file);
+ } catch (IOException ignored) {
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ disposeCachedFile(npmScript);
+ disposeCachedFile(getNodeJSExecutable);
+ super.finalize();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/appium/java_client/service/local/InvalidNodeJSInstance.java b/src/main/java/io/appium/java_client/service/local/InvalidNodeJSInstance.java
index 1b3ed3fcb..c38734fdd 100644
--- a/src/main/java/io/appium/java_client/service/local/InvalidNodeJSInstance.java
+++ b/src/main/java/io/appium/java_client/service/local/InvalidNodeJSInstance.java
@@ -17,10 +17,6 @@
package io.appium.java_client.service.local;
public class InvalidNodeJSInstance extends RuntimeException{
- public InvalidNodeJSInstance(String message){
- super(message);
- }
-
public InvalidNodeJSInstance(String message, Throwable t){
super(message, t);
}
diff --git a/src/main/java/io/appium/java_client/service/local/Scripts.java b/src/main/java/io/appium/java_client/service/local/Scripts.java
new file mode 100644
index 000000000..21376eea6
--- /dev/null
+++ b/src/main/java/io/appium/java_client/service/local/Scripts.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.appium.java_client.service.local;
+
+import org.apache.commons.io.IOUtils;
+import java.io.*;
+
+enum Scripts {
+ GET_PATH_TO_DEFAULT_NODE_UNIX("get_path_to_default_node.sh"),
+ GET_NODE_JS_EXECUTABLE("getExe.js")
+ ;
+ private static final String RESOURCE_FOLDER = "/scripts/";
+ private final String script;
+
+ Scripts(String script) {
+ this.script = script;
+ }
+
+ public File getScriptFile() {
+ InputStream inputStream = getClass().getResourceAsStream(RESOURCE_FOLDER + this.script);
+ byte[] bytes;
+ try {
+ bytes = IOUtils.toByteArray(inputStream);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ String[] splittedName = this.script.split("\\.");
+ File scriptFile;
+ try {
+ scriptFile = File.createTempFile(splittedName[0], "." + splittedName[1]);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ if (!scriptFile.exists()) {
+ try {
+ scriptFile.createNewFile();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ FileOutputStream output;
+ try {
+ output = new FileOutputStream(scriptFile, true);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+
+ try {
+ output.write(bytes);
+ output.flush();
+ output.close();
+ return scriptFile;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+}
diff --git a/src/main/resources/scripts/getExe.js b/src/main/resources/scripts/getExe.js
new file mode 100644
index 000000000..15cfdb975
--- /dev/null
+++ b/src/main/resources/scripts/getExe.js
@@ -0,0 +1 @@
+console.log(process.execPath);
\ No newline at end of file
diff --git a/src/main/resources/scripts/get_path_to_default_node.sh b/src/main/resources/scripts/get_path_to_default_node.sh
new file mode 100644
index 000000000..fce4693ea
--- /dev/null
+++ b/src/main/resources/scripts/get_path_to_default_node.sh
@@ -0,0 +1,4 @@
+#!bin/sh
+OUTPUT="$(npm root -g)"
+echo "${OUTPUT}"
+exit
\ No newline at end of file
diff --git a/src/test/java/io/appium/java_client/android/AndroidGestureTest.java b/src/test/java/io/appium/java_client/android/AndroidGestureTest.java
index 3714902be..1e2b6a93c 100644
--- a/src/test/java/io/appium/java_client/android/AndroidGestureTest.java
+++ b/src/test/java/io/appium/java_client/android/AndroidGestureTest.java
@@ -87,7 +87,7 @@ public void dragNDropTest() {
driver.findElementByAccessibilityId("Views").click();
driver.findElement(MobileBy.AndroidUIAutomator("description(\"Drag and Drop\")")).click();
- WebElement actionBarTitle = driver.findElement(By.id("android:id/action_bar_title"));
+ WebElement actionBarTitle = driver.findElement(MobileBy.AndroidUIAutomator("text(\"Views/Drag and Drop\")"));
assertEquals("Wrong title.", "Views/Drag and Drop", actionBarTitle.getText());
WebElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java
index 08c3bdd50..14b8a3b8b 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java
@@ -45,108 +45,21 @@
public class DesktopBrowserCompatibilityTest {
- private static enum AvailableDrivers {
- FIREFOX(FirefoxDriver.class, new ArrayList() {
- private static final long serialVersionUID = 1L;
- {
- add(Platform.WINDOWS);
- add(Platform.MAC);
- }
- }, new HashMap(), null),
-
- CHROME(ChromeDriver.class,
- new ArrayList() {
- private static final long serialVersionUID = 1L;
- {
- add(Platform.WINDOWS);
- add(Platform.MAC);
- }
-
- }, new HashMap() {
- private static final long serialVersionUID = 1L;
-
- {
- put(Platform.WINDOWS,
- new File(
- "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe"));
- put(Platform.MAC,
- new File(
- "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver"));
- }
- }, ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY),
- SAFARI(
- SafariDriver.class, new ArrayList() {
- private static final long serialVersionUID = 1L;
- {
- add(Platform.MAC);
- }
-
- }, new HashMap(), null);
- // TODO Linux can be added if is necessary
-
- private final Class extends WebDriver> driverClazz;
- private final List platformCompatible;
- private final Map serviceBinaries;
- private final String propertyName;
-
- private AvailableDrivers(Class extends WebDriver> driverClazz,
- List platformCompatible,
- Map serviceBinaries, String property) {
- this.driverClazz = driverClazz;
- this.platformCompatible = platformCompatible;
- this.serviceBinaries = serviceBinaries;
- this.propertyName = property;
+ public void setUp() {
+ if (current.is(Platform.WINDOWS)) {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe");
}
-
- private static AvailableDrivers getAvailableDriver(
- Class extends WebDriver> driverClass, Platform p) {
- AvailableDrivers[] availableDrivers = AvailableDrivers.values();
- for (AvailableDrivers availableDriver : availableDrivers) {
- if (!availableDriver.driverClazz.equals(driverClass)){
- continue;
- }
-
- for (Platform compatible: availableDriver.platformCompatible){
- if (p.is(compatible)){
- return availableDriver;
- }
- }
- }
- return null;
- }
-
- private void setSystemProperty(Platform p) {
- Platform platform = null;
- for (Platform compatible: platformCompatible){
- if (p.is(compatible)){
- platform = compatible;
- break;
- }
- }
-
- if ((platform != null) && (propertyName != null)
- && (serviceBinaries.get(platform) != null)) {
- System.setProperty(propertyName, serviceBinaries.get(platform)
- .getAbsolutePath());
- }
- }
- }
-
-
- public void setUp(Class extends WebDriver> driverClass) {
- AvailableDrivers availableDriver = AvailableDrivers.getAvailableDriver(driverClass, current);
- if (availableDriver != null){
- availableDriver.setSystemProperty(current);
+ else {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver");
}
}
private final Platform current = Platform.getCurrent();
private final long IMPLICITLY_WAIT = 15;
-
-
-
@AndroidFindBy(className = "someClass")
@iOSFindBys({
@iOSFindBy(xpath = "//selector[1]"),
@@ -159,7 +72,8 @@ public void setUp(Class extends WebDriver> driverClass) {
private WebDriver trap1;
private List> trap2;
- private void test(WebDriver driver){
+ private void test(){
+ WebDriver driver = new ChromeDriver();
try {
PageFactory.initElements(new AppiumFieldDecorator(driver, IMPLICITLY_WAIT, TimeUnit.SECONDS), this);
driver.get("file:///" + new File("src/test/java/io/appium/java_client/hello appium - saved page.htm").getAbsolutePath());
@@ -172,29 +86,9 @@ private void test(WebDriver driver){
}
}
- @Test
- public void fireFoxTest() {
- if (AvailableDrivers.getAvailableDriver(FirefoxDriver.class, current)!=null){
- setUp(FirefoxDriver.class);
- test(new FirefoxDriver());
- }
- }
-
@Test
public void chromeTest() {
- System.getProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
- if (AvailableDrivers.getAvailableDriver(ChromeDriver.class, current)!=null){
- setUp(ChromeDriver.class);
- test(new ChromeDriver());
- }
+ setUp();
+ test();
}
-
- @Test
- public void safariTest() {
- if (AvailableDrivers.getAvailableDriver(SafariDriver.class, current)!=null){
- setUp(SafariDriver.class);
- test(new SafariDriver());
- }
- }
-
}
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/TimeOutResetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/TimeOutResetTest.java
index c560aa6e9..641bc451f 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/TimeOutResetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/TimeOutResetTest.java
@@ -23,9 +23,11 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
-import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.support.FindAll;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
@@ -52,7 +54,15 @@ public class TimeOutResetTest {
@Before
public void setUp() throws Exception {
- driver = new FirefoxDriver();
+ if (Platform.getCurrent().is(Platform.WINDOWS)) {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe");
+ }
+ else {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver");
+ }
+ driver = new ChromeDriver();
timeOutDuration = new TimeOutDuration(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT,
AppiumFieldDecorator.DEFAULT_TIMEUNIT);
PageFactory.initElements(new AppiumFieldDecorator(driver, timeOutDuration), this);
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/HtmlOverrideWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/HtmlOverrideWidgetTest.java
index 1c146807a..04c49f462 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/HtmlOverrideWidgetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/HtmlOverrideWidgetTest.java
@@ -2,13 +2,16 @@
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.pagefactory.TimeOutDuration;
+import io.appium.java_client.pagefactory_tests.widgets.html.RottenTomatoesSite;
import org.apache.commons.lang3.StringUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.NoSuchElementException;
-import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.Platform;
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.support.PageFactory;
import java.io.File;
@@ -19,14 +22,23 @@
public class HtmlOverrideWidgetTest implements WidgetTest{
- private static FirefoxDriver driver;
+ private static ChromeDriver driver;
private static RottenTomatoes rottenTomatoes;
@BeforeClass
public static void beforeClass() throws Exception {
- driver = new FirefoxDriver();
- driver.get("file:///" + new File("src/test/java/io/appium/java_client/RottenTomatoesSnapshot.html").getAbsolutePath());
+ if (Platform.getCurrent().is(Platform.WINDOWS)) {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe");
+ }
+ else {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver");
+ }
+
+ driver = new ChromeDriver();
+ driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
rottenTomatoes = new RottenTomatoes();
PageFactory.initElements(new AppiumFieldDecorator(driver, new TimeOutDuration(5, TimeUnit.SECONDS)), rottenTomatoes);
}
@@ -34,7 +46,7 @@ public static void beforeClass() throws Exception {
@Before
public void setUp() throws Exception {
if (driver != null)
- driver.navigate().back();
+ driver.get("file:///" + new File("src/test/java/io/appium/java_client/RottenTomatoesSnapshot.html").getAbsolutePath());
}
@AfterClass
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/HtmlCombinedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/HtmlCombinedWidgetTest.java
index e0557fad1..34e5b0c78 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/HtmlCombinedWidgetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/HtmlCombinedWidgetTest.java
@@ -10,7 +10,9 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.NoSuchElementException;
-import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.Platform;
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.support.PageFactory;
import java.io.File;
@@ -21,14 +23,23 @@
public class HtmlCombinedWidgetTest implements WidgetTest{
- private static FirefoxDriver driver;
+ private static ChromeDriver driver;
private static RottenTomatoesAppWithCombinedWidgets rottenTomatoes;
@BeforeClass
public static void beforeClass() throws Exception {
- driver = new FirefoxDriver();
- driver.get("file:///" + new File("src/test/java/io/appium/java_client/RottenTomatoesSnapshot.html").getAbsolutePath());
+ if (Platform.getCurrent().is(Platform.WINDOWS)) {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe");
+ }
+ else {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver");
+ }
+
+ driver = new ChromeDriver();
+ driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
rottenTomatoes = new RottenTomatoesAppWithCombinedWidgets();
PageFactory.initElements(new AppiumFieldDecorator(driver, new TimeOutDuration(5, TimeUnit.SECONDS)), rottenTomatoes);
}
@@ -36,7 +47,7 @@ public static void beforeClass() throws Exception {
@Before
public void setUp() throws Exception {
if (driver != null)
- driver.navigate().back();
+ driver.get("file:///" + new File("src/test/java/io/appium/java_client/RottenTomatoesSnapshot.html").getAbsolutePath());
}
@AfterClass
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/html/HtmlWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/html/HtmlWidgetTest.java
index efac13ec1..eeb1d9352 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/html/HtmlWidgetTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/html/HtmlWidgetTest.java
@@ -4,13 +4,16 @@
import io.appium.java_client.pagefactory.TimeOutDuration;
import io.appium.java_client.pagefactory_tests.widgets.Movie;
import io.appium.java_client.pagefactory_tests.widgets.WidgetTest;
+import io.appium.java_client.pagefactory_tests.widgets.combined.RottenTomatoesAppWithCombinedWidgets;
import org.apache.commons.lang3.StringUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.NoSuchElementException;
-import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.Platform;
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.support.PageFactory;
import java.io.File;
@@ -21,14 +24,23 @@
public class HtmlWidgetTest implements WidgetTest{
- private static FirefoxDriver driver;
+ private static ChromeDriver driver;
private static RottenTomatoesSite rottenTomatoesSite;
@BeforeClass
public static void beforeClass() throws Exception {
- driver = new FirefoxDriver();
- driver.get("file:///" + new File("src/test/java/io/appium/java_client/RottenTomatoesSnapshot.html").getAbsolutePath());
+ if (Platform.getCurrent().is(Platform.WINDOWS)) {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver.exe");
+ }
+ else {
+ System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
+ "src/test/java/io/appium/java_client/pagefactory_tests/chromedriver");
+ }
+
+ driver = new ChromeDriver();
+ driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
rottenTomatoesSite = new RottenTomatoesSite();
PageFactory.initElements(new AppiumFieldDecorator(driver, new TimeOutDuration(5, TimeUnit.SECONDS)), rottenTomatoesSite);
}
@@ -36,7 +48,7 @@ public static void beforeClass() throws Exception {
@Before
public void setUp() throws Exception {
if (driver != null)
- driver.navigate().back();
+ driver.get("file:///" + new File("src/test/java/io/appium/java_client/RottenTomatoesSnapshot.html").getAbsolutePath());
}
@AfterClass