com.codeborne.selenide.appium.SelenideAppiumTargetLocator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenide-appium Show documentation
Show all versions of selenide-appium Show documentation
Selenide = concise API for Selenium WebDriver
package com.codeborne.selenide.appium;
import com.codeborne.selenide.Driver;
import com.codeborne.selenide.logevents.SelenideLogger;
import org.openqa.selenium.ContextAware;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Set;
import static com.codeborne.selenide.impl.WebdriverUnwrapper.cast;
@ParametersAreNonnullByDefault
public class SelenideAppiumTargetLocator {
private final Driver driver;
SelenideAppiumTargetLocator(Driver driver) {
this.driver = driver;
}
public void context(String contextName) {
SelenideLogger.run("set context", contextName, () -> {
cast(driver, ContextAware.class)
.map(contextAware -> contextAware.context(contextName))
.orElseThrow(() -> new UnsupportedOperationException("Context not found" + contextName));
});
}
public Set getContextHandles() {
return cast(driver, ContextAware.class)
.map(ContextAware::getContextHandles)
.orElseThrow(() -> new UnsupportedOperationException("Cannot get contexts from mobile driver"));
}
public String getCurrentContext() {
return cast(driver, ContextAware.class)
.map(ContextAware::getContext)
.orElseThrow(() -> new UnsupportedOperationException("Cannot get current context from mobile driver"));
}
}