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

com.codeborne.selenide.appium.commands.AppiumDoubleClick Maven / Gradle / Ivy

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

import com.codeborne.selenide.ClickOptions;
import com.codeborne.selenide.Command;
import com.codeborne.selenide.Driver;
import com.codeborne.selenide.SelenideElement;
import com.codeborne.selenide.commands.DoubleClick;
import com.codeborne.selenide.impl.WebElementSource;
import org.openqa.selenium.WebElement;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import static com.codeborne.selenide.ClickMethod.JS;
import static com.codeborne.selenide.appium.WebdriverUnwrapper.isMobile;
import static com.codeborne.selenide.commands.Util.firstOf;

@ParametersAreNonnullByDefault
public class AppiumDoubleClick implements Command {

  private final DoubleClick defaultDoubleClick = new DoubleClick();

  @Override
  @Nonnull
  public SelenideElement execute(SelenideElement proxy, WebElementSource locator, @Nullable Object[] args) {
    if (!isMobile(locator.driver())) {
      return defaultDoubleClick.execute(proxy, locator, args);
    }
    Driver driver = locator.driver();
    WebElement webElement = findElement(locator);
    ClickOptions clickOptions = options(args);
    if (clickOptions.clickMethod() == JS) {
      throw new UnsupportedOperationException("Click using JavaScript is not supported in mobile");
    }
    if (clickOptions.timeout() != null) {
      throw new UnsupportedOperationException("Click timeout is not supported in mobile");
    }
    else {
      driver.actions().doubleClick(webElement);
    }
    return proxy;
  }

  private ClickOptions options(@Nullable Object[] args) {
    return (args == null || args.length == 0) ?
      ClickOptions.usingDefaultMethod() :
      firstOf(args);
  }

  @Nonnull
  @CheckReturnValue
  protected WebElement findElement(WebElementSource locator) {
    return locator.getWebElement();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy