Skip to content

Commit 0c6a867

Browse files
authored
Find/verify driver executable path, populate property (#221)
1 parent 4c5f488 commit 0c6a867

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.nordstrom.automation.selenium.exceptions;
2+
3+
public class DriverExecutableNotFoundException extends RuntimeException {
4+
5+
private static final long serialVersionUID = -5718589545720652315L;
6+
7+
private static final String PATH_DEFINED = "Driver executable neither found at '%s' (specified by [%s]) nor on the PATH";
8+
private static final String PATH_OMITTED = "Driver executable not found on the PATH; add it or specify location in [%s]";
9+
10+
public DriverExecutableNotFoundException(String driverPathProp) {
11+
super(getMessage(driverPathProp));
12+
}
13+
14+
private static String getMessage(final String driverPathProp) {
15+
String driverPath = System.getProperty(driverPathProp);
16+
if (driverPath != null) {
17+
return String.format(PATH_DEFINED, driverPath, driverPathProp);
18+
} else {
19+
return String.format(PATH_OMITTED, driverPathProp);
20+
}
21+
}
22+
23+
}

src/main/java/com/nordstrom/automation/selenium/plugins/ChromeCaps.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.nordstrom.automation.selenium.plugins;
22

3+
import java.io.File;
34
import java.util.Collections;
45
import java.util.HashMap;
56
import java.util.Map;
7+
import com.nordstrom.automation.selenium.exceptions.DriverExecutableNotFoundException;
8+
import com.nordstrom.automation.selenium.utility.BinaryFinder;
69

710
public class ChromeCaps {
811

@@ -57,6 +60,12 @@ public static Map<String, String> getPersonalities() {
5760
}
5861

5962
public static String[] getPropertyNames() {
63+
try {
64+
File driverPath = BinaryFinder.findBinary("chromedriver", DRIVER_PATH, null, null);
65+
System.setProperty(DRIVER_PATH, driverPath.getAbsolutePath());
66+
} catch (IllegalStateException e) {
67+
throw new DriverExecutableNotFoundException(DRIVER_PATH);
68+
}
6069
return PROPERTY_NAMES;
6170
}
6271

src/main/java/com/nordstrom/automation/selenium/plugins/EdgeCaps.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.nordstrom.automation.selenium.plugins;
22

3+
import java.io.File;
34
import java.util.Collections;
45
import java.util.HashMap;
56
import java.util.Map;
67

8+
import com.nordstrom.automation.selenium.exceptions.DriverExecutableNotFoundException;
9+
import com.nordstrom.automation.selenium.utility.BinaryFinder;
10+
711
public class EdgeCaps {
812

913
private EdgeCaps() {
@@ -52,6 +56,12 @@ public static Map<String, String> getPersonalities() {
5256
}
5357

5458
public static String[] getPropertyNames() {
59+
try {
60+
File driverPath = BinaryFinder.findBinary("msedgedriver", DRIVER_PATH, null, null);
61+
System.setProperty(DRIVER_PATH, driverPath.getAbsolutePath());
62+
} catch (IllegalStateException e) {
63+
throw new DriverExecutableNotFoundException(DRIVER_PATH);
64+
}
5565
return PROPERTY_NAMES;
5666
}
5767

src/main/java/com/nordstrom/automation/selenium/plugins/FirefoxCaps.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.nordstrom.automation.selenium.plugins;
22

3+
import java.io.File;
34
import java.util.Collections;
45
import java.util.HashMap;
56
import java.util.Map;
67

8+
import com.nordstrom.automation.selenium.exceptions.DriverExecutableNotFoundException;
9+
import com.nordstrom.automation.selenium.utility.BinaryFinder;
10+
711
public class FirefoxCaps {
812

913
private FirefoxCaps() {
@@ -50,6 +54,12 @@ public static Map<String, String> getPersonalities() {
5054
}
5155

5256
public static String[] getPropertyNames() {
57+
try {
58+
File driverPath = BinaryFinder.findBinary("geckodriver", DRIVER_PATH, null, null);
59+
System.setProperty(DRIVER_PATH, driverPath.getAbsolutePath());
60+
} catch (IllegalStateException e) {
61+
throw new DriverExecutableNotFoundException(DRIVER_PATH);
62+
}
5363
return PROPERTY_NAMES;
5464
}
5565

src/main/java/com/nordstrom/automation/selenium/plugins/OperaCaps.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.nordstrom.automation.selenium.plugins;
22

3+
import java.io.File;
34
import java.util.Collections;
45
import java.util.HashMap;
56
import java.util.Map;
67

8+
import com.nordstrom.automation.selenium.exceptions.DriverExecutableNotFoundException;
9+
import com.nordstrom.automation.selenium.utility.BinaryFinder;
10+
711
public class OperaCaps {
812

913
private OperaCaps() {
@@ -41,6 +45,12 @@ public static Map<String, String> getPersonalities() {
4145
}
4246

4347
public static String[] getPropertyNames() {
48+
try {
49+
File driverPath = BinaryFinder.findBinary("operadriver", DRIVER_PATH, null, null);
50+
System.setProperty(DRIVER_PATH, driverPath.getAbsolutePath());
51+
} catch (IllegalStateException e) {
52+
throw new DriverExecutableNotFoundException(DRIVER_PATH);
53+
}
4454
return PROPERTY_NAMES;
4555
}
4656

src/main/java/com/nordstrom/automation/selenium/plugins/SafariCaps.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.nordstrom.automation.selenium.plugins;
22

3+
import java.io.File;
34
import java.util.Collections;
45
import java.util.HashMap;
56
import java.util.Map;
67

8+
import com.nordstrom.automation.selenium.exceptions.DriverExecutableNotFoundException;
9+
import com.nordstrom.automation.selenium.utility.BinaryFinder;
10+
711
public class SafariCaps {
812

913
private SafariCaps() {
@@ -38,6 +42,12 @@ public static Map<String, String> getPersonalities() {
3842
}
3943

4044
public static String[] getPropertyNames() {
45+
try {
46+
File driverPath = BinaryFinder.findBinary("safaridriver", DRIVER_PATH, null, null);
47+
System.setProperty(DRIVER_PATH, driverPath.getAbsolutePath());
48+
} catch (IllegalStateException e) {
49+
throw new DriverExecutableNotFoundException(DRIVER_PATH);
50+
}
4151
return PROPERTY_NAMES;
4252
}
4353

0 commit comments

Comments
 (0)