Skip to content

Commit 9f60d06

Browse files
committed
Fixes #96 Adding Selenium 4 support
1 parent bdb28bc commit 9f60d06

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Selenium Shutterbug is a utility library written in Java for making screenshots
99

1010
The idea behind the project is to make testers life easier by enabling them to create descriptive screenshots which, in some cases, could be directly attached to the bug reports or serve as a source of information about system state at a specific moment of time.
1111

12+
##### Selenium WebDriver version 4+ support starts from version 1.6
13+
1214
Supported features:
1315

1416
- Capturing the entire page

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.assertthat</groupId>
66
<artifactId>selenium-shutterbug</artifactId>
7-
<version>1.7-SNAPSHOT</version>
7+
<version>1.6-SNAPSHOT</version>
88
<name>selenium-shutterbug</name>
99
<description>Utility library to create customized screenshots using Selenium WebDriver and Java AWT</description>
1010
<url>http://www.assertthat.com</url>
@@ -43,8 +43,8 @@
4343
<dependency>
4444
<groupId>org.seleniumhq.selenium</groupId>
4545
<artifactId>selenium-java</artifactId>
46-
<version>3.141.59</version>
47-
<scope>compile</scope>
46+
<version>4.1.1</version>
47+
<scope>compile</scope>
4848
</dependency>
4949
<dependency>
5050
<groupId>commons-io</groupId>

src/main/java/com/assertthat/selenium_shutterbug/utils/web/Browser.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
import org.openqa.selenium.chrome.ChromeDriver;
1515
import org.openqa.selenium.edge.EdgeDriver;
1616
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.*;
2118
import org.openqa.selenium.remote.http.HttpMethod;
2219
import org.openqa.selenium.support.ui.FluentWait;
2320

@@ -28,6 +25,7 @@
2825
import java.io.File;
2926
import java.io.IOException;
3027
import java.io.InputStream;
28+
import java.lang.reflect.Field;
3129
import java.lang.reflect.InvocationTargetException;
3230
import java.lang.reflect.Method;
3331
import java.time.Duration;
@@ -906,8 +904,19 @@ private void defineCustomCommand(String name, CommandInfo info) {
906904
try {
907905
Method defineCommand = HttpCommandExecutor.class.getDeclaredMethod("defineCommand", String.class, CommandInfo.class);
908906
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) {
911920
throw new RuntimeException(e);
912921
}
913922
}

0 commit comments

Comments
 (0)