mirror of
https://github.com/google/nomulus.git
synced 2025-07-25 20:18:34 +02:00
Enable screenshot comparison in external build
This change actually enabled the screenshot comparison in the visual regression tests. We used Docker to provision Chrome and ChromeDriver to eliminate the discrepancy of environment between local development and Travis CI. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=237811918
This commit is contained in:
parent
d6b7b1cfaa
commit
b0ad8b6a9b
87 changed files with 338 additions and 69 deletions
|
@ -14,6 +14,8 @@
|
|||
|
||||
package google.registry.webdriver;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
|
@ -23,15 +25,21 @@ import org.junit.runners.model.Statement;
|
|||
/**
|
||||
* A JUnit test runner which can retry each test up to 3 times.
|
||||
*
|
||||
* <p>This runner is for our visual regression to prevent flakes
|
||||
* during the run. The test is repeated multiple times until it
|
||||
* passes and it only fails if it failed 3 times.
|
||||
* <p>This runner is for our visual regression to prevent flakes during the run. The test is
|
||||
* repeated multiple times until it passes and it only fails if it failed 3 times.
|
||||
*/
|
||||
public class RepeatableRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private static final int MAX_ATTEMPTS = 3;
|
||||
private static final boolean RUN_ALL_ATTEMPTS =
|
||||
Boolean.parseBoolean(System.getProperty("test.screenshot.runAllAttempts", "false"));
|
||||
|
||||
private static final int MAX_ATTEMPTS =
|
||||
Integer.parseInt(System.getProperty("test.screenshot.maxAttempts", "3"));
|
||||
|
||||
// TODO(b/127984872): Find an elegant way to pass the index of attempt to the test
|
||||
public static int currentAttemptIndex;
|
||||
|
||||
/** Constructs a new instance of the default runner */
|
||||
public RepeatableRunner(Class<?> klass) throws InitializationError {
|
||||
|
@ -56,18 +64,37 @@ public class RepeatableRunner extends BlockJUnit4ClassRunner {
|
|||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
for (int i = 1; i <= MAX_ATTEMPTS; i++) {
|
||||
checkState(MAX_ATTEMPTS > 0);
|
||||
int numSuccess = 0, numFailure = 0;
|
||||
Throwable firstException = null;
|
||||
for (int attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
||||
currentAttemptIndex = attempt;
|
||||
try {
|
||||
statement.evaluate();
|
||||
numSuccess++;
|
||||
if (RUN_ALL_ATTEMPTS) {
|
||||
logger.atInfo().log(
|
||||
"[%s] Attempt %d of %d succeeded!\n", method.getName(), attempt, MAX_ATTEMPTS);
|
||||
continue;
|
||||
}
|
||||
return;
|
||||
} catch (Throwable e) {
|
||||
logger.atSevere().log(
|
||||
"[%s] Attempt %d of %d failed!\n", method.getName(), i, MAX_ATTEMPTS);
|
||||
if (i == MAX_ATTEMPTS) {
|
||||
throw e;
|
||||
numFailure++;
|
||||
if (firstException == null) {
|
||||
firstException = e;
|
||||
}
|
||||
logger.atWarning().log(
|
||||
"[%s] Attempt %d of %d failed!\n", method.getName(), attempt, MAX_ATTEMPTS);
|
||||
}
|
||||
}
|
||||
logger.atInfo().log(
|
||||
"Test [%s] was executed %d times, %d attempts succeeded and %d attempts failed.",
|
||||
method.getName(), numSuccess + numFailure, numSuccess, numFailure);
|
||||
if (numSuccess == 0) {
|
||||
logger.atSevere().log(
|
||||
"[%s] didn't pass after all %d attempts failed!\n", method.getName(), MAX_ATTEMPTS);
|
||||
throw firstException;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue