use of org.openqa.selenium.remote.LocalFileDetector in project carina by qaprosoft.
the class ExtendedWebElement method overrideAction.
// single place for all supported UI actions in carina core
private Object overrideAction(ACTION_NAME actionName, Object... inputArgs) {
Object output = executeAction(actionName, new ActionSteps() {
@Override
public void doClick() {
try {
DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));
try {
element.click();
} catch (ElementNotInteractableException e) {
// TODO: investigate if more exceptions should be catched
// not visible so we can't interact using selenium or actions
LOGGER.warn("Trying to do click by JavascriptExecutor because element '" + getNameWithLocator() + "' is not visible...");
JavascriptExecutor executor = (JavascriptExecutor) getDriver();
executor.executeScript("arguments[0].click();", element);
}
} catch (WebDriverException e) {
if (e != null && (e.getMessage().contains("Other element would receive the click:"))) {
LOGGER.warn("Trying to do click by Actions due to the: " + e.getMessage());
Actions actions = new Actions(getDriver());
actions.moveToElement(element).click().perform();
} else {
throw e;
}
}
}
@Override
public // click for mobile devices
void doTap() {
DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));
element.click();
}
@Override
public void doDoubleClick() {
DriverListener.setMessages(Messager.ELEMENT_DOUBLE_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_DOUBLE_CLICKED.getMessage(getNameWithLocator()));
WebDriver drv = getDriver();
Actions action = new Actions(drv);
action.moveToElement(element).doubleClick(element).build().perform();
}
@Override
public void doHover(Integer xOffset, Integer yOffset) {
DriverListener.setMessages(Messager.ELEMENT_HOVERED.getMessage(getName()), Messager.ELEMENT_NOT_HOVERED.getMessage(getNameWithLocator()));
WebDriver drv = getDriver();
Actions action = new Actions(drv);
if (xOffset != null && yOffset != null) {
action.moveToElement(element, xOffset, yOffset).build().perform();
} else {
action.moveToElement(element).build().perform();
}
}
@Override
public void doSendKeys(Keys keys) {
DriverListener.setMessages(Messager.KEYS_SEND_TO_ELEMENT.getMessage(keys.toString(), getName()), Messager.KEYS_NOT_SEND_TO_ELEMENT.getMessage(keys.toString(), getNameWithLocator()));
element.sendKeys(keys);
}
@Override
public void doType(String text) {
final String decryptedText = cryptoTool.decryptByPattern(text, CRYPTO_PATTERN);
/* if (!element.getText().isEmpty()) {
DriverListener.setMessages(Messager.KEYS_CLEARED_IN_ELEMENT.getMessage(getName()),
Messager.KEYS_NOT_CLEARED_IN_ELEMENT.getMessage(getNameWithLocator()));
element.clear();
}
*/
DriverListener.setMessages(Messager.KEYS_CLEARED_IN_ELEMENT.getMessage(getName()), Messager.KEYS_NOT_CLEARED_IN_ELEMENT.getMessage(getNameWithLocator()));
element.clear();
String textLog = (!decryptedText.equals(text) ? "********" : text);
DriverListener.setMessages(Messager.KEYS_SEND_TO_ELEMENT.getMessage(textLog, getName()), Messager.KEYS_NOT_SEND_TO_ELEMENT.getMessage(textLog, getNameWithLocator()));
element.sendKeys(decryptedText);
}
@Override
public void doAttachFile(String filePath) {
final String decryptedText = cryptoTool.decryptByPattern(filePath, CRYPTO_PATTERN);
String textLog = (!decryptedText.equals(filePath) ? "********" : filePath);
DriverListener.setMessages(Messager.FILE_ATTACHED.getMessage(textLog, getName()), Messager.FILE_NOT_ATTACHED.getMessage(textLog, getNameWithLocator()));
((JavascriptExecutor) getDriver()).executeScript("arguments[0].style.display = 'block';", element);
((RemoteWebDriver) castDriver(getDriver())).setFileDetector(new LocalFileDetector());
element.sendKeys(decryptedText);
}
@Override
public String doGetText() {
String text = element.getText();
LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Text", text, getName()));
return text;
}
@Override
public Point doGetLocation() {
Point point = element.getLocation();
LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Location", point.toString(), getName()));
return point;
}
@Override
public Dimension doGetSize() {
Dimension dim = element.getSize();
LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Size", dim.toString(), getName()));
return dim;
}
@Override
public String doGetAttribute(String name) {
String attribute = element.getAttribute(name);
LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage(name, attribute, getName()));
return attribute;
}
@Override
public void doRightClick() {
DriverListener.setMessages(Messager.ELEMENT_RIGHT_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_RIGHT_CLICKED.getMessage(getNameWithLocator()));
WebDriver drv = getDriver();
Actions action = new Actions(drv);
action.moveToElement(element).contextClick(element).build().perform();
}
@Override
public void doCheck() {
DriverListener.setMessages(Messager.CHECKBOX_CHECKED.getMessage(getName()), null);
boolean isSelected = element.isSelected();
if (element.getAttribute("checked") != null) {
isSelected |= element.getAttribute("checked").equalsIgnoreCase("true");
}
if (!isSelected) {
click();
}
}
@Override
public void doUncheck() {
DriverListener.setMessages(Messager.CHECKBOX_UNCHECKED.getMessage(getName()), null);
boolean isSelected = element.isSelected();
if (element.getAttribute("checked") != null) {
isSelected |= element.getAttribute("checked").equalsIgnoreCase("true");
}
if (isSelected) {
click();
}
}
@Override
public boolean doIsChecked() {
boolean res = element.isSelected();
if (element.getAttribute("checked") != null) {
res |= element.getAttribute("checked").equalsIgnoreCase("true");
}
return res;
}
@Override
public boolean doSelect(String text) {
final String decryptedSelectText = cryptoTool.decryptByPattern(text, CRYPTO_PATTERN);
String textLog = (!decryptedSelectText.equals(text) ? "********" : text);
DriverListener.setMessages(Messager.SELECT_BY_TEXT_PERFORMED.getMessage(textLog, getName()), Messager.SELECT_BY_TEXT_NOT_PERFORMED.getMessage(textLog, getNameWithLocator()));
final Select s = new Select(getCachedElement());
// [VD] do not use selectByValue as modern controls could have only visible value without value
s.selectByVisibleText(decryptedSelectText);
return true;
}
@Override
public boolean doSelectValues(String[] values) {
boolean result = true;
for (String value : values) {
if (!select(value)) {
result = false;
}
}
return result;
}
@Override
public boolean doSelectByMatcher(BaseMatcher<String> matcher) {
DriverListener.setMessages(Messager.SELECT_BY_MATCHER_TEXT_PERFORMED.getMessage(matcher.toString(), getName()), Messager.SELECT_BY_MATCHER_TEXT_NOT_PERFORMED.getMessage(matcher.toString(), getNameWithLocator()));
final Select s = new Select(getCachedElement());
String fullTextValue = null;
for (WebElement option : s.getOptions()) {
if (matcher.matches(option.getText())) {
fullTextValue = option.getText();
break;
}
}
s.selectByVisibleText(fullTextValue);
return true;
}
@Override
public boolean doSelectByPartialText(String partialSelectText) {
DriverListener.setMessages(Messager.SELECT_BY_TEXT_PERFORMED.getMessage(partialSelectText, getName()), Messager.SELECT_BY_TEXT_NOT_PERFORMED.getMessage(partialSelectText, getNameWithLocator()));
final Select s = new Select(getCachedElement());
String fullTextValue = null;
for (WebElement option : s.getOptions()) {
if (option.getText().contains(partialSelectText)) {
fullTextValue = option.getText();
break;
}
}
s.selectByVisibleText(fullTextValue);
return true;
}
@Override
public boolean doSelectByIndex(int index) {
DriverListener.setMessages(Messager.SELECT_BY_INDEX_PERFORMED.getMessage(String.valueOf(index), getName()), Messager.SELECT_BY_INDEX_NOT_PERFORMED.getMessage(String.valueOf(index), getNameWithLocator()));
final Select s = new Select(getCachedElement());
s.selectByIndex(index);
return true;
}
@Override
public String doGetSelectedValue() {
final Select s = new Select(getCachedElement());
return s.getAllSelectedOptions().get(0).getText();
}
@Override
public List<String> doGetSelectedValues() {
final Select s = new Select(getCachedElement());
List<String> values = new ArrayList<String>();
for (WebElement we : s.getAllSelectedOptions()) {
values.add(we.getText());
}
return values;
}
}, inputArgs);
return output;
}
use of org.openqa.selenium.remote.LocalFileDetector in project elastest-instrumentation-manager by elastest.
the class EimPluginBaseTest method installElasTestPlugin.
protected void installElasTestPlugin(WebDriver webDriver) throws IOException {
int secondsTimeout = 60;
// Install plugin
log.info("Installing plugin from: {}", pluginPath);
By inputFileName = By.name("name");
WebElement uploadFile = webDriver.findElement(inputFileName);
((RemoteWebElement) uploadFile).setFileDetector(new LocalFileDetector());
uploadFile.sendKeys(pluginPath);
By uploadButton = By.xpath("//button[contains(string(), 'Upload')]");
webDriver.findElement(uploadButton).click();
// Check the plugin installation is ok
log.info("Checking installation status");
boolean pluginAlreadyInstalled = false;
try {
String installationStatusXpath = "//table/tbody/tr/td[contains(string(), 'Success')]";
getElementByXpath(webDriver, ExpectedConditionsEnum.VISIBILITY_OF_ELEMENT_LOCATED, installationStatusXpath, secondsTimeout);
} catch (TimeoutException te) {
String alreadyInstalledMessageXpath = "//table/tbody/tr/td[contains(string(), 'elastest plugin is already installed')]";
getElementByXpath(webDriver, ExpectedConditionsEnum.VISIBILITY_OF_ELEMENT_LOCATED, alreadyInstalledMessageXpath, secondsTimeout);
pluginAlreadyInstalled = true;
}
if (pluginAlreadyInstalled) {
navigateTo(webDriver, jenkinsRestartRelPath);
By yesButton = By.xpath("//button[contains(string(), 'Yes')]");
webDriver.findElement(yesButton).click();
// wait for login form
getElementById(webDriver, ExpectedConditionsEnum.VISIBILITY_OF_ELEMENT_LOCATED, "j_username", 180);
loginOnJenkins(webDriver);
}
log.info("Plugin installation finished");
log.info("Navigate to main page");
By homeLink = By.linkText("Jenkins");
webDriver.findElement(homeLink).click();
}
use of org.openqa.selenium.remote.LocalFileDetector in project muikku by otavanopisto.
the class AbstractUITest method createSauceWebDriver.
protected RemoteWebDriver createSauceWebDriver() throws MalformedURLException {
final DesiredCapabilities capabilities = new DesiredCapabilities();
final String seleniumVersion = System.getProperty("it.selenium.version");
final String browser = getBrowser();
final String browserVersion = getBrowserVersion();
final String browserResolution = getBrowserResolution();
final String platform = getSaucePlatform();
capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
capabilities.setCapability(CapabilityType.VERSION, browserVersion);
capabilities.setCapability(CapabilityType.PLATFORM, platform);
capabilities.setCapability("name", getClass().getSimpleName() + ':' + testName.getMethodName());
capabilities.setCapability("tags", Arrays.asList(String.valueOf(getTestStartTime())));
capabilities.setCapability("build", getProjectVersion());
capabilities.setCapability("video-upload-on-pass", false);
capabilities.setCapability("capture-html", true);
capabilities.setCapability("timeZone", "Universal");
capabilities.setCapability("seleniumVersion", seleniumVersion);
if (!StringUtils.isBlank(browserResolution)) {
capabilities.setCapability("screenResolution", browserResolution);
}
if (getSauceTunnelId() != null) {
capabilities.setCapability("tunnel-identifier", getSauceTunnelId());
}
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(String.format("http://%s:%s@ondemand.saucelabs.com:80/wd/hub", getSauceUsername(), getSauceAccessKey())), capabilities);
remoteWebDriver.setFileDetector(new LocalFileDetector());
return remoteWebDriver;
}
Aggregations