Skip to content

Commit

Permalink
Bugfix: Also add cookies to setup-paths and cleanup-paths preparation…
Browse files Browse the repository at this point in the history
… and teardown calls (#1809)
  • Loading branch information
MediaMarco committed Mar 4, 2025
1 parent 7062fdd commit 6755903
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private static List<ScreenshotContext> buildTestContexts(RunStepConfig runStepCo
for (final String path : paths) {
//TODO: alternatingCookies
screenshotContextList.add(new ScreenshotContext(prepareDomain(runStepConfig, urlConfigEntry.getValue().url), path, deviceConfigBuilder().build(),
Collections.emptyList(), runStepConfig.getBrowserStep(), urlConfigEntry.getValue(), getFullPathOfReportDir(runStepConfig), false, urlConfigEntry.getKey()));
urlConfigEntry.getValue().cookies, runStepConfig.getBrowserStep(), urlConfigEntry.getValue(), getFullPathOfReportDir(runStepConfig), false, urlConfigEntry.getKey()));
}
}
return screenshotContextList;
Expand Down
68 changes: 47 additions & 21 deletions core/src/test/java/de/otto/jlineup/browser/BrowserUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.springframework.boot.autoconfigure.batch.BatchProperties;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -84,8 +85,8 @@ public void shouldGenerateScreenshotsParameters() throws IOException {
ScreenshotContext.of("https://www.otto.de", "multimedia", deviceConfig(600, expectedHeight), before, expectedUrlConfigForOttoDe, expectedUrlConfigForOttoDe.cookies),
ScreenshotContext.of("https://www.otto.de", "multimedia", deviceConfig(800, expectedHeight), before, expectedUrlConfigForOttoDe, expectedUrlConfigForOttoDe.cookies),
ScreenshotContext.of("https://www.otto.de", "multimedia", deviceConfig(1200, expectedHeight), before, expectedUrlConfigForOttoDe, expectedUrlConfigForOttoDe.cookies),
ScreenshotContext.of("http://www.doodle.de", "/", deviceConfig(1200, expectedHeight), before, expectedUrlConfigForGoogleDe, Stream.concat(expectedUrlConfigForGoogleDe.cookies.stream(), expectedUrlConfigForGoogleDe.alternatingCookies.get(0).stream()).collect(Collectors.toList()),"http://www.google.de"),
ScreenshotContext.of("http://www.doodle.de", "/", deviceConfig(1200, expectedHeight), before, expectedUrlConfigForGoogleDe, Stream.concat(expectedUrlConfigForGoogleDe.cookies.stream(), expectedUrlConfigForGoogleDe.alternatingCookies.get(1).stream()).collect(Collectors.toList()),"http://www.google.de")
ScreenshotContext.of("http://www.doodle.de", "/", deviceConfig(1200, expectedHeight), before, expectedUrlConfigForGoogleDe, Stream.concat(expectedUrlConfigForGoogleDe.cookies.stream(), expectedUrlConfigForGoogleDe.alternatingCookies.get(0).stream()).collect(Collectors.toList()), "http://www.google.de"),
ScreenshotContext.of("http://www.doodle.de", "/", deviceConfig(1200, expectedHeight), before, expectedUrlConfigForGoogleDe, Stream.concat(expectedUrlConfigForGoogleDe.cookies.stream(), expectedUrlConfigForGoogleDe.alternatingCookies.get(1).stream()).collect(Collectors.toList()), "http://www.google.de")
);

//when
Expand Down Expand Up @@ -130,11 +131,55 @@ public void shouldPrepareDomain() {
assertThat(result, is("www.bonprix.de"));
}

@Test
public void shouldGetFirefoxDriver() {
final JobConfig jobConfig = jobConfigBuilder().withBrowser(FIREFOX).build();
assertSetDriverType(jobConfig, FirefoxDriver.class);
}

@Test
public void shouldGetChromeDriver() {
final JobConfig jobConfig = jobConfigBuilder().withBrowser(CHROME).build();
assertSetDriverType(jobConfig, ChromeDriver.class);
}

