Skip to content

Commit

Permalink
Add recommended code revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
zmacca committed Jun 10, 2024
1 parent 7f2049c commit 527f0e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
16 changes: 7 additions & 9 deletions src/main/java/au/gov/qld/online/selenium/SeleniumHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public final class SeleniumHelper {
private static DriverService chromeService;

//Keep list of released browsers to reuse until max usage is hit
private static Map<String, WebDriverHolder> webDriverListReleased = new ConcurrentHashMap<>();
private static final Map<String, WebDriverHolder> webDriverListReleased = new ConcurrentHashMap<>();
//Keep internal tabs on open browsers so when we die unexpectedly we don't leave orphaned browsers running on outside of jvm connection
private static List<WebDriver> webDriverListAll = new LinkedList<>();
private static List<DriverService> driverServiceAll = new LinkedList<>();
private static File screenprintFolder = new File("target/screenprints/" + new SimpleDateFormat("dd-M-yyyy", Locale.getDefault()).format(new Date()) + "/");
private static File screenprintCurrentFolder = new File("target/screenprints/current");
private static final List<WebDriver> webDriverListAll = new LinkedList<>();
private static final List<DriverService> driverServiceAll = new LinkedList<>();
private static final File screenprintFolder = new File("target/screenprints/" + new SimpleDateFormat("dd-M-yyyy", Locale.getDefault()).format(new Date()) + "/");
private static final File screenprintCurrentFolder = new File("target/screenprints/current");
private static boolean doScreenPrints = false;
private static boolean headlessEnabled = true;

Expand All @@ -74,12 +74,10 @@ public void run() {
}
for (DriverService service : driverServiceAll) {
if (service != null) {
try {
try (service) {
service.stop();
} catch (Exception e) {
LOGGER.error("exception on close", e);
} finally {
service.close();
}
}
}
Expand Down Expand Up @@ -138,7 +136,7 @@ public static synchronized WebDriverHolder getWebDriver(DriverTypes driverType,
}
}

WebDriver webDriver = null;
WebDriver webDriver;
WebDriverManager wdm;
try {
final Platform platform = Platform.getCurrent();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/au/gov/qld/online/selenium/WebDriverHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

public class WebDriverHolder {

private WebDriver webDriver;
private DriverTypes driverType;
private final WebDriver webDriver;
private final DriverTypes driverType;
private int numberUsed = 0;
private String downloadDirectory;
private final String downloadDirectory;

public WebDriverHolder(WebDriver webDriver, DriverTypes driverType, String downloadDirectory) {
this.webDriver = webDriver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -62,7 +63,6 @@ public void shouldStartFirefoxBrowserMultiTest() {
holder3.getWebDriver().navigate().to("https://www.whirlpool.net.au");
SeleniumHelper.performScreenPrint(holder3, testName);
SeleniumHelper.close(holder);
int afterStart = SeleniumHelper.openDrivers();
}

@Test
Expand Down Expand Up @@ -197,7 +197,7 @@ public void shouldSetDownloadDirectoryForChromeBrowser() throws IOException, Int
try {
Assertions.assertThat(downloadedFile).exists();
} catch (AssertionError e) {
Set<String> files = Stream.of(tempDownloadDirectory.toFile().listFiles())
Set<String> files = Stream.of(Objects.requireNonNull(tempDownloadDirectory.toFile().listFiles()))
.filter(file -> !file.isDirectory())
.map(File::getName)
.collect(Collectors.toSet());
Expand Down

0 comments on commit 527f0e0

Please sign in to comment.