io.github.bonigarcia.wdm.WebDriverManager Java Examples

The following examples show how to use io.github.bonigarcia.wdm.WebDriverManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoteWebDriverJupiterTest.java    From selenium-jupiter with Apache License 2.0 6 votes vote down vote up
@BeforeAll
static void setup() throws Exception {
    // Start hub
    GridLauncherV3.main(new String[] { "-role", "hub", "-port", "4444" });

    // Register Chrome in hub
    WebDriverManager.chromedriver().setup();
    GridLauncherV3.main(new String[] { "-role", "node", "-hub",
            "http://localhost:4444/grid/register", "-browser",
            "browserName=chrome", "-port", "5555" });

    // Register Firefox in hub
    WebDriverManager.firefoxdriver().setup();
    GridLauncherV3.main(new String[] { "-role", "node", "-hub",
            "http://localhost:4444/grid/register", "-browser",
            "browserName=firefox", "-port", "5556" });
}
 
Example #2
Source File: TemplateRemoteTest.java    From selenium-jupiter with Apache License 2.0 6 votes vote down vote up
@BeforeAll
static void setup() {
    // Start hub
    GridLauncherV3.main(new String[] { "-role", "hub", "-port", "4444" });

    // Register Chrome in hub
    WebDriverManager.chromedriver().setup();
    GridLauncherV3.main(new String[] { "-role", "node", "-hub",
            "http://localhost:4444/grid/register", "-browser",
            "browserName=chrome", "-port", "5555" });

    // Register Firefox in hub
    WebDriverManager.firefoxdriver().setup();
    GridLauncherV3.main(new String[] { "-role", "node", "-hub",
            "http://localhost:4444/grid/register", "-browser",
            "browserName=firefox", "-port", "5556" });

    // Register Chrome and Firefox in template
    Browser chrome = BrowserBuilder.chrome()
            .url("http://localhost:4444/wd/hub").build();
    Browser firefox = BrowserBuilder.firefox()
            .url("http://localhost:4444/wd/hub").build();
    seleniumExtension.addBrowsers(chrome);
    seleniumExtension.addBrowsers(firefox);
}
 
Example #3
Source File: StabilityTest.java    From webdrivermanager-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(NUM_THREADS);
    ExecutorService executorService = newFixedThreadPool(NUM_THREADS);

    for (int i = 0; i < NUM_THREADS; i++) {
        executorService.submit(() -> {
            try {
                WebDriverManager.chromedriver().setup();
                ChromeOptions options = new ChromeOptions();
                options.addArguments("--headless");
                WebDriver driver = new ChromeDriver(options);
                driver.get(
                        "https://bonigarcia.github.io/selenium-jupiter/");
                String title = driver.getTitle();
                System.out.println(title);
                driver.quit();
            } finally {
                latch.countDown();
            }
        });
    }

    latch.await();
    executorService.shutdown();
}
 
Example #4
Source File: LocalExecutionTest.java    From demo-java with MIT License 6 votes vote down vote up
@Test
public void localExecution() {
    // Options:
    //
    // 1. Specify location of driver
    // System.setProperty("webdriver.chrome.driver", "lib/drivers/chromedriver");
    //
    // 2. Add driver to PATH ENV
    //
    // 3. Use Driver manager:
    WebDriverManager.chromedriver().setup();

    // Start session (opens browser)
    WebDriver driver = new ChromeDriver();

    // Quit session (closes browser)
    driver.quit();
}
 
Example #5
Source File: DriverFactory.java    From java-maven-selenium with MIT License 6 votes vote down vote up
static WebDriver getDriver() {

        String browser = System.getenv("BROWSER");
        if (browser == null) {
            WebDriverManager.chromedriver().setup();
            return new ChromeDriver();
        }
        switch (browser)
        {
            case "IE":
                WebDriverManager.iedriver().setup();
                return new InternetExplorerDriver();
            case "EDGE":
                WebDriverManager.edgedriver().setup();
                return new EdgeDriver();
            case "FIREFOX":
                WebDriverManager.firefoxdriver().setup();
                return new FirefoxDriver();
            default:
                WebDriverManager.chromedriver().setup();
                return new ChromeDriver();

        }
    }
 
Example #6
Source File: Browser.java    From coteafs-selenium with Apache License 2.0 6 votes vote down vote up
private static void setupDriver(final WebDriverManager manager) throws MalformedURLException {
    final DriverSetting driver = appSetting().getDriver();
    if (!isNull(driver)) {
        if (isNotEmpty(driver.getVersion())) {
            manager.version(driver.getVersion());
        }
        if (isNotEmpty(driver.getExeUrl())) {
            manager.driverRepositoryUrl(new URL(driver.getExeUrl()));
        }
        if (driver.isForceCache()) {
            manager.forceCache();
        }
        if (driver.isForceDownload()) {
            manager.forceDownload();
        }
        if (isNotEmpty(driver.getPath())) {
            manager.targetPath(driver.getPath());
        }
    }
    manager.setup();
}
 
Example #7
Source File: BaseTest.java    From vaadin-app-layout with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() {
    Optional<String> version = WebDriverManager.chromedriver().getVersions().stream().max(String::compareTo);
    if (version.isPresent()) {
        WebDriverManager.chromedriver().version(version.get()).setup();
        driver = new ChromeDriver();
        WebDriverRunner.setWebDriver(driver);
    } else {
        throw new IllegalStateException("No Chromedriver found!");
    }
}
 
Example #8
Source File: AppiumDriverManager.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
private String getPathForChromeDriver(String id) throws IOException {
    int[] versionNamesArr = getChromeVersionsFor(id);
    if (versionNamesArr.length > 0) {
        int highestChromeVersion = Arrays.stream(versionNamesArr).max().getAsInt();
        String message = "ChromeDriver for Chrome version " + highestChromeVersion
                + "on device: " + id;
        LOGGER.info(message);
        WebDriverManager.chromedriver().version(String.valueOf(highestChromeVersion)).setup();
        return WebDriverManager.chromedriver().getBinaryPath();
    } else {
        return null;
    }
}
 
Example #9
Source File: EdgeVersionTest.java    From webdrivermanager with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    browserManager = WebDriverManager.getInstance(EdgeDriver.class);
    os = WIN;
    specificVersions = new String[] { "75.0.139.20", "76.0.183.0",
            "77.0.237.0", "78.0.277.0", "79.0.313.0", "80.0.361.111",
            "81.0.409.0", "82.0.459.1" };
}
 
Example #10
Source File: EdgeReadVersionTest.java    From webdrivermanager with Apache License 2.0 5 votes vote down vote up
@Test
public void edgeVersionsTest() {
    String[] expectedVersions = { "75.0.139.20", "76.0.183.0", "77.0.237.0",
            "78.0.277.0", "79.0.313.0", "80.0.361.111", "81.0.409.0",
            "82.0.459.1" };
    List<String> driverVersions = WebDriverManager.edgedriver()
            .getDriverVersions();

    log.debug("Expected edge versions: {}",
            Arrays.asList(expectedVersions));
    log.debug("Edge versions read from the repository: {}", driverVersions);

    assertThat(driverVersions, hasItems(expectedVersions));
}
 
Example #11
Source File: IExplorerVersionTest.java    From webdrivermanager with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    os = WIN;
    browserManager = WebDriverManager
            .getInstance(InternetExplorerDriver.class);
    specificVersions = new String[] { "2.39", "2.47" };
}
 
Example #12
Source File: SelenideMultiTest.java    From healenium-web with Apache License 2.0 5 votes vote down vote up
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    Configuration.timeout = 15000;

    WebDriverManager.chromedriver().setup();
    capabilities.setBrowserName("chrome");
    ChromeOptions options = new ChromeOptions();
    options.setHeadless(true);
    options.merge(capabilities);
    WebDriver wd = new ChromeDriver(options);
    return SelfHealingDriver.create(wd);
}
 
Example #13
Source File: StartingAppLocallyTest.java    From java-client with Apache License 2.0 5 votes vote down vote up
@Test public void startingAndroidAppWithCapabilitiesAndFlagsOnServerSideTest() {
    DesiredCapabilities serverCapabilities = new DesiredCapabilities();
    serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
    serverCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true);
    serverCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60);
    serverCapabilities.setCapability(MobileCapabilityType.APP, apiDemosApk().toAbsolutePath().toString());

    WebDriverManager chromeManager = chromedriver();
    chromeManager.setup();
    serverCapabilities.setCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE,
            chromeManager.getBinaryPath());

    AppiumServiceBuilder builder = new AppiumServiceBuilder()
            .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
            .withArgument(GeneralServerFlag.STRICT_CAPS).withCapabilities(serverCapabilities);

    DesiredCapabilities clientCapabilities = new DesiredCapabilities();
    clientCapabilities
        .setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis");
    clientCapabilities
        .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1");

    AndroidDriver<?> driver = new AndroidDriver<>(builder, clientCapabilities);
    try {
        Capabilities caps = driver.getCapabilities();

        assertEquals(MobilePlatform.ANDROID, caps.getCapability(MobileCapabilityType.PLATFORM_NAME));
        assertNotEquals(null, caps.getCapability(MobileCapabilityType.DEVICE_NAME));
    } finally {
        driver.quit();
    }
}
 
Example #14
Source File: WebDriverTypeTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
private static void testSetDriverExecutablePathViaAutomaticManager(WebDriverType type,
        Supplier<WebDriverManager> managerSupplier)
{
    WebDriverManager webDriverManager = mock(WebDriverManager.class);
    PowerMockito.mockStatic(WebDriverManager.class);
    when(managerSupplier.get()).thenReturn(webDriverManager);
    type.setDriverExecutablePath(Optional.empty());
    verify(webDriverManager).setup();
}
 
Example #15
Source File: BrowserFactoryTests.java    From aquality-selenium-java with Apache License 2.0 5 votes vote down vote up
private IBrowserFactory getCustomFactory() {
    return () -> {
        FirefoxSettings firefoxSettings = new FirefoxSettings(AqualityServices.get(ISettingsFile.class));
        WebDriverManager.firefoxdriver().setup();
        FirefoxDriver driver = new FirefoxDriver(firefoxSettings.getCapabilities().setHeadless(true));
        return new Browser(driver);
    };
}
 
Example #16
Source File: webdriver.java    From jbang with MIT License 5 votes vote down vote up
public static WebDriver setupDriver() {
  WebDriverManager.chromedriver().setup();
  ChromeOptions options = new ChromeOptions();
  options.addArguments("start-maximized"); 
  options.addArguments("enable-automation"); 
  options.addArguments("--no-sandbox"); 
  options.addArguments("--disable-infobars");
  options.addArguments("--disable-dev-shm-usage");
  options.addArguments("--disable-browser-side-navigation"); 
  options.addArguments("--disable-gpu");
  options.setPageLoadStrategy(PageLoadStrategy.NONE);
  WebDriver driver = new ChromeDriver(options);
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  return driver;
}
 
Example #17
Source File: WebDriverTest.java    From webdrivermanager with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebDriver() {
    WebDriverManager.getInstance(driverClass).setup();
    String binaryPath = WebDriverManager.getInstance(driverClass)
            .getBinaryPath();
    File binary = new File(binaryPath);
    assertTrue(binary.exists());
}
 
Example #18
Source File: StandaloneDriverFactory.java    From teasy with MIT License 5 votes vote down vote up
private WebDriver gecko(DesiredCapabilities customCaps, Platform platform) {
    DriverHolder.setDriverName(GECKO);
    WebDriverManager.firefoxdriver().setup();
    return new FirefoxDriver(
            new GeckoCaps(customCaps, this.alertBehaviour, platform).get()
    );
}
 
Example #19
Source File: ITCreateMultipleBuckets.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    baseUrl = "http://localhost:18080/nifi-registry";
    wait = new WebDriverWait(driver, 30);
}
 
Example #20
Source File: ITRenameBucket.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    baseUrl = "http://localhost:18080/nifi-registry";
    wait = new WebDriverWait(driver, 30);
}
 
Example #21
Source File: AbstractRoleSystemITest.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Start server.
 *
 * @throws Exception
 *             the exception
 */
@BeforeClass
static final synchronized public void startServer() throws Exception {
	System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver-0.13.0-linux64");
	if (!usingExternalServer) {
		CitizenIntelligenceAgencyServer.startTestServer();
	}
	WebDriverManager.getInstance(DriverManagerType.CHROME).setup();
}
 
Example #22
Source File: InteractiveTest.java    From webdrivermanager with Apache License 2.0 5 votes vote down vote up
@Test
public void testInteractive() {
    log.debug("Running interactive wdm with arguments: {}", argument);
    WebDriverManager.main(new String[] { argument });
    File binary = new File(driver);
    boolean exists = binary.exists();
    boolean delete = binary.delete();
    assertTrue(exists && delete);
    log.debug("Interactive test with {} OK", argument);
}
 
Example #23
Source File: ITDeleteSingleBucketCancel.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    baseUrl = "http://localhost:18080/nifi-registry";
    wait = new WebDriverWait(driver, 30);
}
 
Example #24
Source File: ITCreateBucket.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    baseUrl = "http://localhost:18080/nifi-registry";
    wait = new WebDriverWait(driver, 30);
}
 
Example #25
Source File: ITRenameBucketDuplicate.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    baseUrl = "http://localhost:18080/nifi-registry";
    wait = new WebDriverWait(driver, 30);
}
 
Example #26
Source File: ResolutionCacheTest.java    From webdrivermanager with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyTtl() {
    WebDriverManager.main(new String[] { "clear-resolution-cache" });
    chromedriver().ttl(0).setup();
    String binaryPath = chromedriver().getBinaryPath();
    File binary = new File(binaryPath);
    assertTrue(binary.exists());
}
 
Example #27
Source File: CurrentVersionTest.java    From webdrivermanager with Apache License 2.0 5 votes vote down vote up
@Test
public void testCurrentVersion() throws Exception {
    WebDriverManager browserManager = WebDriverManager
            .getInstance(driverManagerType);

    Method method = WebDriverManager.class
            .getDeclaredMethod("getCurrentVersion", URL.class);
    method.setAccessible(true);

    String currentVersion = (String) method.invoke(browserManager,
            new URL(url));

    assertThat(currentVersion, equalTo(expectedVersion));
}
 
Example #28
Source File: PropertiesTest.java    From webdrivermanager with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomProperties() {
    WebDriverManager chromedriver = WebDriverManager.chromedriver();
    chromedriver.config().setProperties("wdm-test.properties");
    chromedriver.setup();
    String binaryPath = chromedriver.getBinaryPath();
    File binary = new File(binaryPath);
    assertTrue(binary.exists());
}
 
Example #29
Source File: DownloadWebDriver.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private static WebDriverManager getInstance(DriverManagerType browser) {
    switch (browser) {
        case CHROME:
            return WebDriverManager.chromedriver();
        case FIREFOX:
            return new FirefoxDriverManagerCustom();
        default:
            throw new UnsupportedOperationException(
                    "Only Chrome and Firefox are currently supported.");
    }
}
 
Example #30
Source File: WebRtcFirefoxTest.java    From webdrivermanager-examples with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupClass() {
    WebDriverManager.firefoxdriver().setup();
}