Search in sources :

Example 6 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project camunda-bpm-platform by camunda.

the class AbstractWebappUiIntegrationTest method createDriver.

@BeforeClass
public static void createDriver() {
    String chromeDriverExecutable = "chromedriver";
    if (System.getProperty("os.name").toLowerCase(Locale.US).indexOf("windows") > -1) {
        chromeDriverExecutable += ".exe";
    }
    File chromeDriver = new File("target/chromedriver/" + chromeDriverExecutable);
    if (!chromeDriver.exists()) {
        throw new RuntimeException("chromedriver could not be located!");
    }
    ChromeDriverService chromeDriverService = new ChromeDriverService.Builder().withVerbose(true).usingAnyFreePort().usingDriverExecutable(chromeDriver).build();
    driver = new ChromeDriver(chromeDriverService);
}
Also used : ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 7 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project jmeter-plugins by undera.

the class ChromeDriverConfig method getThreadService.

private ChromeDriverService getThreadService() {
    ChromeDriverService service = services.get(currentThreadName());
    if (service != null) {
        return service;
    }
    try {
        service = new ChromeDriverService.Builder().usingDriverExecutable(new File(getChromeDriverPath())).build();
        service.start();
        services.put(currentThreadName(), service);
    } catch (IOException e) {
        LOGGER.error("Failed to start chrome service");
        service = null;
    }
    return service;
}
Also used : IOException(java.io.IOException) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) File(java.io.File)

Example 8 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project jmeter-plugins by undera.

the class ChromeDriverConfigTest method shouldQuitWebDriverAndStopServiceWhenQuitBrowserIsInvoked.

@Test
public void shouldQuitWebDriverAndStopServiceWhenQuitBrowserIsInvoked() throws Exception {
    ChromeDriver mockChromeDriver = mock(ChromeDriver.class);
    ChromeDriverService mockService = mock(ChromeDriverService.class);
    when(mockService.isRunning()).thenReturn(true);
    config.getServices().put(config.currentThreadName(), mockService);
    config.quitBrowser(mockChromeDriver);
    verify(mockChromeDriver).quit();
    assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap()));
    verify(mockService, times(1)).stop();
}
Also used : ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project jmeter-plugins by undera.

the class ChromeDriverConfigTest method shouldCreateChromeAndStartService.

@Test
public void shouldCreateChromeAndStartService() throws Exception {
    ChromeDriver mockChromeDriver = mock(ChromeDriver.class);
    whenNew(ChromeDriver.class).withParameterTypes(ChromeDriverService.class, Capabilities.class).withArguments(isA(ChromeDriverService.class), isA(Capabilities.class)).thenReturn(mockChromeDriver);
    ChromeDriverService.Builder mockServiceBuilder = mock(ChromeDriverService.Builder.class);
    whenNew(ChromeDriverService.Builder.class).withNoArguments().thenReturn(mockServiceBuilder);
    when(mockServiceBuilder.usingDriverExecutable(isA(File.class))).thenReturn(mockServiceBuilder);
    ChromeDriverService mockService = mock(ChromeDriverService.class);
    when(mockServiceBuilder.build()).thenReturn(mockService);
    final ChromeDriver browser = config.createBrowser();
    assertThat(browser, is(mockChromeDriver));
    verifyNew(ChromeDriver.class, times(1)).withArguments(isA(ChromeDriverService.class), isA(Capabilities.class));
    verify(mockServiceBuilder, times(1)).build();
    assertThat(config.getServices().size(), is(1));
    assertThat(config.getServices().values(), hasItem(mockService));
}
Also used : Capabilities(org.openqa.selenium.Capabilities) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with ChromeDriverService

use of org.openqa.selenium.chrome.ChromeDriverService in project jmeter-plugins by undera.

the class ChromeDriverConfigTest method shouldNotCreateChromeWhenStartingServiceThrowsAnException.

@Test
public void shouldNotCreateChromeWhenStartingServiceThrowsAnException() throws Exception {
    ChromeDriverService.Builder mockServiceBuilder = mock(ChromeDriverService.Builder.class);
    whenNew(ChromeDriverService.Builder.class).withNoArguments().thenReturn(mockServiceBuilder);
    when(mockServiceBuilder.usingDriverExecutable(isA(File.class))).thenReturn(mockServiceBuilder);
    ChromeDriverService mockService = mock(ChromeDriverService.class);
    when(mockServiceBuilder.build()).thenReturn(mockService);
    doThrow(new IOException("Stubbed exception")).when(mockService).start();
    final ChromeDriver browser = config.createBrowser();
    assertThat(browser, is(nullValue()));
    assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap()));
    verify(mockServiceBuilder, times(1)).build();
}
Also used : ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)12 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)9 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 File (java.io.File)4 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)4 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)3 TechnicalException (com.github.noraui.exception.TechnicalException)1 SourceFile (com.google.javascript.jscomp.SourceFile)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Capabilities (org.openqa.selenium.Capabilities)1 WebDriver (org.openqa.selenium.WebDriver)1 LogEntry (org.openqa.selenium.logging.LogEntry)1 LoggingPreferences (org.openqa.selenium.logging.LoggingPreferences)1 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)1