/** * Get the current process id. * * @return the pid */ public static long getProcessId() { return Context.getCurrentContext().getProcessId(); }
public static void exit() { Context.getCurrentContext().getStack().exit(); }
/** * Get a value with id from current context. NB, this will not cause * exception if the id doesn't exist! * * @param id * the id * @param searchParent * true to search the parent context, false not to. * @return true the value or null if not found. */ public static Object getConst(String id, boolean searchParent) { return Context.getCurrentContext().getConst(id, searchParent); }
/** * Select xpath objects. @see Context.xpathSelect(xpath) * * @param xpath * xpath * * @return the object */ public static Object xpathSelect(String xpath) { return Context.getCurrentContext().xpathSelect(null, xpath); }
/** * Check if an id exists in current context. * * @param id * the id * @param searchParent * true to search the parent context, false not to. * @return true if exists, false if not. */ public static boolean hasConst(String id, boolean searchParent) { return Context.getCurrentContext().hasConstId(id, searchParent); }
Stack stack = context.getStack(); if (stack.isDying() || (!stack.isEmpty() && context.getCurrentEntityContext().isReturning())) { return null; context.pushStack(this); List<ITagExecutionListener> listeners = context.getTagExecutionListeners(false); try { if (listeners != null) { context.popStack(); return result; } catch (Exception e) { log.error("Exception in AbstractTag.execute.", e); if (null == context.getExceptionContext()) { context.setExceptionContext(context); listeners = context.getTagExecutionListeners(false); if (listeners != null) { for (ITagExecutionListener listener : listeners) {
private void doPopulateReport(ITestResult result) throws Exception { final Context exceptionContext = context == null ? null : context.getExceptionContext(); addMap(context.getIdMap(true, false), dump.getContextValue()); s.setErrorMessage(r.getErrorMessage()); if (exceptionContext != null) { addMap(exceptionContext.getIdMap(true, false), dump.getContextValue()); exceptionContext.getStack().traverse(new IStackTraverser() { Context.cleanCurrentThreadContext();
final Context propertiesContext = rootContext == null ? new Context(System.getProperties(), processId) : rootContext; final Context context = new Context(propertiesContext); context.setAsCurrentThreadContext(); context.setPaxml(this); context.setPaxmlExecutionListeners(paxmlExecutionListeners); context.setEntityExecutionListeners(entityExecutionListeners); context.setTagExecutionListeners(tagExecutionListeners); if (propertiesContext.isRoot()) { if (log.isInfoEnabled()) { log.info("Starting process " + processId + " to execute scenario: " + entity.getResource().getPath()); for (IExecutionListener listener : context.getPaxmlExecutionListeners(false)) { listener.onEntry(this, context);
/** * Call a tag. * * @param name * the tag name * @param args * the arguments map * @return the result */ public static Object call(String name, Map<String, Object> args) { final Context context = Context.getCurrentContext(); final IEntity tag = context.getPaxml().getEntity(name); if (tag == null) { throw new PaxmlRuntimeException("No tag defined as: " + name); } final Context subContext = new Context(context); subContext.setAsCurrentThreadContext(); try { if (args != null) { for (Map.Entry<String, Object> entry : args.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); subContext.addConst(key, key, value, false); } } return tag.execute(subContext); } finally { context.setAsCurrentThreadContext(); } }
List<SeleniumHelper> seleniums = (List<SeleniumHelper>) context.getInternalObject(PrivateKeys.SELENIUMS, true); if (seleniums == null) { seleniums = new ArrayList<SeleniumHelper>(1); context.setInternalObject(PrivateKeys.SELENIUMS, seleniums, true); SeleniumHelper selenium = forceNew ? null : (SeleniumHelper) context.getInternalObject(PrivateKeys.SELENIUM, true); selenium.start(); context.setInternalObject(PrivateKeys.SELENIUM, selenium, true); PaxmlListener listener = (PaxmlListener) context.getInternalObject(PrivateKeys.LISTENER, true); if (listener == null) { listener = new PaxmlListener(seleniums); context.setInternalObject(PrivateKeys.LISTENER, listener, true); context.getPaxmlExecutionListeners(true).add(listener); context.getPaxml().addPaxmlExecutionListener(listener);
/** * Check if a tag name is callable. * * @param tagName * the name of the tag * @return true callable, false not */ public static boolean isCallable(String tagName) { return null != Context.getCurrentContext().getPaxml().getResourceLocator().getResource(tagName); }
/** * Add a screenshot to a context. * * @param file * @return */ private static int addSnapshot(Context context, File file) { List<SnapshotInfo> list = (List<SnapshotInfo>) context.getInternalObject(Keys.SNAPSHOTS, true); if (list == null) { list = new ArrayList<SnapshotInfo>(1); context.setInternalObject(Keys.SNAPSHOTS, list, true); } final SnapshotInfo si = new SnapshotInfo(); si.setFile(file); context.getStack().traverse(new IStackTraverser() { public boolean onItem(IEntity entity, ITag tag) { CallStack cs = new CallStack(); cs.setEntity(entity); cs.setTag(tag); si.getCallStack().add(cs); return true; } }); list.add(si); return list.size(); }
/** * Pop a tag from execution stack. * */ public void popStack() { getStack().pop(); }
public static void registerSession(Context context, WebDriver ws, boolean keepOnError) { if (ws == null) { throw new RuntimeException("WebDriver cannot be null!"); } SessionCleanListener listener = (SessionCleanListener) context.getInternalObject(PrivateKeys.LISTENER, true); if (listener == null) { listener = new SessionCleanListener(); context.setInternalObject(PrivateKeys.LISTENER, listener, true); context.getPaxmlExecutionListeners(true).add(listener); // add to jvm shutdown hook in case the java process is killed. Runtime.getRuntime().addShutdownHook(new Thread(listener)); } WebDriverWrapper wp = new WebDriverWrapper(); wp.webDriver = ws; wp.keepOnError = keepOnError; getWebDrivers().add(wp); }
Context context = Context.getCurrentContext(); Map<String, Object> map = excludesParentContext ? context.getIdConstsMap() : context.getIdMap(mergeWithParentContext, true); if (inheritance) { Class clazz = Class.forName(className);
/** * Check how selenium should behave at the end of the execution. * * @param context * the context * @return true means to keep the selenium session if there is an error; * false means to close the session anyway. */ public static boolean isKeepSessionOnError(Context context) { Boolean yes = (Boolean) context.getInternalObject(PrivateKeys.KEEP_SESSION_ON_ERROR, true); return yes != null && yes; }
/** * Get the current paxml resource. * * @return the resource */ public static PaxmlResource getCurrentyResource() { return Context.getCurrentContext().getCurrentEntity().getResource(); }
/** * Call the execute() method of all children tags in order. * * @param context * the execution context. * @return the execution result. */ protected ChildrenResultList executeChildren(Context context) { int index = 0; Stack stack = context.getStack(); ChildrenResultList result = new ChildrenResultList(1); for (ITag tag : getChildren()) { if (stack.isDying()) { return null; } if (!stack.isEmpty() && context.getCurrentEntityContext().isReturning()) { break; } result.add(executeChild(tag, index++, context)); } return result; }
/** * Get selenium rc host. * * @param context * the context * @return the rc host, null if unknown */ public static String getRcServerHost(Context context) { return (String) context.getConst(SELENIUM_RC_HOST, true); }
public Object get(String name) { Object obj = context.getConst(name, true); if (obj == null) { // check if it is a util function reference obj = getUtilFunctions(name, context); if (obj != null) { context.getRootContext().addConst(name, null, obj, true); } } return obj; }