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

com.codeborne.selenide.appium.AppiumClipboard Maven / Gradle / Ivy

There is a newer version: 7.5.1
Show newest version
package com.codeborne.selenide.appium;

import com.codeborne.selenide.Clipboard;
import com.codeborne.selenide.DefaultClipboard;
import com.codeborne.selenide.Driver;
import io.appium.java_client.clipboard.HasClipboard;

import java.util.Optional;

import static com.codeborne.selenide.impl.WebdriverUnwrapper.cast;

public class AppiumClipboard implements Clipboard {
  private final Driver driver;
  private final Clipboard defaultClipboard;

  public AppiumClipboard(Driver driver) {
    this.driver = driver;
    defaultClipboard = new DefaultClipboard(driver);
  }

  @Override
  public Driver driver() {
    return driver;
  }

  @Override
  public Clipboard object() {
    return this;
  }

  @Override
  public String getText() {
    return getWebDriver()
      .map(HasClipboard::getClipboardText)
      .orElseGet(defaultClipboard::getText);
  }

  @Override
  public void setText(String text) {
    Optional mobileDriver = getWebDriver();
    if (mobileDriver.isPresent()) {
      mobileDriver.get().setClipboardText(text);
    }
    else {
      defaultClipboard.setText(text);
    }
  }

  private Optional getWebDriver() {
    return cast(driver, HasClipboard.class);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy