@Test
  public void shouldHaveAndroidConfigWhenAndroidIsEnabled() {
    config.setAndroidEnabled(true);

    final Capabilities capabilities = config.createCapabilities();
    Map<String, Object> options =
        (Map<String, Object>) capabilities.getCapability(ChromeOptions.CAPABILITY);
    assertThat("ChromeOption expected", options, is(notNullValue()));

    final String androidConfig = (String) options.get("androidPackage");
    assertThat(androidConfig, is("com.android.chrome"));
  }
  @Test
  public void shouldBeAbleToCallQuitBrowserMultipleTimes() 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);
    config.quitBrowser(mockChromeDriver);

    assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap()));
    verify(mockService, times(1)).stop();
  }
  @Test
  public void shouldNotStopServiceIfNotRunningWhenQuitBrowserIsInvoked() throws Exception {
    ChromeDriver mockChromeDriver = mock(ChromeDriver.class);
    ChromeDriverService mockService = mock(ChromeDriverService.class);
    when(mockService.isRunning()).thenReturn(false);
    config.getServices().put(config.currentThreadName(), mockService);

    config.quitBrowser(mockChromeDriver);

    verify(mockChromeDriver).quit();
    assertThat(config.getServices(), is(Collections.<String, ChromeDriverService>emptyMap()));
    verify(mockService, times(0)).stop();
  }
  @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();
  }
  @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));
  }
 @After
 public void resetConfig() {
   config.clearThreadBrowsers();
   config.getServices().clear();
   JMeterContextService.getContext().setVariables(null);
 }
 @Test
 public void getSetAndroidEnabled() {
   assertThat(config.isAndroidEnabled(), is(false));
   config.setAndroidEnabled(true);
   assertThat(config.isAndroidEnabled(), is(true));
 }
 @Test
 public void getSetChromeDriverPath() {
   config.setChromeDriverPath("some path");
   assertThat(config.getChromeDriverPath(), is("some path"));
 }
 @Test
 public void shouldNotHaveChromeOptionsWhenAndroidIsNotEnabled() {
   config.setAndroidEnabled(false);
   final Capabilities capabilities = config.createCapabilities();
   assertThat(capabilities.getCapability(ChromeOptions.CAPABILITY), is(nullValue()));
 }
 @Test
 public void shouldHaveProxyInCapability() {
   final Capabilities capabilities = config.createCapabilities();
   assertThat(capabilities.getCapability(CapabilityType.PROXY), is(notNullValue()));
 }