List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed
public Object proceed(Object[] args) throws Throwable;
From source file:com.rover12421.shaka.smali.util.StringUtilsAj.java
License:Apache License
@Around("execution(* org.jf.util.StringUtils.writeEscapedString(..))" + "&& args(writer, value)") public void writeEscapedString(ProceedingJoinPoint joinPoint, Writer writer, String value) throws Throwable { if (!ShakaDecodeOption.getInstance().isShowMoreRecognizableCharacters()) { joinPoint.proceed(joinPoint.getArgs()); return;/* w ww.ja v a2 s. c o m*/ } for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); writer.write(ShakaStringUtil.escaped(c)); } }
From source file:com.rover12421.shaka.smali.util.StringUtilsAj.java
License:Apache License
@Around("execution(* org.jf.util.StringUtils.escapeString(..))" + "&& args(value)") public String escapeString(ProceedingJoinPoint joinPoint, String value) throws Throwable { if (!ShakaDecodeOption.getInstance().isShowMoreRecognizableCharacters()) { return (String) joinPoint.proceed(joinPoint.getArgs()); }/* w w w .j a v a 2s . c om*/ int len = value.length(); StringBuilder sb = new StringBuilder(len * 3 / 2); for (int i = 0; i < len; i++) { char c = value.charAt(i); sb.append(ShakaStringUtil.escaped(c)); } return sb.toString(); }
From source file:com.seleniumtests.core.aspects.LogAction.java
License:Apache License
@Around("execution(public * com.seleniumtests.uipage.PageObject+.* (..)) " + "|| execution(public * com.seleniumtests.uipage.htmlelements.HtmlElement+.* (..))") public Object logDebug(ProceedingJoinPoint joinPoint) throws Throwable { if (LogAction.indent.get(Thread.currentThread()) == null) { LogAction.indent.put(Thread.currentThread(), 0); }/*from w w w . ja v a 2 s . c o m*/ String currentIndent = StringUtils.repeat(" ", LogAction.indent.get(Thread.currentThread())); logger.debug(String.format("%sEntering %s", currentIndent, joinPoint.getSignature())); Object reply = null; try { LogAction.indent.put(Thread.currentThread(), LogAction.indent.get(Thread.currentThread()) + 2); reply = joinPoint.proceed(joinPoint.getArgs()); } catch (Throwable e) { logger.debug(String.format("%sError in %s: %s - %s", currentIndent, joinPoint.getSignature(), e.getClass().getName(), e.getMessage())); throw e; } finally { LogAction.indent.put(Thread.currentThread(), LogAction.indent.get(Thread.currentThread()) - 2); logger.debug(String.format("%sFinishing %s: %s", currentIndent, joinPoint.getSignature(), buildReplyValues(reply))); } return reply; }
From source file:com.seleniumtests.core.aspects.LogAction.java
License:Apache License
/** * Log any call to test steps (page object calls inside a PageObject subclass) * @param joinPoint// w w w. j a va 2s. c om * @throws Throwable */ @Around("this(com.seleniumtests.uipage.PageObject) && " + // caller is a PageObject "(call(public * com.seleniumtests.uipage.PageObject+.* (..))" + "&& !call(public * com.seleniumtests.uipage.PageObject.* (..)))") public Object logSubTestStep(ProceedingJoinPoint joinPoint) throws Throwable { if (SeleniumTestsContextManager.getThreadContext().isManualTestSteps()) { return joinPoint.proceed(joinPoint.getArgs()); } return commonLogTestStep(joinPoint, "", false); }
From source file:com.seleniumtests.core.aspects.LogAction.java
License:Apache License
/** * Log this method call as a test step//from w w w . j a va 2s. c o m * @param joinPoint the join point * @param stepNamePrefix string to add before step name * @param configStep is this method call a TestNG configuration method (\@BeforeXXX or \@AfterXXX) * @return * @throws Throwable */ private Object logTestStep(ProceedingJoinPoint joinPoint, String stepNamePrefix, boolean configStep) throws Throwable { // skip test logging when manual steps are active. This avoid having steps logged twice. // do not skip configuration step logging so that debugging remains easy if ((SeleniumTestsContextManager.getThreadContext().isManualTestSteps() && !configStep) // skip internal configuration steps || joinPoint.getSignature().getDeclaringTypeName().startsWith("com.seleniumtests.core")) { return joinPoint.proceed(joinPoint.getArgs()); } return commonLogTestStep(joinPoint, stepNamePrefix, configStep); }
From source file:com.seleniumtests.core.aspects.LogAction.java
License:Apache License
/** * Log an action inside a TestStep/*from w w w .j a va 2 s . c o m*/ * @param joinPoint the joinPoint * @param targetName target on which action is done (page or element) * @return * @throws Throwable */ private Object logAction(ProceedingJoinPoint joinPoint, String targetName) throws Throwable { List<String> pwdToReplace = new ArrayList<>(); String actionName = String.format("%s on %s %s", joinPoint.getSignature().getName(), targetName, buildArgString(joinPoint, pwdToReplace, new HashMap<>())); Object reply = null; boolean actionFailed = false; TestAction currentAction = new TestAction(actionName, false, pwdToReplace); // log action before its started. By default, it's OK. Then result may be overwritten if step fails // order of steps is the right one (first called is first displayed) if (TestLogging.getParentTestStep() != null) { TestLogging.getParentTestStep().addAction(currentAction); } try { reply = joinPoint.proceed(joinPoint.getArgs()); } catch (Throwable e) { actionFailed = true; throw e; } finally { if (TestLogging.getParentTestStep() != null) { currentAction.setFailed(actionFailed); } } return reply; }
From source file:com.seleniumtests.core.aspects.LogAction.java
License:Apache License
/** * exclude driver creation from the time of the current step * @param joinPoint/*from w ww. j a va 2s .c o m*/ * @return * @throws Throwable */ @Around("execution(public org.openqa.selenium.WebDriver com.seleniumtests.driver.WebUIDriver.createRemoteWebDriver (..))") public Object measureDriverCreation(ProceedingJoinPoint joinPoint) throws Throwable { TestStep cuurrentTestStep = TestLogging.getCurrentRootTestStep(); long start = new Date().getTime(); try { return joinPoint.proceed(joinPoint.getArgs()); } finally { long duration = new Date().getTime() - start; if (cuurrentTestStep != null) { cuurrentTestStep.setDurationToExclude(duration); } TestLogging.info(String.format("driver creation took: %f secs", duration / 1000.0)); } }
From source file:com.seleniumtests.core.aspects.LogAction.java
License:Apache License
/** * Log a TestStep, inside a parent TestStep or not * Common method used for all test step logging * @return//from w w w. j av a 2 s . co m * @throws Throwable */ private Object commonLogTestStep(ProceedingJoinPoint joinPoint, String stepNamePrefix, boolean configStep) throws Throwable { Object reply = null; boolean rootStep = false; TestStep previousParent = null; // step name will contain method arguments only if it's not a configuration method (as they are generic) TestStep currentStep = buildRootStep(joinPoint, stepNamePrefix, !configStep); BrowserMobProxy mobProxy = WebUIDriver.getBrowserMobProxy(); NLWebDriver neoloadDriver = WebUIDriver.getNeoloadDriver(); // check if any root step is already registered (a main step) // happens when using cucumber where a cucumber method can call an other method intercepted by this pointcut // ex: Given (url "www.somesite.com") calls "open(url)" // In this case, open becomes a child of Given // if rootStep is null, parent step is also null if (TestLogging.getCurrentRootTestStep() == null) { TestLogging.setCurrentRootTestStep(currentStep); // will also set parent step rootStep = true; if (mobProxy != null) { mobProxy.newPage(currentStep.getName()); } if (neoloadDriver != null) { neoloadDriver.startTransaction(currentStep.getName()); } } else { TestLogging.getParentTestStep().addStep(currentStep); previousParent = TestLogging.getParentTestStep(); TestLogging.setParentTestStep(currentStep); } try { reply = joinPoint.proceed(joinPoint.getArgs()); } catch (Throwable e) { currentStep.setFailed(true); currentStep.setActionException(e); throw e; } finally { if (rootStep) { TestLogging.getCurrentRootTestStep().updateDuration(); TestLogging.logTestStep(TestLogging.getCurrentRootTestStep()); if (neoloadDriver != null) { neoloadDriver.stopTransaction(); } } else { TestLogging.setParentTestStep(previousParent); } } return reply; }
From source file:com.seleniumtests.uipage.aspects.InterceptBy.java
License:Apache License
/** * Change the argument of the By. when it's in the mapping files * @param joinPoint/*from ww w . j av a 2s . c o m*/ */ @Around("call(* org.openqa.selenium.By..* (..) )") public Object changeArg(ProceedingJoinPoint joinPoint) throws Throwable { Object[] args = joinPoint.getArgs(); Object reply = null; if (args != null) { for (int i = 0; i < args.length; i++) { Object argument = args[i]; if (argument != null && argument instanceof String && argument.toString().contains("map:")) { String[] input = ((String) argument).split(":"); if (input[0].equals("map")) { String page = getCallerName(Thread.currentThread().getStackTrace()); Map<String, HashMap<String, String>> config = SeleniumTestsContextManager.getThreadContext() .getIdMapping(); if (config == null) { config = new ConfigMappingReader().readConfig(); if (config != null && !config.isEmpty()) { SeleniumTestsContextManager.getThreadContext().setIdMapping(config); } else { throw new ConfigurationException( "There is no mapping file correspondant to this type and version"); } } if (input[1] != null && !input[1].equals("")) { if (config.get(page) != null && !config.get(page).isEmpty()) { String toPass = config.get(page).get(input[1]); if (toPass != null && !toPass.equals("")) { args[i] = toPass; } else { throw new ConfigurationException( "This id is not in the mapping files for this page"); } } else { throw new ConfigurationException("This page doesn't have mapping configuration"); } } } } } } reply = joinPoint.proceed(args); return reply; }
From source file:com.seleniumtests.uipage.aspects.ReplayAction.java
License:Apache License
/** * Replay all HtmlElement actions annotated by ReplayOnError. * Classes which are not subclass of HtmlElement won't go there * See javadoc of the annotation for details * @param joinPoint/*from ww w .ja v a2s . co m*/ * @throws Throwable */ @Around("execution(public * com.seleniumtests.uipage.htmlelements.HtmlElement+.* (..))" + "&& execution(@com.seleniumtests.uipage.ReplayOnError public * * (..)) && @annotation(replay)") public Object replayHtmlElement(ProceedingJoinPoint joinPoint, ReplayOnError replay) throws Throwable { Instant end = systemClock.instant() .plusSeconds(SeleniumTestsContextManager.getThreadContext().getReplayTimeout()); Object reply = null; // update driver reference of the element // corrects bug of waitElementPresent which threw a SessionNotFoundError because driver reference were not // updated before searching element (it used the driver reference of an old test session) HtmlElement element = (HtmlElement) joinPoint.getTarget(); element.setDriver(WebUIDriver.getWebDriver()); String targetName = joinPoint.getTarget().toString(); TestAction currentAction = null; String methodName = joinPoint.getSignature().getName(); if (methodName != "getCoordinates") { List<String> pwdToReplace = new ArrayList<>(); String actionName = String.format("%s on %s %s", methodName, targetName, LogAction.buildArgString(joinPoint, pwdToReplace, new HashMap<>())); currentAction = new TestAction(actionName, false, pwdToReplace); } // log action before its started. By default, it's OK. Then result may be overwritten if step fails // order of steps is the right one (first called is first displayed) if (currentAction != null && isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { TestLogging.getParentTestStep().addAction(currentAction); } boolean actionFailed = false; boolean ignoreFailure = false; try { while (end.isAfter(systemClock.instant())) { // in case we have switched to an iframe for using previous webElement, go to default content if (element.getDriver() != null && SeleniumTestsContextManager.isWebTest()) { element.getDriver().switchTo().defaultContent(); // TODO: error when clic is done, closing current window } try { reply = joinPoint.proceed(joinPoint.getArgs()); WaitHelper.waitForMilliSeconds(200); break; } catch (UnhandledAlertException e) { throw e; } catch (WebDriverException e) { // don't prevent TimeoutException to be thrown when coming from waitForPresent // only check that cause is the not found element and not an other error (NoSucheSessionError for example) if ((e instanceof TimeoutException && joinPoint.getSignature().getName().equals("waitForPresent") && e.getCause() instanceof NoSuchElementException) // issue #104: do not log error when waitForPresent raises TimeoutException || (e instanceof NoSuchElementException && isFromExpectedConditions(Thread.currentThread().getStackTrace())) // issue #194: return immediately if the action has been performed from ExpectedConditions class // This way, we let the FluentWait process to retry or re-raise the exception ) { ignoreFailure = true; throw e; } if (end.minusMillis(200).isAfter(systemClock.instant())) { WaitHelper.waitForMilliSeconds(replay.replayDelayMs()); continue; } else { if (e instanceof NoSuchElementException) { throw new NoSuchElementException("Searched element could not be found"); } else if (e instanceof UnreachableBrowserException) { throw new WebDriverException("Browser did not reply, it may have frozen"); } throw e; } } } return reply; } catch (Throwable e) { if (e instanceof NoSuchElementException && joinPoint.getTarget() instanceof HtmlElement && (joinPoint.getSignature().getName().equals("findElements") || joinPoint.getSignature().getName().equals("findHtmlElements"))) { return new ArrayList<WebElement>(); } else { actionFailed = true && !ignoreFailure; throw e; } } finally { if (currentAction != null && isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { currentAction.setFailed(actionFailed); } } }