com.applitools.eyes.EyesKeyboard Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eyes-selenium-java Show documentation
Show all versions of eyes-selenium-java Show documentation
Applitools Eyes SDK for Selenium Java WebDriver
/*
* Applitools SDK for Selenium integration.
*/
package com.applitools.eyes;
import com.applitools.utils.ArgumentGuard;
import org.openqa.selenium.interactions.Keyboard;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebElement;
/**
* A wrapper class for Selenium's Keyboard interface, so we can record keyboard
* events.
*/
class EyesKeyboard implements Keyboard {
private final Logger logger;
private final EyesWebDriver eyesDriver;
private final Keyboard keyboard;
public EyesKeyboard(Logger logger, EyesWebDriver eyesDriver,
Keyboard keyboard) {
ArgumentGuard.notNull(logger, "logger");
ArgumentGuard.notNull(eyesDriver, "eyesDriver");
ArgumentGuard.notNull(keyboard, "keyboard");
this.logger = logger;
this.eyesDriver = eyesDriver;
this.keyboard = keyboard;
}
public void sendKeys(CharSequence... charSequences) {
Region control = Region.EMPTY;
// We first find the active element to get the region
WebElement activeElement = eyesDriver.switchTo().activeElement();
if (activeElement instanceof RemoteWebElement) {
activeElement = new EyesRemoteWebElement(logger, eyesDriver,
(RemoteWebElement) activeElement);
control = ((EyesRemoteWebElement)activeElement).getBounds();
}
for(CharSequence keys : charSequences) {
String text = String.valueOf(keys);
eyesDriver.getEyes().addTextTrigger(control, text);
}
keyboard.sendKeys(charSequences);
}
public void pressKey(CharSequence keyToPress) {
keyboard.pressKey(keyToPress);
}
public void releaseKey(CharSequence keyToRelease) {
keyboard.releaseKey(keyToRelease);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy