All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.bonigarcia.wdm.EdgeDriverManager Maven / Gradle / Ivy

Go to download

Automated driver management and other helper features for Selenium WebDriver in Java

There is a newer version: 5.9.2
Show newest version
/*
 * (C) Copyright 2015 Boni Garcia (http://bonigarcia.github.io/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 */
package io.github.bonigarcia.wdm;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

/**
 * Manager for Microsoft Edge.
 *
 * @author Boni Garcia ([email protected])
 * @since 1.3.0
 */
public class EdgeDriverManager extends BrowserManager {

    public static synchronized BrowserManager getInstance() {
        if (instance == null
                || !instance.getClass().equals(EdgeDriverManager.class)) {
            instance = new EdgeDriverManager();
        }
        return instance;
    }

    @Override
    public List getDrivers() throws Exception {
        listVersions = new ArrayList<>();
        List urlList = new ArrayList<>();

        String edgeDriverUrl = WdmConfig.getString("wdm.edgeDriverUrl");
        log.debug("Reading {} to find out the latest version of Edge driver",
                edgeDriverUrl);

        int timeout = (int) TimeUnit.SECONDS
                .toMillis(WdmConfig.getInt("wdm.timeout"));

        try (InputStream in = httpClient
                .execute(new WdmHttpClient.Get(edgeDriverUrl, timeout))
                .getContent()) {
            Document doc = Jsoup.parse(in, null, "");

            Elements downloadLink = doc
                    .select("ul.driver-downloads li.driver-download > a");
            Elements versionParagraph = doc.select(
                    "ul.driver-downloads li.driver-download p.driver-download__meta");

            for (int i = 0; i < downloadLink.size(); i++) {
                String[] version = versionParagraph.get(i).text().split(" ");
                listVersions.add(version[1]);
                urlList.add(new URL(downloadLink.get(i).attr("href")));
            }

            return urlList;
        }
    }

    @Override
    protected String getExportParameter() {
        return WdmConfig.getString("wdm.edgeExport");
    }

    @Override
    protected String getDriverVersionKey() {
        return "wdm.edgeVersion";
    }

    @Override
    protected String getDriverUrlKey() {
        return "wdm.edgeDriverUrl";
    }

    @Override
    protected List getDriverName() {
        return Arrays.asList("MicrosoftWebDriver");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy