|
14 | 14 | import org.openqa.selenium.chrome.ChromeDriver;
|
15 | 15 | import org.openqa.selenium.edge.EdgeDriver;
|
16 | 16 | import org.openqa.selenium.firefox.FirefoxDriver;
|
17 |
| -import org.openqa.selenium.remote.CommandInfo; |
18 |
| -import org.openqa.selenium.remote.HttpCommandExecutor; |
19 |
| -import org.openqa.selenium.remote.RemoteWebDriver; |
20 |
| -import org.openqa.selenium.remote.Response; |
| 17 | +import org.openqa.selenium.remote.*; |
21 | 18 | import org.openqa.selenium.remote.http.HttpMethod;
|
22 | 19 | import org.openqa.selenium.support.ui.FluentWait;
|
23 | 20 |
|
|
28 | 25 | import java.io.File;
|
29 | 26 | import java.io.IOException;
|
30 | 27 | import java.io.InputStream;
|
| 28 | +import java.lang.reflect.Field; |
31 | 29 | import java.lang.reflect.InvocationTargetException;
|
32 | 30 | import java.lang.reflect.Method;
|
33 | 31 | import java.time.Duration;
|
@@ -906,8 +904,19 @@ private void defineCustomCommand(String name, CommandInfo info) {
|
906 | 904 | try {
|
907 | 905 | Method defineCommand = HttpCommandExecutor.class.getDeclaredMethod("defineCommand", String.class, CommandInfo.class);
|
908 | 906 | defineCommand.setAccessible(true);
|
909 |
| - defineCommand.invoke(((RemoteWebDriver) this.driver).getCommandExecutor(), name, info); |
910 |
| - } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { |
| 907 | + CommandExecutor commandExecutor = ((RemoteWebDriver) this.driver).getCommandExecutor(); |
| 908 | + try { |
| 909 | + Class.forName("org.openqa.selenium.remote.TracedCommandExecutor"); |
| 910 | + if (commandExecutor instanceof TracedCommandExecutor) { |
| 911 | + Field delegateField = TracedCommandExecutor.class.getDeclaredField("delegate"); |
| 912 | + delegateField.setAccessible(true); |
| 913 | + commandExecutor = (CommandExecutor) delegateField.get(commandExecutor); |
| 914 | + } |
| 915 | + }catch (ClassNotFoundException cnfe){ |
| 916 | + //Then using selenium 3 |
| 917 | + } |
| 918 | + defineCommand.invoke(commandExecutor, name, info); |
| 919 | + } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException | NoSuchFieldException e) { |
911 | 920 | throw new RuntimeException(e);
|
912 | 921 | }
|
913 | 922 | }
|
|
0 commit comments