Skip to content

Commit

Permalink
Check if command "google-chrome-stable" is available when running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
centic9 committed Jan 10, 2025
1 parent 0826ce0 commit 4c40472
Showing 1 changed file with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
package org.dstadler.commons.selenium;

import static org.dstadler.commons.selenium.ChromeDriverUtils.PROPERTY_CHROME_DRIVER;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.dstadler.commons.exec.ExecutionHelper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.dstadler.commons.selenium.ChromeDriverUtils.PROPERTY_CHROME_DRIVER;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ChromeDriverUtilsTest {
@AfterEach
public void tearDown() {
ChromeDriverUtils.cleanUp();
}

private void assumeGoogleChrome() {
// we only read from the registry on Windows
if (SystemUtils.IS_OS_WINDOWS) {
return;
}

CommandLine cmdLine = new CommandLine("google-chrome-stable");
cmdLine.addArgument("--version");

try {
ExecutionHelper.getCommandResult(cmdLine, new File("."), 0, 10_000);
} catch (IOException e) {
Assumptions.assumeTrue(false, "Command " + cmdLine + " not available: " + e.getMessage());
}
}

@Test
public void testGetGoogleChromeVersion() throws IOException {
String googleChromeVersion = ChromeDriverUtils.getGoogleChromeVersion();
assumeGoogleChrome();

String googleChromeVersion = ChromeDriverUtils.getGoogleChromeVersion();

assertTrue(StringUtils.isNotBlank(googleChromeVersion));

Expand All @@ -30,7 +52,9 @@ public void testGetGoogleChromeVersion() throws IOException {

@Test
public void testConfigureMatchingChromeDriver() throws IOException {
assertTrue(StringUtils.isBlank(System.getProperty(PROPERTY_CHROME_DRIVER)),
assumeGoogleChrome();

assertTrue(StringUtils.isBlank(System.getProperty(PROPERTY_CHROME_DRIVER)),
"System property for chrome-driver should not be set before starting this test");

ChromeDriverUtils.configureMatchingChromeDriver();
Expand Down

0 comments on commit 4c40472

Please sign in to comment.