net.serenitybdd.screenplay.targets.IFrameSwitcher Maven / Gradle / Ivy
package net.serenitybdd.screenplay.targets;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Optional;
import static java.util.Optional.empty;
class IFrameSwitcher {
private static final Logger LOGGER = LoggerFactory.getLogger(IFrameSwitcher.class);
private final static ThreadLocal frameSwitcher = new ThreadLocal<>();
private final HashMap> currentIFrames = new HashMap<>();
static synchronized IFrameSwitcher getInstance() {
IFrameSwitcher iFrameSwitcher = frameSwitcher.get();
if (iFrameSwitcher == null) {
iFrameSwitcher = new IFrameSwitcher();
frameSwitcher.set(iFrameSwitcher);
}
return iFrameSwitcher;
}
private IFrameSwitcher() {}
void switchToIFrame(WebDriver driver, final Target target) {
if (!currentIFrames.containsKey(driver)) {
currentIFrames.put(driver, empty());
}
Optional