Search in sources :

Example 1 with Config

use of de.otto.jlineup.config.Config in project jlineup by otto-de.

the class BrowserTest method shouldGetChromeDriver.

@Test
public void shouldGetChromeDriver() throws InterruptedException {
    final Config config = configBuilder().withBrowser(CHROME).build();
    assertSetDriverType(config, ChromeDriver.class);
}
Also used : UrlConfig(de.otto.jlineup.config.UrlConfig) Config(de.otto.jlineup.config.Config) Test(org.junit.Test)

Example 2 with Config

use of de.otto.jlineup.config.Config in project jlineup by otto-de.

the class BrowserTest method setup.

@Before
public void setup() throws IOException {
    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(Config.class))).thenReturn(webDriverMock);
    when(browserUtilsMock.getWebDriverByConfig(any(Config.class), anyInt())).thenReturn(webDriverMock);
    Config config = configBuilder().build();
    testee = new Browser(parameters, config, fileService, browserUtilsMock);
    testee.initializeWebDriver();
}
Also used : UrlConfig(de.otto.jlineup.config.UrlConfig) Config(de.otto.jlineup.config.Config) Browser(de.otto.jlineup.browser.Browser) Before(org.junit.Before)

Example 3 with Config

use of de.otto.jlineup.config.Config in project jlineup by otto-de.

the class BrowserTest method shouldDoAllTheScreenshotWebdriverCalls.

@Test
public void shouldDoAllTheScreenshotWebdriverCalls() throws Exception {
    // given
    final Long viewportHeight = 500L;
    final Long pageHeight = 2000L;
    UrlConfig urlConfig = new UrlConfig(ImmutableList.of("/"), 0f, ImmutableList.of(new Cookie("testcookiename", "testcookievalue")), ImmutableMap.of(), ImmutableMap.of("key", "value"), ImmutableMap.of("key", "value"), ImmutableList.of(600, 800), 5000, 0, 0, 0, 3, "testJS();", 5);
    Config config = configBuilder().withBrowser(FIREFOX).withUrls(ImmutableMap.of("testurl", urlConfig)).withWindowHeight(100).build();
    testee.close();
    testee = new Browser(parameters, config, fileService, browserUtilsMock);
    ScreenshotContext screenshotContext = ScreenshotContext.of("testurl", "/", 600, true, urlConfig);
    ScreenshotContext screenshotContext2 = ScreenshotContext.of("testurl", "/", 800, true, urlConfig);
    when(webDriverMock.executeScript(JS_DOCUMENT_HEIGHT_CALL)).thenReturn(pageHeight);
    when(webDriverMock.executeScript(JS_CLIENT_VIEWPORT_HEIGHT_CALL)).thenReturn(viewportHeight);
    when(webDriverMock.getScreenshotAs(OutputType.FILE)).thenReturn(new File(getFilePath("screenshots/http_url_root_ff3c40c_1001_02002_before.png")));
    when(webDriverMock.executeScript(JS_RETURN_DOCUMENT_FONTS_SIZE_CALL)).thenReturn(3L);
    when(webDriverMock.executeScript(JS_RETURN_DOCUMENT_FONTS_STATUS_LOADED_CALL)).thenReturn(false).thenReturn(true);
    // when
    testee.takeScreenshots(ImmutableList.of(screenshotContext, screenshotContext2));
    // then
    verify(webDriverWindowMock, times(2)).setSize(new Dimension(600, 100));
    verify(webDriverWindowMock, times(2)).setSize(new Dimension(800, 100));
    verify(webDriverMock, times(2)).executeScript(JS_SCROLL_TO_TOP_CALL);
    verify(webDriverMock, times(2)).executeScript("testJS();");
    verify(webDriverMock, times(10)).executeScript(JS_DOCUMENT_HEIGHT_CALL);
    verify(webDriverMock, times(5)).get("testurl/");
    verify(webDriverMock, times(2)).executeScript(JS_CLIENT_VIEWPORT_HEIGHT_CALL);
    verify(webDriverOptionsMock, times(2)).addCookie(new org.openqa.selenium.Cookie("testcookiename", "testcookievalue"));
    verify(webDriverMock, times(2)).executeScript(String.format(JS_SET_LOCAL_STORAGE_CALL, "key", "value"));
    verify(webDriverMock, times(2)).executeScript(String.format(JS_SET_SESSION_STORAGE_CALL, "key", "value"));
    verify(webDriverMock, times(8)).executeScript(String.format(JS_SCROLL_CALL, 500));
}
Also used : Cookie(de.otto.jlineup.config.Cookie) UrlConfig(de.otto.jlineup.config.UrlConfig) UrlConfig(de.otto.jlineup.config.UrlConfig) Config(de.otto.jlineup.config.Config) Dimension(org.openqa.selenium.Dimension) File(java.io.File) Browser(de.otto.jlineup.browser.Browser) Test(org.junit.Test)

Example 4 with Config

use of de.otto.jlineup.config.Config in project jlineup by otto-de.

the class BrowserTest method shouldGetFirefoxDriver.

@Test
public void shouldGetFirefoxDriver() throws InterruptedException {
    final Config config = configBuilder().withBrowser(FIREFOX).build();
    assertSetDriverType(config, FirefoxDriver.class);
}
Also used : UrlConfig(de.otto.jlineup.config.UrlConfig) Config(de.otto.jlineup.config.Config) Test(org.junit.Test)

Example 5 with Config

use of de.otto.jlineup.config.Config in project jlineup by otto-de.

the class Main method buildConfig.

private static Config buildConfig(Parameters parameters) throws FileNotFoundException {
    Config config;
    if (parameters.getUrl() != null) {
        String url = BrowserUtils.prependHTTPIfNotThereAndToLowerCase(parameters.getUrl());
        config = Config.defaultConfig(url);
        if (!parameters.isPrintConfig()) {
            System.out.printf("You specified an explicit URL parameter (%s), any given config file is ignored! This should only be done for testing purpose.%n", url);
            System.out.printf("Using generated config:%n%s%n", Util.createPrettyConfigJson(config));
            System.out.println("You can take this generated config as base and save it as a text file named 'lineup.json'.");
            System.out.println("Just add --print-config parameter to let JLineup print an example config");
        }
    } else {
        try {
            config = Config.readConfig(parameters);
        } catch (FileNotFoundException e) {
            if (!parameters.isPrintConfig()) {
                System.err.println(e.getMessage());
                System.err.println("Use --help to see the JLineup quick help.");
                throw e;
            } else {
                return Config.exampleConfig();
            }
        }
    }
    return config;
}
Also used : Config(de.otto.jlineup.config.Config) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Config (de.otto.jlineup.config.Config)10 UrlConfig (de.otto.jlineup.config.UrlConfig)8 Test (org.junit.Test)7 Browser (de.otto.jlineup.browser.Browser)3 Parameters (de.otto.jlineup.config.Parameters)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 JCommander (com.beust.jcommander.JCommander)1 Cookie (de.otto.jlineup.config.Cookie)1 Before (org.junit.Before)1 Dimension (org.openqa.selenium.Dimension)1