google-nomulus/javatests/google/registry/webdriver/WebDriverPlusScreenDiffer.java
shicong 8af9090fb0 Use reflection to inject the attempt number
This CL is to address the public static field in RepeatableRunner
for caller to get the current attempt number. We tried to have
a JUnit TestRule to achieve the purpose but it ended up with having
a RuleChain in each class where we already have multiple rules and
need to add the retry rule. This is because we have to make sure
the retry rule is the last one to wrap the test statement so that
the actual retry can include the actions defined in other rules.
Having a rule chain is not scalable and confuses engineer so we
gave it up.

Instead, we decided to expand the current RepeatableRunner to
use reflection to inject the attempt number to the test class.
Doing it this way can reduce the burden from the caller and it also
gets rid of the global state from the previous public static field.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=240789045
2019-03-29 16:17:35 -04:00

60 lines
2.5 KiB
Java

// Copyright 2019 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.webdriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
/**
* Interface to provide the implementation of {@link org.openqa.selenium.WebDriver} and APIs to
* compare screenshots for visual regression tests.
*/
interface WebDriverPlusScreenDiffer {
/** Gets the implementation of {@link org.openqa.selenium.WebDriver}. */
WebDriver getWebDriver();
/**
* Checks that the screenshot of the element matches the golden image by pixel comparison. {@link
* #verifyAndQuit()} needs to be invoked to actually trigger the comparison.
*
* <p>On mismatch, the test will continue until the end of the test (and then fail). This is so
* other screenshot matches can be executed in the same function - allowing you to approve /
* reject all at once.
*
* @param element the element on the page to be compared
* @param imageKey a unique name such that by prepending the calling class name and method name in
* the format of ClassName_MethodName_<imageKey> will uniquely identify golden image.
* @param attempt the attempt number of the test
*/
void diffElement(WebElement element, String imageKey, int attempt);
/**
* Checks that the screenshot matches the golden image by pixel comparison. {@link
* #verifyAndQuit()} needs to be invoked to actually trigger the comparison.
*
* <p>On mismatch, the test will continue until the end of the test (and then fail). This is so
* other screenshot matches can be executed in the same function - allowing you to approve /
* reject all at once.
*
* @param imageKey a unique name such that by prepending the calling class name and method name in
* the format of ClassName_MethodName_<imageKey> will uniquely identify golden image.
* @param attempt the attempt number of the test
*/
void diffPage(String imageKey, int attempt);
/** Asserts that all diffs up to this point have PASSED. */
void verifyAndQuit();
}