use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class DriverHelper method dragAndDrop.
/**
* Drags and drops element to specified place.
*
* @param from
* - element to drag.
* @param to
* - element to drop to.
*/
public void dragAndDrop(final ExtendedWebElement from, final ExtendedWebElement to) {
if (from.isElementPresent() && to.isElementPresent()) {
WebDriver drv = getDriver();
if (!drv.toString().contains("safari")) {
Actions builder = new Actions(drv);
Action dragAndDrop = builder.clickAndHold(from.getElement()).moveToElement(to.getElement()).release(to.getElement()).build();
dragAndDrop.perform();
} else {
WebElement LocatorFrom = from.getElement();
WebElement LocatorTo = to.getElement();
String xto = Integer.toString(LocatorTo.getLocation().x);
String yto = Integer.toString(LocatorTo.getLocation().y);
((JavascriptExecutor) driver).executeScript("function simulate(f,c,d,e){var b,a=null;for(b in eventMatchers)if(eventMatchers[b].test(c)){a=b;break}if(!a)return!1;document.createEvent?(b=document.createEvent(a),a==\"HTMLEvents\"?b.initEvent(c,!0,!0):b.initMouseEvent(c,!0,!0,document.defaultView,0,d,e,d,e,!1,!1,!1,!1,0,null),f.dispatchEvent(b)):(a=document.createEventObject(),a.detail=0,a.screenX=d,a.screenY=e,a.clientX=d,a.clientY=e,a.ctrlKey=!1,a.altKey=!1,a.shiftKey=!1,a.metaKey=!1,a.button=1,f.fireEvent(\"on\"+c,a));return!0} var eventMatchers={HTMLEvents:/^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,MouseEvents:/^(?:click|dblclick|mouse(?:down|up|over|move|out))$/}; " + "simulate(arguments[0],\"mousedown\",0,0); simulate(arguments[0],\"mousemove\",arguments[1],arguments[2]); simulate(arguments[0],\"mouseup\",arguments[1],arguments[2]); ", LocatorFrom, xto, yto);
}
Messager.ELEMENTS_DRAGGED_AND_DROPPED.info(from.getName(), to.getName());
} else {
Messager.ELEMENTS_NOT_DRAGGED_AND_DROPPED.error(from.getNameWithLocator(), to.getNameWithLocator());
}
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class DriverHelper method findExtendedWebElements.
/**
* Find List of Extended Web Elements on page using By.
*
* @param by
* Selenium By locator
* @param timeout
* Timeout to find
* @return List of ExtendedWebElement.
*/
public List<ExtendedWebElement> findExtendedWebElements(final By by, long timeout) {
List<ExtendedWebElement> extendedWebElements = new ArrayList<ExtendedWebElement>();
List<WebElement> webElements = new ArrayList<WebElement>();
String name = "undefined";
if (!waitUntil(ExpectedConditions.presenceOfElementLocated(by), timeout)) {
Messager.ELEMENT_NOT_FOUND.info(name);
return extendedWebElements;
}
webElements = getDriver().findElements(by);
int i = 1;
for (WebElement element : webElements) {
try {
name = element.getText();
} catch (Exception e) {
/* do nothing and keep 'undefined' for control name */
}
ExtendedWebElement tempElement = new ExtendedWebElement(element, name);
tempElement.setBy(tempElement.generateByForList(by, i));
extendedWebElements.add(tempElement);
i++;
}
return extendedWebElements;
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class LocatingListHandler method invoke.
public Object invoke(Object object, Method method, Object[] objects) throws Throwable {
// Hotfix for huge and expected regression in carina: we lost managed
// time delays with lists manipulations
// Temporary we are going to restore explicit waiter here with hardcoded
// timeout before we find better solution
// Pros: super fast regression issue which block UI execution
// Cons: there is no way to manage timeouts in this places
// if (!waitUntil(ExpectedConditions.or(ExpectedConditions.presenceOfElementLocated(by),
// ExpectedConditions.visibilityOfElementLocated(by)))) {
// LOGGER.error("List is not present: " + by);
// }
List<WebElement> elements = null;
try {
elements = locator.findElements();
} catch (StaleElementReferenceException | InvalidElementStateException e) {
LOGGER.debug("catched StaleElementReferenceException: ", e);
elements = driver.findElements(by);
}
List<ExtendedWebElement> extendedWebElements = null;
int i = 0;
if (elements != null) {
extendedWebElements = new ArrayList<ExtendedWebElement>();
for (WebElement element : elements) {
InvocationHandler handler = new LocatingListsElementHandler(element, locator);
WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[] { WebElement.class, WrapsElement.class, Locatable.class }, handler);
ExtendedWebElement webElement = new ExtendedWebElement(proxy, name + i, by);
Field searchContextField = locator.getClass().getDeclaredField("searchContext");
searchContextField.setAccessible(true);
webElement.setSearchContext((SearchContext) searchContextField.get(locator));
extendedWebElements.add(webElement);
i++;
}
}
try {
return method.invoke(extendedWebElements, objects);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class DivisionElementExtractor method getElementsByCoordinates.
@Override
public ExtendedWebElement getElementsByCoordinates(int x, int y) {
String elementName = String.format("Element founded by x:%d - y:%d", x, y);
WebDriver driver = getDriver();
List<WebElement> elements = getEndLevelElements(driver);
WebElement tempElement;
int index = 0;
int isLower;
Rectangle tempRect;
while (elements.size() != 1) {
index = (int) (Math.round(elements.size() / 2f));
tempElement = elements.get(index);
tempRect = getRect(tempElement);
isLower = isLower(tempRect, y);
LOGGER.debug("Is Lower: " + isLower);
if (isInside(tempRect, x, y) || isLower == 0) {
break;
}
if (isLower == 1) {
elements = elements.subList(index, elements.size());
} else {
elements = elements.subList(0, index);
}
}
LOGGER.debug("Index: " + index);
if (elements.size() == 1) {
return generateExtenedElement(elements, elementName);
}
return generateExtenedElement(checkBoundaryElements(elements, x, y, index), elementName);
}
use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.
the class L10Nparser method checkMultipleLocalization.
/**
* check MultipleLocalization
*
* @param localizationCheckList
* - ExtendedWebElement[] should be set on required page with all
* needed public elements
* @param timeout - timeout for element presence waiting.
* @param skipPunctuationAndNumbers - if true - there will be no numbers and tricky punctuation in l10n values
* @return boolean
*/
public static boolean checkMultipleLocalization(ExtendedWebElement[] localizationCheckList, int timeout, boolean skipPunctuationAndNumbers) {
boolean ret = true;
String returnAssertErrorMsg = "";
assertErrorMsg = "";
for (ExtendedWebElement elem : localizationCheckList) {
if (!checkLocalizationText(elem, true, timeout, skipPunctuationAndNumbers)) {
ret = false;
returnAssertErrorMsg = returnAssertErrorMsg + " \n" + assertErrorMsg;
}
}
assertErrorMsg = returnAssertErrorMsg;
return ret;
}
Aggregations