/*
 * (C) Copyright 2020 Boni Garcia (http://bonigarcia.github.io/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package io.github.bonigarcia.wdm.test.chromium;

import static org.apache.commons.lang3.SystemUtils.IS_OS_MAC;
import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS;
import static org.assertj.core.api.Assumptions.assumeThat;

import java.io.File;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import io.github.bonigarcia.wdm.WebDriverManager;
import io.github.bonigarcia.wdm.test.base.BrowserTestParent;

/**
 * Test with Google Chromium browser.
 *
 * @author Boni Garcia
 * @since 3.8.0
 */
class ChromiumTest extends BrowserTestParent {

    @BeforeAll
    static void setupClass() {
        WebDriverManager.chromiumdriver().setup();
    }

    @BeforeEach
    void setupTest() {
        File chromiumPath = new File(getChromiumPath());
        assumeThat(chromiumPath).exists();

        ChromeOptions options = new ChromeOptions();
        options.setBinary(chromiumPath);
        driver = new ChromeDriver(options);
    }

    private String getChromiumPath() {
        if (IS_OS_WINDOWS) {
            String localAppDat = System.getenv("LOCALAPPDATA")
                    .replaceAll("\\\\", "\\\\\\\\");
            return localAppDat + "\\Chromium\\Application\\chrome.exe";
        } else {
            return IS_OS_MAC
                    ? "/Applications/Chromium.app/Contents/MacOS/Chromium"
                    : "/usr/bin/chromium-browser";
        }
    }

}

@@ -691,120 +691,103 @@
 tic 
-org.apache.commons.lang3.SystemUtils.IS_OS_MAC;%0Aimport static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS
+java.lang.invoke.MethodHandles.lookup;%0Aimport static org.assertj.core.api.Assertions.assertThat
 ;%0Aim
@@ -842,16 +842,65 @@
 umeThat;
+%0Aimport static org.slf4j.LoggerFactory.getLogger;
 %0A%0Aimport
@@ -909,17 +909,90 @@
 ava.
+n
 io.
-F
+f
 ile
+.Path;%0Aimport java.util.Optional;%0A%0Aimport org.junit.jupiter.api.AfterEach
 ;
-%0A
 %0Aimp
@@ -1065,24 +1065,97 @@
 BeforeEach;%0A
+import org.junit.jupiter.api.Test;%0Aimport org.openqa.selenium.WebDriver;%0A
 import org.o
@@ -1238,16 +1238,41 @@
 Options;
+%0Aimport org.slf4j.Logger;
 %0A%0Aimport
@@ -1318,69 +1318,8 @@
 ger;
-%0Aimport io.github.bonigarcia.wdm.test.base.BrowserTestParent;
 %0A%0A/*
@@ -1427,35 +1427,131 @@
 est 
-extends BrowserTestParent %7B
+%7B%0A%0A    final Logger log = getLogger(lookup().lookupClass());%0A%0A    WebDriver driver;%0A%0A    static Optional%3CPath%3E browserPath;
 %0A%0A  
@@ -1601,16 +1601,30 @@
 %0A       
+ browserPath =
  WebDriv
@@ -1654,21 +1654,30 @@
 r().
-setup
+getBrowserPath
 ();%0A    
 %7D%0A%0A 
@@ -1676,49 +1676,49 @@
     
-%7D%0A%0A
     
-@BeforeEach%0A    void setupTest() %7B
+assumeThat(browserPath).isPresent();%0A
 %0A   
@@ -1726,100 +1726,96 @@
     
-File chromiumPath = new File(getChromiumPath()
+WebDriverManager.chromiumdriver().setup(
 );%0A    
+%7D%0A%0A
     
-assumeThat(chromiumPath).exi
+@BeforeEach%0A    void setupTe
 st
-s
 ()
-;%0A
+ %7B
 %0A   
@@ -1894,20 +1894,34 @@
 ary(
-chromiumPath
+browserPath.get().toFile()
 );%0A 
@@ -1978,38 +1978,36 @@
     
-private String getChromiumPath
+@AfterEach%0A    void teardown
 () %7B
@@ -2023,21 +2023,22 @@
 if (
-IS_OS_WINDOWS
+driver != null
 ) %7B%0A
@@ -2053,58 +2053,22 @@
     
-String localAppDat = System.getenv(%22LOCALAPPDATA%22)
+driver.quit();
 %0A   
@@ -2076,306 +2076,355 @@
     
+%7D%0A
     
+%7D%0A%0A
     
-    .replaceAll(%22%5C%5C%5C%5C%22, %22%5C%5C%5C%5C%5C%5C%5C%5C%22);%0A            return localAppDat + %22%5C%5CChromium%5C%5CApplication%5C%5Cchrome.exe%22;%0A        %7D else %7B%0A            return IS_OS_MAC%0A                    ? %22/Applications/Chromium.app/Contents/MacOS/Chromium%22%0A                    : %22/usr/bin/chromium-browser%22;%0A        %7D
+@Test%0A    void test() %7B%0A        String sutUrl = %22https://github.com/bonigarcia/webdrivermanager%22;%0A        driver.get(sutUrl);%0A        String title = driver.getTitle();%0A        log.debug(%22The title of %7B%7D is %7B%7D%22, sutUrl, title);%0A%0A        assertThat(title)%0A                .contains(%22Automated driver management for Selenium WebDriver%22);
 %0A   

Use assumption based on browser path in Chromium test