@Test
public void shouldGetChromeDriverForHeadlessChrome() {
final JobConfig jobConfig = jobConfigBuilder().withBrowser(CHROME_HEADLESS).build();
assertSetDriverType(jobConfig, ChromeDriver.class);
}

@Test
public void shouldAddCookiesToTestSetupCalls() {
final JobConfig jobConfig = jobConfigBuilder().addUrlConfig(getExpectedUrlConfigForOttoDe().url, getExpectedUrlConfigForOttoDe()).build();
List<ScreenshotContext> screenshotContexts = BrowserUtils.buildTestSetupContexts(runStepConfigBuilder().withStep(RunStep.before).build(), jobConfig);
assertThat(screenshotContexts.size(), is(1));
assertThat(screenshotContexts.get(0).cookies.size(), is(2));
assertThat(screenshotContexts.get(0).cookies.get(0).name, is("testcookie1"));
assertThat(screenshotContexts.get(0).cookies.get(0).value, is("true"));
assertThat(screenshotContexts.get(0).cookies.get(1).name, is("testcookie2"));
assertThat(screenshotContexts.get(0).cookies.get(1).value, is("1"));
}

@Test
public void shouldAddCookiesToTestCleanupCalls() {
final JobConfig jobConfig = jobConfigBuilder().addUrlConfig(getExpectedUrlConfigForOttoDe().url, getExpectedUrlConfigForOttoDe()).build();
List<ScreenshotContext> screenshotContexts = BrowserUtils.buildTestCleanupContexts(runStepConfigBuilder().withStep(RunStep.before).build(), jobConfig);
assertThat(screenshotContexts.size(), is(1));
assertThat(screenshotContexts.get(0).cookies.size(), is(2));
assertThat(screenshotContexts.get(0).cookies.get(0).name, is("testcookie1"));
assertThat(screenshotContexts.get(0).cookies.get(0).value, is("true"));
assertThat(screenshotContexts.get(0).cookies.get(1).name, is("testcookie2"));
assertThat(screenshotContexts.get(0).cookies.get(1).value, is("1"));
}

public static UrlConfig getExpectedUrlConfigForOttoDe() {

return UrlConfig.urlConfigBuilder()
.withUrl("https://www.otto.de")
.withPaths(ImmutableList.of("/", "multimedia"))
.withSetupPaths(ImmutableList.of("setup"))
.withCleanupPaths(ImmutableList.of("cleanup"))
.withMaxDiff(0.05d)
.withCookies(ImmutableList.of(new Cookie("testcookie1", "true"), new Cookie("testcookie2", "1")))
.withEnvMapping(ImmutableMap.of("live", "www"))
Expand Down Expand Up @@ -167,25 +212,6 @@ public static UrlConfig getExpectedUrlConfigForGoogleDe() {
.build();
}

@Test
public void shouldGetFirefoxDriver() {
final JobConfig jobConfig = jobConfigBuilder().withBrowser(FIREFOX).build();
assertSetDriverType(jobConfig, FirefoxDriver.class);
}

@Test
public void shouldGetChromeDriver() {
final JobConfig jobConfig = jobConfigBuilder().withBrowser(CHROME).build();
assertSetDriverType(jobConfig, ChromeDriver.class);
}

@Test
public void shouldGetChromeDriverForHeadlessChrome() {
final JobConfig jobConfig = jobConfigBuilder().withBrowser(CHROME_HEADLESS).build();
assertSetDriverType(jobConfig, ChromeDriver.class);
}


private void assertSetDriverType(JobConfig jobConfig, Class<? extends WebDriver> driverClass) {
WebDriver driver = null;
BrowserUtils realBrowserUtils = new BrowserUtils();
Expand Down
6 changes: 6 additions & 0 deletions core/src/test/resources/lineup_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"/",
"multimedia"
],
"setup-paths": [
"setup"
],
"cleanup-paths": [
"cleanup"
],
"max-diff": 0.05,
"cookies": [
{
Expand Down

0 comments on commit 6755903

Please sign in to comment.