@Override public String[] execute(Context context, String... args) { return context .findElements("css=a") .stream() .map(elem -> LangUtils.nullToEmpty(elem.getAttribute("id"))) .toArray(String[]::new); }
protected void evalCurArgs(Context context, String[] curArgs) { for (int i = 0; i < curArgs.length; i++) { Matcher matcher = JS_BLOCK_RE.matcher(curArgs[i]); if (matcher.matches()) { Object value = context.getEval().eval(context, matcher.group(1)); if (value == null) value = ""; curArgs[i] = value.toString(); } } }
@DoCommand protected Result doCommand(Context context, ICommand command, String... curArgs) { try { if (context.isInteractive()) { System.out.println(">>> Press ENTER to continue <<<"); System.in.read(); } return command.execute(context, curArgs); } catch (SeleneseCommandErrorException e) { return e.getError(); } catch (Exception e) { return new Error(e); } }
/** * Execute command list. * * @param context Selenese Runner context. * @param cresultList command result list for keeping all command results. * @return result of command list execution. */ public Result execute(Context context, CommandResultList cresultList) { CommandListIterator parentIterator = context.getCommandListIterator(); CommandListIterator commandListIterator = iterator(parentIterator); context.pushCommandListIterator(commandListIterator); CommandSequence sequence = commandListIterator.getCommandSequence(); boolean isContinued = true; try { while (isContinued && commandListIterator.hasNext()) { ICommand command = commandListIterator.next(); sequence.increment(command); List<Screenshot> ss = command.getScreenshots(); int prevSSIndex = (ss == null) ? 0 : ss.size(); String[] curArgs = context.getVarsMap().replaceVarsForArray(command.getArguments()); evalCurArgs(context, curArgs); Result result = doCommand(context, command, curArgs); if (result.isAborted()) isContinued = false; else context.waitSpeed(); ss = command.getScreenshots(); List<Screenshot> newSS; if (ss == null || prevSSIndex == ss.size()) newSS = null; else newSS = new ArrayList<>(ss.subList(prevSSIndex, ss.size())); CommandResult cresult = new CommandResult( sequence.toString(), command, newSS, result, cresultList.getEndTime(), System.currentTimeMillis()); cresultList.add(cresult); } } finally { context.popCommandListIterator(); } return cresultList.getResult(); }