Skip to content

Instantly share code, notes, and snippets.

@nickgrealy
Last active February 5, 2020 08:31
Show Gist options
  • Save nickgrealy/267fd8016bc84eddeb50 to your computer and use it in GitHub Desktop.
Save nickgrealy/267fd8016bc84eddeb50 to your computer and use it in GitHub Desktop.
Class to synchronise calls to the WebDriver instance.
package selenium.webdrivers;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerDriverService;
import org.openqa.selenium.remote.Response;
import java.util.Map;
/**
* A synchronised implementation of the InternetExplorerDriver. Workaround for Selenium issue:
* <a href="http://code.google.com/p/selenium/issues/detail?id=6592">IE Driver returns 404: File not found</a>.
* <p/>
* <b>N.B.</b> synchronises the execute(...) methods.
*
* @author [email protected]
* @version 1.0
* @since 27/08/2014
*/
public class SynchronizedInternetExplorerDriver extends InternetExplorerDriver {
private Object lock;
/* constructors */
public SynchronizedInternetExplorerDriver() {
super();
}
public SynchronizedInternetExplorerDriver(Capabilities capabilities) {
super(capabilities);
}
public SynchronizedInternetExplorerDriver(int port) {
super(port);
}
public SynchronizedInternetExplorerDriver(InternetExplorerDriverService service) {
super(service);
}
public SynchronizedInternetExplorerDriver(InternetExplorerDriverService service, Capabilities capabilities) {
super(service, capabilities);
}
public SynchronizedInternetExplorerDriver(InternetExplorerDriverService service, Capabilities capabilities, int port) {
super(service, capabilities, port);
}
/* overrides */
@Override
protected Response execute(String driverCommand, Map<String, ?> parameters) {
synchronized (getLock()) {
return super.execute(driverCommand, parameters);
}
}
@Override
protected Response execute(String command) {
synchronized (getLock()) {
return super.execute(command);
}
}
/* getters */
public Object getLock() {
if (lock == null) {
// class level variable is not initialised if called from within constructor.
lock = new Object();
}
return lock;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment