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

com.testvagrant.optimus.devicemanager.BrowserstackDeviceManager Maven / Gradle / Ivy

Go to download

Optimus Lite API to manage test devices and create appium driver based on platform

There is a newer version: 0.1.7-beta
Show newest version
package com.testvagrant.optimus.devicemanager;

import com.testvagrant.optimus.core.exceptions.NoSuchDeviceException;
import com.testvagrant.optimus.core.models.OptimusSupportedPlatforms;
import com.testvagrant.optimus.core.models.TargetDetails;
import com.testvagrant.optimus.core.remote.CloudConfigBuilder;
import com.testvagrant.optimus.core.remote.browserstack.BrowserStackDeviceClient;

import java.util.List;
import java.util.function.Predicate;

public class BrowserstackDeviceManager {

  private final List devices;
  private static BrowserstackDeviceManager deviceManager;
  private OptimusSupportedPlatforms platform;

  private BrowserstackDeviceManager(OptimusSupportedPlatforms platform) {
    BrowserStackDeviceClient browserStackClient =
        new BrowserStackDeviceClient(new CloudConfigBuilder().build());

    devices =
        platform.equals(OptimusSupportedPlatforms.IOS)
            ? browserStackClient.getIosDevices()
            : browserStackClient.getAndroidDevices();
  }

  public static BrowserstackDeviceManager getInstance(OptimusSupportedPlatforms platform) {
    return new BrowserstackDeviceManager(platform);
  }

  public synchronized TargetDetails getDevice(Predicate deviceFilterPredicate) {
    return devices.stream()
        .filter(deviceFilterPredicate)
        .findFirst()
        .orElseThrow(NoSuchDeviceException::new);
  }

  public TargetDetails getDevice() {
    return getDevice(platformQueryPredicate());
  }

  protected Predicate platformQueryPredicate() {
    return TargetDetails -> !TargetDetails.getName().isEmpty();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy