.withBrowser(FIREFOX) .withUrls(ImmutableMap.of("http://testurl", urlConfig)) .withWindowHeight(100) .build(); testee.close(); testee = new Browser(runStepConfig, jobConfig, fileService, browserUtilsMock);
@Test public void shouldNotCheckForErrorsIfDisabled() { //given when(webDriver.manage().logs().get(LogType.BROWSER)).thenReturn(new LogEntries(of(new LogEntry(Level.SEVERE, Instant.now().toEpochMilli(), "Fehler!")))); JobConfig jobConfig = JobConfig.exampleConfigBuilder().withCheckForErrorsInLog(false).build(); //when new LogErrorChecker().checkForErrors(webDriver, jobConfig); //then expect no exception } }
private JobConfig createJobConfigWithUrlAndName(String url, String name) { return configBuilder() .withName(name) .withUrls(ImmutableMap.of(url, new UrlConfig( ImmutableList.of("/"), 0, ImmutableList.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableList.of(600), 100000, 0, 0, 0, DEFAULT_WARMUP_BROWSER_CACHE_TIME, null, 0, new HttpCheckConfig(), 0, false ))) .build(); } }
.withBrowser(FIREFOX) .withUrls(ImmutableMap.of("http://testurl", urlConfig)) .withWindowHeight(100) .build();
.withBrowser(FIREFOX) .withUrls(ImmutableMap.of("http://testurl", urlConfig)) .withWindowHeight(100) .build(); testee.close(); testee = new Browser(runStepConfig, jobConfig, fileService, browserUtilsMock);
.withBrowser(CHROME_HEADLESS) .withUrls(ImmutableMap.of("testurl", urlConfig)) .withWindowHeight(100) .build();
private JobConfig createTestConfig() { return configBuilder() .withUrls(ImmutableMap.of("http://www.example.com", new UrlConfig( ImmutableList.of("/"), 0, ImmutableList.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableList.of(600), 100000, 0, 0, 0, DEFAULT_WARMUP_BROWSER_CACHE_TIME, null, 0, new HttpCheckConfig(), 0, false ))) .build(); } }
public static JobConfig.Builder exampleConfigBuilder() { return configBuilder() .withUrls(ImmutableMap.of("http://www.example.com", new UrlConfig( ImmutableList.of("/", "someOtherPath"), DEFAULT_MAX_DIFF, ImmutableList.of( new Cookie("exampleCookieName", "exampleValue", "http://www.example.com", "/", new Date(1000L), true) ), ImmutableMap.of("live", "www"), ImmutableMap.of("exampleLocalStorageKey", "value"), ImmutableMap.of("exampleSessionStorageKey", "value"), ImmutableList.of(600, 800, 1000), DEFAULT_MAX_SCROLL_HEIGHT, DEFAULT_WAIT_AFTER_PAGE_LOAD, DEFAULT_WAIT_AFTER_SCROLL, DEFAULT_WAIT_FOR_NO_ANIMATION_AFTER_SCROLL, DEFAULT_WARMUP_BROWSER_CACHE_TIME, "console.log('This is JavaScript!')", DEFAULT_WAIT_FOR_FONTS_TIME, new HttpCheckConfig(true), DEFAULT_MAX_COLOR_DIFF_PER_PIXEL, false ))); }
@Test public void shouldSanitizeJobConfig() throws BrowserNotInstalledException { //Given JobConfig evilJobConfig = copyOfBuilder(exampleConfig()) .withBrowser(CHROME_HEADLESS) .withThreads(Integer.MAX_VALUE) .withDebug(true) .withLogToFile(true) .withReportFormat(1) .build(); //When JobConfig sanitizedJobConfig = jLineupRunnerFactory.sanitizeJobConfig(evilJobConfig); //Then assertThat(sanitizedJobConfig.threads, is(jLineupWebProperties.getMaxThreadsPerJob())); assertThat(sanitizedJobConfig.debug, is(false)); assertThat(sanitizedJobConfig.logToFile, is(false)); assertThat(sanitizedJobConfig.reportFormat, is(DEFAULT_REPORT_FORMAT)); }
@Test public void shouldReturn422IfConfigValidationFails() throws Exception { // given JobConfig jobConfig = JobConfig.copyOfBuilder(exampleConfig()).withUrls(null).build(); when(jLineupService.startBeforeRun(jobConfig)).thenThrow(new ConfigValidationException("Validation message")); // when ResultActions result = mvc .perform(post("/runs") .content(JobConfig.prettyPrint(jobConfig)) .contentType(MediaType.APPLICATION_JSON)); // then result .andExpect(status().isUnprocessableEntity()) .andExpect(content().string("\"Validation message\"")); }
@Before public void setup() { initMocks(this); when(webDriverMock.manage()).thenReturn(webDriverOptionsMock); when(webDriverOptionsMock.timeouts()).thenReturn(webDriverTimeoutMock); when(webDriverOptionsMock.window()).thenReturn(webDriverWindowMock); when(webDriverOptionsMock.logs()).thenReturn(webDriverLogs); when(browserUtilsMock.getWebDriverByConfig(any(JobConfig.class), any(RunStepConfig.class))).thenReturn(webDriverMock); when(browserUtilsMock.getWebDriverByConfig(any(JobConfig.class), any(RunStepConfig.class), anyInt())).thenReturn(webDriverMock); when(webDriverMock.executeScript(JS_GET_USER_AGENT)).thenReturn("Mocked Webdriver"); JobConfig jobConfig = configBuilder().build(); testee = new Browser(runStepConfig, jobConfig, fileService, browserUtilsMock); testee.initializeWebDriver(); }
public static Builder copyOfBuilder(JobConfig jobConfig) { return configBuilder() .withName(jobConfig.name) .withUrls(jobConfig.urls) .withHttpCheck(jobConfig.httpCheck) .withBrowser(jobConfig.browser) .withGlobalWaitAfterPageLoad(jobConfig.globalWaitAfterPageLoad) .withPageLoadTimeout(jobConfig.pageLoadTimeout) .withWindowHeight(jobConfig.windowHeight) .withThreads(jobConfig.threads) .withScreenshotRetries(jobConfig.screenshotRetries) .withReportFormat(jobConfig.reportFormat) .withGlobalTimeout(jobConfig.globalTimeout) .withDebug(jobConfig.debug) .withLogToFile(jobConfig.logToFile) .withCheckForErrorsInLog(jobConfig.checkForErrorsInLog); }
public static JobConfig exampleConfig() { return exampleConfigBuilder().build(); }
private JobConfig localTestConfig(String endpoint, Browser.Type browser, boolean checkForErrors, UrlConfig urlConfig) { return JobConfig.configBuilder().withCheckForErrorsInLog(checkForErrors).withUrls(ImmutableMap.of("http://localhost:" + port + "/" + endpoint, urlConfig)).withBrowser(browser).build(); }
@Test public void shouldFailIfBrowserIsNotConfigured() { JobConfig jobConfig = copyOfBuilder(createTestConfig()).withBrowser(Browser.Type.FIREFOX).build(); expectStatusCodeForConfig(jobConfig, UNPROCESSABLE_ENTITY.value()); }
@Test public void shouldGetPhantomJSDriver() { final JobConfig jobConfig = configBuilder().withBrowser(PHANTOMJS).build(); assertSetDriverType(jobConfig, PhantomJSDriver.class); }
@Test public void shouldGetChromeDriverForHeadlessChrome() { final JobConfig jobConfig = configBuilder().withBrowser(CHROME_HEADLESS).build(); assertSetDriverType(jobConfig, ChromeDriver.class); }
@Test(expected = BrowserNotInstalledException.class) public void shouldThrowBrowserNotInstalledException() throws BrowserNotInstalledException { // Given JobConfig jobConfig = copyOfBuilder(exampleConfig()) .withBrowser(FIREFOX) .build(); //When jLineupRunnerFactory.sanitizeJobConfig(jobConfig); }
@Test public void shouldGetFirefoxDriver() { final JobConfig jobConfig = configBuilder().withBrowser(FIREFOX).build(); assertSetDriverType(jobConfig, FirefoxDriver.class); }