testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

BrowserWebDriverContainer marks all FLV files as FAILED even if tests pass

Open TVictor opened this issue 8 years ago • 2 comments

Running:

public class SeleniumContainerTest {
	
	@Rule
	public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
			                                          .withDesiredCapabilities(DesiredCapabilities.chrome())
			                                          .withRecordingMode(RECORD_ALL, new File("target"));
	
	@Test
	public void simplePlainSeleniumTest() throws InterruptedException {
		RemoteWebDriver driver = chrome.getWebDriver();
				
				driver.get("https://wikipedia.org");
		WebElement searchInput = driver.findElementByName("search");
		
		searchInput.sendKeys("Rick Astley");
		searchInput.submit();
		
		WebElement otherPage = driver.findElementByLinkText("Rickrolling");
		otherPage.click();
		
		boolean expectedTextFound = driver.findElementsByCssSelector("p")
				                            .stream()
				                            .anyMatch(element -> element.getText().contains("meme"));
		
		assertTrue("The word 'meme' is found on a page about rickrolling", expectedTextFound);
		
	}
}

This will create a flv file like this: FAILED-testcontainer.SeleniumContainerTest-simplePlainSeleniumTest-20180815-092837.flv

Even if I switch Recording Mode to RECORD_FAIL it still produces the flv file, even though the test pass. After playing around with BrowserWebDriverContainer I found that if I change this method:

@Override
	public void afterTest(TestDescription description, Optional<Throwable> throwable) {
		retainRecordingIfNeeded(description.getFilesystemFriendlyName(), !throwable.isPresent());
	}

I get the desired result of PASSED-.flv on RECORD_ALL or nothing on RECORD_FAILED, and get FAILED-.flv when I force an assertion failure.

It is such a small fix, should I PR this?

TVictor avatar Aug 15 '18 07:08 TVictor

Hi @TVictor! Yes, there is a bug, it is fixed in #821, will be released soon :)

bsideup avatar Aug 15 '18 07:08 bsideup

Great, thank you for letting me know.

TVictor avatar Aug 15 '18 07:08 TVictor