How to use doAttachFile method of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement.doAttachFile

Source:ExtendedWebElement.java Github

copy

Full Screen

...1147 1148 void doHover(Integer xOffset, Integer yOffset);1149 void doType(String text);1150 void doSendKeys(Keys keys);1151 void doAttachFile(String filePath);1152 void doCheck();1153 void doUncheck();1154 1155 boolean doIsChecked();1156 1157 String doGetText();1158 Point doGetLocation();1159 Dimension doGetSize();1160 String doGetAttribute(String name);1161 boolean doSelect(String text);1162 boolean doSelectValues(final String[] values);1163 boolean doSelectByMatcher(final BaseMatcher<String> matcher);1164 boolean doSelectByPartialText(final String partialSelectText);1165 boolean doSelectByIndex(final int index);1166 1167 String doGetSelectedValue();1168 1169 List<String> doGetSelectedValues();1170 }1171 private Object executeAction(ACTION_NAME actionName, ActionSteps actionSteps, Object... inputArgs) {1172 Object result = null;1173 switch (actionName) {1174 case CLICK:1175 actionSteps.doClick();1176 break;1177 case CLICK_BY_JS:1178 actionSteps.doClickByJs();1179 break;1180 case CLICK_BY_ACTIONS:1181 actionSteps.doClickByActions();1182 break;1183 case DOUBLE_CLICK:1184 actionSteps.doDoubleClick();1185 break;1186 case HOVER:1187 actionSteps.doHover((Integer) inputArgs[0], (Integer) inputArgs[1]);1188 break;1189 case RIGHT_CLICK:1190 actionSteps.doRightClick();1191 break;1192 case GET_TEXT:1193 result = actionSteps.doGetText();1194 break;1195 case GET_LOCATION:1196 result = actionSteps.doGetLocation();1197 break;1198 case GET_SIZE:1199 result = actionSteps.doGetSize();1200 break;1201 case GET_ATTRIBUTE:1202 result = actionSteps.doGetAttribute((String) inputArgs[0]);1203 break;1204 case SEND_KEYS:1205 actionSteps.doSendKeys((Keys) inputArgs[0]);1206 break;1207 case TYPE:1208 actionSteps.doType((String) inputArgs[0]);1209 break;1210 case ATTACH_FILE:1211 actionSteps.doAttachFile((String) inputArgs[0]);1212 break;1213 case CHECK:1214 actionSteps.doCheck();1215 break;1216 case UNCHECK:1217 actionSteps.doUncheck();1218 break;1219 case IS_CHECKED:1220 result = actionSteps.doIsChecked();1221 break;1222 case SELECT:1223 result = actionSteps.doSelect((String) inputArgs[0]);1224 break;1225 case SELECT_VALUES:1226 result = actionSteps.doSelectValues((String[]) inputArgs);1227 break;1228 case SELECT_BY_MATCHER:1229 result = actionSteps.doSelectByMatcher((BaseMatcher<String>) inputArgs[0]);1230 break;1231 case SELECT_BY_PARTIAL_TEXT:1232 result = actionSteps.doSelectByPartialText((String) inputArgs[0]);1233 break;1234 case SELECT_BY_INDEX:1235 result = actionSteps.doSelectByIndex((int) inputArgs[0]);1236 break;1237 case GET_SELECTED_VALUE:1238 result = actionSteps.doGetSelectedValue();1239 break;1240 case GET_SELECTED_VALUES:1241 result = actionSteps.doGetSelectedValues();1242 break;1243 default:1244 Assert.fail("Unsupported UI action name" + actionName.toString());1245 break;1246 }1247 return result;1248 }1249 /**1250 * doAction on element.1251 *1252 * @param actionName1253 * ACTION_NAME1254 * @param timeout1255 * long1256 * @param waitCondition1257 * to check element conditions before action1258 * @return1259 * Object1260 */1261 private Object doAction(ACTION_NAME actionName, long timeout, ExpectedCondition<?> waitCondition) {1262 // [VD] do not remove null args otherwise all actions without arguments will be broken!1263 Object nullArgs = null;1264 return doAction(actionName, timeout, waitCondition, nullArgs);1265 }1266 private Object doAction(ACTION_NAME actionName, long timeout, ExpectedCondition<?> waitCondition,1267 Object...inputArgs) {1268 1269 if (waitCondition != null) {1270 //do verification only if waitCondition is not null1271 if (!waitUntil(waitCondition, timeout)) {1272 //TODO: think about raising exception otherwise we do extra call and might wait and hangs especially for mobile/appium1273 LOGGER.error(Messager.ELEMENT_CONDITION_NOT_VERIFIED.getMessage(actionName.getKey(), getNameWithLocator()));1274 }1275 }1276 1277 if (isLocalized) {1278 isLocalized = false; // single verification is enough for this particular element1279 L10N.verify(this);1280 }1281 Object output = null;1282 try {1283 this.element = getElement();1284 output = overrideAction(actionName, inputArgs);1285 } catch (StaleElementReferenceException e) {1286 //TODO: analyze mobile testing for staled elements. Potentially it should be fixed by appium java client already1287 // sometime Appium instead printing valid StaleElementException generate java.lang.ClassCastException:1288 // com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to java.lang.String1289 LOGGER.debug("catched StaleElementReferenceException: ", e);1290 // try to find again using driver context and do action1291 element = this.findElement();1292 output = overrideAction(actionName, inputArgs);1293 }1294 return output;1295 }1296 // single place for all supported UI actions in carina core1297 private Object overrideAction(ACTION_NAME actionName, Object...inputArgs) {1298 Object output = executeAction(actionName, new ActionSteps() {1299 @Override1300 public void doClick() {1301 DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()),1302 Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));1303 element.click();1304 }1305 1306 @Override1307 public void doClickByJs() {1308 DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()),1309 Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));1310 LOGGER.info("Do click by JavascriptExecutor for element: " + getNameWithLocator());1311 JavascriptExecutor executor = (JavascriptExecutor) getDriver();1312 executor.executeScript("arguments[0].click();", element);1313 }1314 1315 @Override1316 public void doClickByActions() {1317 DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()),1318 Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));1319 LOGGER.info("Do click by Actions for element: " + getNameWithLocator());1320 Actions actions = new Actions(getDriver());1321 actions.moveToElement(element).click().perform();1322 } 1323 1324 @Override1325 public void doDoubleClick() {1326 DriverListener.setMessages(Messager.ELEMENT_DOUBLE_CLICKED.getMessage(getName()),1327 Messager.ELEMENT_NOT_DOUBLE_CLICKED.getMessage(getNameWithLocator()));1328 1329 WebDriver drv = getDriver();1330 Actions action = new Actions(drv);1331 action.moveToElement(element).doubleClick(element).build().perform();1332 }1333 1334 @Override1335 public void doHover(Integer xOffset, Integer yOffset) {1336 DriverListener.setMessages(Messager.ELEMENT_HOVERED.getMessage(getName()),1337 Messager.ELEMENT_NOT_HOVERED.getMessage(getNameWithLocator()));1338 1339 WebDriver drv = getDriver();1340 Actions action = new Actions(drv);1341 if (xOffset != null && yOffset!= null) {1342 action.moveToElement(element, xOffset, yOffset).build().perform();1343 } else {1344 action.moveToElement(element).build().perform();1345 }1346 }1347 1348 @Override1349 public void doSendKeys(Keys keys) {1350 DriverListener.setMessages(Messager.KEYS_SEND_TO_ELEMENT.getMessage(keys.toString(), getName()),1351 Messager.KEYS_NOT_SEND_TO_ELEMENT.getMessage(keys.toString(), getNameWithLocator()));1352 element.sendKeys(keys);1353 }1354 @Override1355 public void doType(String text) {1356 final String decryptedText = cryptoTool.decryptByPattern(text, CRYPTO_PATTERN);1357/* if (!element.getText().isEmpty()) {1358 DriverListener.setMessages(Messager.KEYS_CLEARED_IN_ELEMENT.getMessage(getName()),1359 Messager.KEYS_NOT_CLEARED_IN_ELEMENT.getMessage(getNameWithLocator()));1360 element.clear();1361 }1362*/1363 DriverListener.setMessages(Messager.KEYS_CLEARED_IN_ELEMENT.getMessage(getName()),1364 Messager.KEYS_NOT_CLEARED_IN_ELEMENT.getMessage(getNameWithLocator()));1365 element.clear();1366 String textLog = (!decryptedText.equals(text) ? "********" : text);1367 DriverListener.setMessages(Messager.KEYS_SEND_TO_ELEMENT.getMessage(textLog, getName()),1368 Messager.KEYS_NOT_SEND_TO_ELEMENT.getMessage(textLog, getNameWithLocator()));1369 element.sendKeys(decryptedText);1370 }1371 @Override1372 public void doAttachFile(String filePath) {1373 final String decryptedText = cryptoTool.decryptByPattern(filePath, CRYPTO_PATTERN);1374 String textLog = (!decryptedText.equals(filePath) ? "********" : filePath);1375 DriverListener.setMessages(Messager.FILE_ATTACHED.getMessage(textLog, getName()),1376 Messager.FILE_NOT_ATTACHED.getMessage(textLog, getNameWithLocator()));1377 ((JavascriptExecutor) getDriver()).executeScript("arguments[0].style.display = 'block';", element);1378 ((RemoteWebDriver) castDriver(getDriver())).setFileDetector(new LocalFileDetector());1379 element.sendKeys(decryptedText);1380 }1381 @Override1382 public String doGetText() {1383 String text = element.getText();1384 LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Text", text, getName()));1385 return text;1386 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful