Skip to content

Commit 4feb7ab

Browse files
committed
Improve logic to detect opera binary in test
1 parent e246811 commit 4feb7ab

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/test/java/io/github/bonigarcia/wdm/test/opera/OperaTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
*/
1717
package io.github.bonigarcia.wdm.test.opera;
1818

19+
import static java.nio.file.Files.exists;
1920
import static org.apache.commons.lang3.SystemUtils.IS_OS_MAC;
2021
import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS;
2122
import static org.junit.Assume.assumeTrue;
2223

23-
import java.io.File;
24+
import java.nio.file.Path;
25+
import java.nio.file.Paths;
2426

2527
import org.junit.Before;
2628
import org.junit.BeforeClass;
@@ -44,13 +46,23 @@ public static void setupClass() {
4446

4547
@Before
4648
public void setupTest() {
47-
String opera = IS_OS_WINDOWS
48-
? "C:\\Users\\boni\\AppData\\Local\\Programs\\Opera\\launcher.exe"
49-
: IS_OS_MAC ? "/Applications/Opera.app/Contents/MacOS/Opera"
50-
: "/usr/bin/opera";
51-
assumeTrue(new File(opera).exists());
49+
Path browserPath = getBrowserPath();
50+
assumeTrue(exists(browserPath));
5251

5352
driver = new OperaDriver();
5453
}
5554

55+
private Path getBrowserPath() {
56+
Path path;
57+
if (IS_OS_WINDOWS) {
58+
path = Paths.get(System.getenv("LOCALAPPDATA"),
59+
"/Programs/Opera/launcher.exe");
60+
} else if (IS_OS_MAC) {
61+
path = Paths.get("/Applications/Opera.app/Contents/MacOS/Opera");
62+
} else {
63+
path = Paths.get("/usr/bin/opera");
64+
}
65+
return path;
66+
}
67+
5668
}

0 commit comments

Comments
 (0)