forked from zaproxy/zap-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selenium: add support for Firefox 48+
Change ExtensionSelenium to use geckodriver/marionette, allowing to use newer versions of Firefox (>= 48). Change options to allow to specify the path to geckodriver. Backport GeckoDriverService to not require updating Selenium (which needs Java 8). Update help pages to mention the supported versions of Firefox, fix typos and add suggested workaround for PhantomJS. Bump version and update changes in ZapAddOn.xml file. Fix zaproxy/zaproxy#2743 - Unable to use Firefox 48+ with AJAX Spider
- Loading branch information
Showing
10 changed files
with
277 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
src/org/openqa/selenium/firefox/GeckoDriverService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. 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 org.openqa.selenium.firefox; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
import org.openqa.selenium.WebDriverException; | ||
import org.openqa.selenium.firefox.internal.Executable; | ||
import org.openqa.selenium.remote.service.DriverService; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.ConnectException; | ||
import java.net.InetSocketAddress; | ||
import java.net.MalformedURLException; | ||
import java.net.Socket; | ||
import java.net.SocketTimeoutException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Manages the life and death of an GeckoDriver aka 'wires'. | ||
*/ | ||
public class GeckoDriverService extends DriverService { | ||
|
||
/** | ||
* System property that defines the location of the GeckoDriver executable | ||
* that will be used by the {@link #createDefaultService() default service}. | ||
*/ | ||
public static final String GECKO_DRIVER_EXE_PROPERTY = "webdriver.gecko.driver"; | ||
|
||
/** | ||
* | ||
* @param executable The GeckoDriver executable. | ||
* @param port Which port to start the GeckoDriver on. | ||
* @param args The arguments to the launched server. | ||
* @param environment The environment for the launched server. | ||
* @throws IOException If an I/O error occurs. | ||
*/ | ||
public GeckoDriverService(File executable, int port, ImmutableList<String> args, | ||
ImmutableMap<String, String> environment) throws IOException { | ||
super(executable, port, args, environment); | ||
} | ||
|
||
/** | ||
* Configures and returns a new {@link GeckoDriverService} using the default configuration. In | ||
* this configuration, the service will use the GeckoDriver executable identified by the | ||
* {@link #GECKO_DRIVER_EXE_PROPERTY} system property. Each service created by this method will | ||
* be configured to use a free port on the current system. | ||
* | ||
* @return A new GeckoDriverService using the default configuration. | ||
*/ | ||
public static GeckoDriverService createDefaultService() { | ||
return new Builder().usingAnyFreePort().build(); | ||
} | ||
|
||
@Override | ||
protected void waitUntilAvailable() throws MalformedURLException { | ||
waitForPortUp(getUrl().getPort(), 20, SECONDS); | ||
} | ||
|
||
private static void waitForPortUp(int port, int timeout, TimeUnit unit) { | ||
long end = System.currentTimeMillis() + unit.toMillis(timeout); | ||
while (System.currentTimeMillis() < end) { | ||
try { | ||
Socket socket = new Socket(); | ||
socket.connect(new InetSocketAddress("localhost", port), 1000); | ||
socket.close(); | ||
return; | ||
} catch (ConnectException e) { | ||
// Ignore this | ||
} catch (SocketTimeoutException e) { | ||
// Ignore this | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Builder used to configure new {@link GeckoDriverService} instances. | ||
*/ | ||
public static class Builder extends DriverService.Builder< | ||
GeckoDriverService, GeckoDriverService.Builder> { | ||
|
||
@Override | ||
protected File findDefaultExecutable() { | ||
return findExecutable("wires", GECKO_DRIVER_EXE_PROPERTY, | ||
"https://github.com/jgraham/wires", | ||
"https://github.com/jgraham/wires"); | ||
} | ||
|
||
@Override | ||
protected ImmutableList<String> createArgs() { | ||
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder(); | ||
argsBuilder.add(String.format("--webdriver-port=%d", getPort())); | ||
if (getLogFile() != null) { | ||
argsBuilder.add(String.format("--log-file=\"%s\"", getLogFile().getAbsolutePath())); | ||
} | ||
argsBuilder.add("-b"); | ||
argsBuilder.add(new Executable(null).getPath()); | ||
return argsBuilder.build(); | ||
} | ||
|
||
@Override | ||
protected GeckoDriverService createDriverService(File exe, int port, | ||
ImmutableList<String> args, | ||
ImmutableMap<String, String> environment) { | ||
try { | ||
return new GeckoDriverService(exe, port, args, environment); | ||
} catch (IOException e) { | ||
throw new WebDriverException(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.