8000 ChromeDriverBuilder#withPathToChromeDriverExe() ->#withPathToChromeDr… · seleniumQuery/seleniumQuery@a2a0b5f · GitHub
[go: up one dir, main page]

Skip to content

Commit a2a0b5f

Browse files
committed
ChromeDriverBuilder#withPathToChromeDriverExe() ->#withPathToChromeDriver() - see #81
1 parent e93d956 commit a2a0b5f

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

src/main/java/io/github/seleniumquery/browser/BrowserFunctionsWithDeprecatedFunctions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public class OldBrowserFunctions {
6464
* @return A self reference. */
6565
public OldBrowserFunctions setDefaultDriverAsChrome() { browser.driver().useChrome(); return this; }
6666

67-
/** @deprecated Use: <code>$.driver().useChrome().withPathToChromeDriverExe(path);</code>
68-
* @param path path to chromedriver.exe.
67+
/** @deprecated Use: <code>$.driver().useChrome().withPathToChromeDriver(path);</code>
68+
* @param path path to ChromeDriver executable (<code>chromedriver.exe</code>/<code>chromedriver</code>).
6969
* @return A self reference. */
70-
public OldBrowserFunctions setDefaultDriverAsChrome(String path) { browser.driver().useChrome().withPathToChromeDriverExe(path); return this; }
70+
public OldBrowserFunctions setDefaultDriverAsChrome(String path) { browser.driver().useChrome().withPathToChromeDriver(path); return this; }
7171

7272
/** @deprecated Use: <code>$.driver().useInternetExplorer();</code>
7373
* @return A self reference. */

src/main/java/io/github/seleniumquery/browser/driver/SeleniumQueryDriver.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,20 @@ public FirefoxDriverBuilder useFirefox() {
105105
/**
106106
* Sets {@link org.openqa.selenium.chrome.ChromeDriver} as the {@link WebDriver} for this seleniumQuery browser instance.
107107
* <p>
108-
* Note that the Chrome driver needs a <i>server executable</i> to bridge Selenium to the browser and as such
109-
* Selenium must know the path to it. It is a file usually named <code>chromedriver.exe</code> and its latest
110-
* version can be downloaded from
111-
* <a href="http://chromedriver.storage.googleapis.com/index.html">ChromeDriver's download page</a> -- or check
108+
* Note that the Chrome needs a <i>ChromeDriver Server executable</i> to bridge Selenium to the browser and as such
109+
* Selenium must know the path to it. It is a file usually named <code>chromedriver.exe</code> (windows) or <code>chromedriver</code> (linix)
110+
* and its latest version can be downloaded from
111+
* <a href="http://chromedriver.storage.googleapis.com/index.html">ChromeDriver's download page</a>. You can also check
112112
* <a href="https://github.com/seleniumQuery/seleniumQuery/wiki/seleniumQuery-and-Chrome-Driver">seleniumQuery and Chrome Driver wiki page</a>
113-
* for the latest info.
113+
* for the other info.
114114
* </p>
115115
* <br>
116-
* <b> This method looks for the <code>chromedriver.exe</code> at the CLASSPATH (tipically at a {@code resources/} folder of a
117-
* maven project), at the "webdriver.chrome.driver" system property or at the system's PATH variable.</b>
116+
* <b> This method looks for the ChromeDriver executable (<code>chromedriver.exe</code>/<code>chromedriver</code>) at the CLASSPATH
117+
* (tipically at a {@code resources/} folder of a maven project), at the "webdriver.chrome.driver" system property or at the system's PATH variable.</b>
118118
* If you wish to directly specify a path, use:
119119
* <pre>
120-
* $.driver().useChrome().withPathToChromeDriverExe("other/path/to/chromedriver.exe");
120+
* $.driver().useChrome().withPathToChromeDriver("other/path/to/chromedriver.exe"); // windows
121+
* $.driver().useChrome().withPathToChromeDriver("other/path/to/chromedriver"); // linux
121122
* </pre>
122123
*
123124
* @return A {@link ChromeDriverBuilder}, allowing further configuration of the driver.

src/main/java/io/github/seleniumquery/browser/driver/builders/ChromeDriverBuilder.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ public class ChromeDriverBuilder extends DriverBuilder<ChromeDriverBuilder> {
2727
"(1) on the classpath of this project; or\n" +
2828
"(2) on the path specified by the \"" + CHROME_DRIVER_EXECUTABLE_SYSTEM_PROPERTY + "\" system property; or\n" +
2929
"(3) on a folder in the system's PATH variable; or\n" +
30-
"(4) wherever and set the path via $.driver().useChrome().withPathToChromeDriverExe(\"other/path/to/chromedriver.exe\").\n" +
30+
"(4) wherever and set the path via $.driver().useChrome().withPathToChromeDriver(\"other/path/to/chromedriver<.exe>\").\n" +
3131
"For more information, see https://github.com/seleniumQuery/seleniumQuery/wiki/seleniumQuery-and-Chrome-Driver";
3232

3333
private static final String BAD_PATH_PROVIDED_EXCEPTION_MESSAGE = "The ChromeDriver Server executable file was not found (or is a directory) at \"%s\"." + EXCEPTION_MESSAGE;
3434

3535
static String CHROMEDRIVER_EXE = "chromedriver.exe"; // package visibility so it can be changed during test
3636

3737

38-
private String customPathToChromeDriverExe;
38+
private String customPathToChromeDriver;
3939
private ChromeOptions chromeOptions;
4040

4141
/**
4242
* Sets specific {@link ChromeOptions} options to be used in the {@link ChromeDriver}.
43+
*
4344
* @param chromeOptions Options to be used.
4445
* @return A self reference, allowing further configuration.
4546
*
@@ -51,18 +52,19 @@ public ChromeDriverBuilder withOptions(ChromeOptions chromeOptions) {
5152
}
5253

5354
/**
54-
* Configures the builder to look for the <code>chromedriver.exe</code> at the path specified by the argument.
55+
* Configures the builder to look for the ChromeDriver executable (<code>chromedriver.exe</code>/<code>chromedriver</code>) at
56+
* the specified path.
5557
*
56-
* @param pathToChromeDriverExe The path to the executable server file. Examples:
57-
* <code>"C:\\myFiles\\chromedriver.exe"</code>; can be relative, as in <code>"..\\stuff\\chromedriver.exe"</code>;
58-
* does not matter if the executable was renamed, such as <code>"drivers\\chrome\\chromedriver_v12345.exe"</code>.
58+
* @param pathToChromeDriver The path to the executable server file. Examples:
59+
* <code>"C:\myFiles\chromedriver.exe"</code>; can be relative, as in <code>"..\stuff\chromedriver"</code>;
60+
* does not matter if the executable was renamed, such as <code>"wherever/myself/drivers/chromedriver_v12345.exe"</code>.
5961
*
6062
* @return A self reference, allowing further configuration.
6163
*
6264
* @since 0.9.0
6365
*/
64-
public ChromeDriverBuilder withPathToChromeDriverExe(String pathToChromeDriverExe) {
65-
this.customPathToChromeDriverExe = pathToChromeDriverExe;
66+
public ChromeDriverBuilder withPathToChromeDriver(String pathToChromeDriver) {
67+
this.customPathToChromeDriver = pathToChromeDriver;
6668
return this;
6769
}
6870

@@ -71,8 +73,8 @@ protected WebDriver build() {
7173
DesiredCapabilities capabilities = capabilities(DesiredCapabilities.chrome());
7274
overwriteCapabilityIfValueNotNull(capabilities, ChromeOptions.CAPABILITY, this.chromeOptions);
7375

74-
if (customPathWasProvidedAndExecutableExistsThere(this.customPathToChromeDriverExe, BAD_PATH_PROVIDED_EXCEPTION_MESSAGE)) {
75-
System.setProperty(CHROME_DRIVER_EXECUTABLE_SYSTEM_PROPERTY, getFullPath(this.customPathToChromeDriverExe));
76+
if (customPathWasProvidedAndExecutableExistsThere(this.customPathToChromeDriver, BAD_PATH_PROVIDED_EXCEPTION_MESSAGE)) {
77+
System.setProperty(CHROME_DRIVER_EXECUTABLE_SYSTEM_PROPERTY, getFullPath(this.customPathToChromeDriver));
7678
} else if (executableExistsInClasspath(CHROMEDRIVER_EXE)) {
7779
System.setProperty(CHROME_DRIVER_EXECUTABLE_SYSTEM_PROPERTY, getFullPathForFileInClasspath(CHROMEDRIVER_EXE));
7880
}

src/test/java/io/github/seleniumquery/browser/driver/builders/ChromeDriverBuilderTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.seleniumquery.browser.driver.builders;
22

33
import org.junit.After;
4+
import org.junit.Before;
45
import org.junit.Test;
56
import org.openqa.selenium.chrome.ChromeOptions;
67
import org.openqa.selenium.remote.DesiredCapabilities;
@@ -13,6 +14,13 @@
1314

1415
public class ChromeDriverBuilderTest {
1516

17+
String chromeExecutable = ChromeDriverBuilder.CHROMEDRIVER_EXE;
18+
19+
@Before
20+
public void setUp() throws Exception {
21+
System.out.println("OS: "+System.getProperty("os.name"));
22+
}
23+
1624
@After
1725
public void tearDown() throws Exception {
1826
$.quit();
@@ -50,9 +58,9 @@ public void withCapabilities__should_return_the_current_ChromeDriverBuilder_inst
5058
}
5159

5260
@Test
53-
public void withPathToChromeDriverExe() {
61+
public void withPathToChromeDriver() {
5462
// given
55-
$.driver().useChrome().withPathToChromeDriverExe("src/test/resources/chromedriver.exe");
63+
$.driver().useChrome().withPathToChromeDriver("src/test/resources/"+chromeExecutable);
5664
// when
5765
$.url(classNameToTestFileUrl(ChromeDriverBuilderTest.class));
5866
// then
@@ -62,8 +70,8 @@ public void withPathToChromeDriverExe() {
6270
@Test
6371
public void useChrome__should_fall_back_to_systemProperty_when_executable_not_found_in_classpath() {
6472
// given
65-
ChromeDriverBuilder.CHROMEDRIVER_EXE = "not-in-classpath.exe";
66-
System.setProperty("webdriver.chrome.driver", getFullPathForFileInClasspath("chromedriver.exe"));
73+
ChromeDriverBuilder.CHROMEDRIVER_EXE = "not-in-classpath.txt";
74+
System.setProperty("webdriver.chrome.driver", getFullPathForFileInClasspath(chromeExecutable));
6775
// when
6876
$.driver().useChrome();
6977
$.url(classNameToTestFileUrl(ChromeDriverBuilderTest.class));

0 commit comments

Comments
 (0)
0