Last active
August 25, 2019 14:14
-
-
Save beatngu13/e4d756c494cb1d45496f8b4dbff27991 to your computer and use it in GitHub Desktop.
Deep visual testing across multiple browsers and pages using JUnit 5, Selenium, and recheck-web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An abstract base class for all visual tests, defining the pages to test. One can also use separate test cases/methods | |
* if specific pages need different test steps. | |
*/ | |
abstract class AbstractVisualTest { | |
WebDriver driver; | |
Recheck re; | |
abstract WebDriver getWebDriver(); | |
abstract Recheck getRecheck(); | |
@BeforeEach | |
void setUp() { | |
driver = getWebDriver(); | |
re = getRecheck(); | |
} | |
@ParameterizedTest | |
@ValueSource( strings = { "https://example.com/foo/", "https://example.com/bar/" } ) | |
void test( final String url ) { | |
re.startTest( testName( driver, url ) ); | |
driver.get( url ); | |
re.check( driver, "initial" ); | |
re.capTest(); | |
} | |
String testName( final WebDriver driver, final String url ) { | |
final String urlName = url.replaceAll( "http(s)|:|/", "" ); | |
final String driverName = driver.getClass().getSimpleName(); | |
return urlName + "-via-" + driverName; | |
} | |
@AfterEach | |
void tearDown() { | |
driver.quit(); | |
re.cap(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An implementation of the abstract base class for a specific browser, in this case Chrome. One can use this class to | |
* declare specific browser options and configure recheck-web per browser. | |
*/ | |
class ChromeVisualTest extends AbstractVisualTest { | |
@Override | |
WebDriver getWebDriver() { | |
return new ChromeDriver(); | |
} | |
@Override | |
Recheck getRecheck() { | |
return new RecheckImpl(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, one can also combine a list of
WebDriver
s with a list ofURL
s to test against: