Browser

mail@pastecode.io avatar
unknown
javascript
3 years ago
2.3 kB
5
Indexable
Never
/**
     * Ham nay dung de detect trinh duyet dung de test
     */
    public WebDriver getBrowser(String browserName) {
        switch (browserName) {
            case Constants.FIREFOX:
                WebDriverManager.firefoxdriver().setup();
                driver = new FirefoxDriver();
                break;

            case Constants.HEADLESS_FIREFOX:
                WebDriverManager.firefoxdriver().setup();
                final FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.addArguments("window-size=1920x1080");
                driver = new FirefoxDriver(firefoxOptions);
                break;

            case Constants.CHROME:
                WebDriverManager.chromedriver().setup();
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.addArguments("use-fake-device-for-media-stream");
                chromeOptions.addArguments("use-fake-ui-for-media-stream");
                Map<String, Object> prefs = new HashMap<String, Object>();
                prefs.put("download.default_directory",System.getProperty("user.dir"));
                chromeOptions.setExperimentalOption("prefs", prefs);
                driver = new ChromeDriver(chromeOptions);
                break;

            case Constants.HEADLESS_CHROME:
                WebDriverManager.chromedriver().setup();
                chromeOptions = new ChromeOptions();
                chromeOptions.addArguments("--headless");
                chromeOptions.addArguments("window-size=1920x1080");
                chromeOptions.addArguments("allow-file-access-from-files");
                chromeOptions.addArguments("use-fake-device-for-media-stream");
                chromeOptions.addArguments("use-fake-ui-for-media-stream");
                chromeOptions.addArguments("--no-sandbox");
                chromeOptions.addArguments("--disable-dev-shm-usage");
                driver = new ChromeDriver(chromeOptions);
                break;

            default:
                WebDriverManager.chromedriver().setup();
                driver = new ChromeDriver();
                break;
        }

        driver.get(Constants.URL);
        driver.manage().window().maximize();
        return driver;
    }