/** * Converts a user interactions transition to a list of Selenium commands. * * @param transition The transition to convert. */ public void handleUserInteractions( SeleniumHolder seleniumHolder, UserInteractionsTransition transition) { for (UserInteraction userInteraction : transition.getUserInteractions()) { IActionElement actionElement = userInteraction.getElement(); if (actionElement == null) { Logger.warn("Action element was null. Skipping user interaction: " + userInteraction); continue; } int waitMillis = seleniumHolder.getNextPageElementTimeout() * 1000; int waitIntervalMillis = 100; int i = 0; while (true) { try { handleUserInteraction(seleniumHolder, userInteraction); break; } catch (UserInteractionException e) { if (i > waitMillis) { handleUserInteractionFailure(seleniumHolder, userInteraction, e); } try { Thread.sleep(waitIntervalMillis); i += waitIntervalMillis; Logger.warn( "Retrying user interaction: " + userInteraction.toString() + " after error: " + ErrorHandler.getCause(e).toString()); } catch (InterruptedException e2) { throw new ExporterException(e2.toString() + " came after " + e.toString(), e); } } } // increment the number of steps in test: seleniumHolder.addResult(null, TestPartStatus.PASS); } if (transition.hasCustomTimeout()) { seleniumHolder.setNextPageElementTimeout(transition.getSecondsToWaitForResult()); } }
private void handleUserInteractionFailure( SeleniumHolder seleniumHolder, UserInteraction userInteraction, UserInteractionException e) { String msg = "Error invoking user interaction: " + userInteraction.toString() + "."; if (userInteraction.getElement() instanceof PageElement) { PageElement pe = (PageElement) userInteraction.getElement(); if (pe.getStatus().equals(TestPartStatus.FAIL)) { msg += "\n\nPage element " + pe.toString() + " not found."; } seleniumHolder.addResultByIsNot(pe, TestPartStatus.EXCEPTION, pe.isNot()); } Logger.error(msg, e); throw new UserInteractionException(msg); }
public static CustomTestStep loadFromFile(File file) { String xml = ""; try { String charset = TestPersistance.getCharset(file); xml = FileUtils.readFileToString(file, charset); } catch (FileNotFoundException e) { Logger.error("Error loading test.", e); throw new TestNotFoundException(e.getMessage()); } catch (IOException e) { ErrorHandler.logAndRethrow(e); } CustomTestStep customStep = null; try { customStep = (CustomTestStep) new CubicTestXStream().fromXML(xml); return customStep; } catch (StreamException e) { } if (customStep == null) customStep = new CustomTestStep(); return customStep; }