From a6ca894010ac2d426f81b22a61a6b4229a75fcf6 Mon Sep 17 00:00:00 2001 From: IWAMURO Motonori Date: Sun, 5 Mar 2017 11:33:41 +0900 Subject: [PATCH] Revert "remove result from command." This reverts commit 45e032bdf4865c8591a2874f72b415b29f9c07b9. --- .../java/jp/vmi/html/result/HtmlResult.java | 24 +---------- .../jp/vmi/html/result/ResultRenderer.java | 2 +- .../jp/vmi/selenium/selenese/TestCase.java | 4 +- .../selenese/command/AbstractCommand.java | 40 +++++++++++++++++-- .../selenese/command/AddCollection.java | 4 +- .../selenese/command/AddLocationStrategy.java | 4 +- .../selenese/command/AddSelection.java | 4 +- .../selenese/command/AddToCollection.java | 4 +- .../selenese/command/AllowNativeXpath.java | 4 +- .../selenium/selenese/command/AltKeyDown.java | 5 ++- .../selenium/selenese/command/AltKeyUp.java | 5 ++- .../selenese/command/AnswerOnNextPrompt.java | 4 +- .../selenium/selenese/command/Assertion.java | 10 ++--- .../selenium/selenese/command/AssignId.java | 4 +- .../selenium/selenese/command/AttachFile.java | 4 +- .../selenese/command/BuiltInCommand.java | 4 +- .../command/CaptureEntirePageScreenshot.java | 6 +-- .../vmi/selenium/selenese/command/Check.java | 4 +- .../ChooseCancelOnNextConfirmation.java | 5 ++- .../command/ChooseOkOnNextConfirmation.java | 5 ++- .../vmi/selenium/selenese/command/Click.java | 3 +- .../selenium/selenese/command/ClickAt.java | 4 +- .../vmi/selenium/selenese/command/Close.java | 5 ++- .../selenese/command/CommandList.java | 12 +++++- .../selenium/selenese/command/Comment.java | 4 +- .../selenese/command/ControlKeyDown.java | 5 ++- .../selenese/command/ControlKeyUp.java | 5 ++- .../selenese/command/CreateCookie.java | 4 +- .../command/DeleteAllVisibleCookies.java | 5 ++- .../selenese/command/DoubleClick.java | 4 +- .../selenese/command/DragAndDrop.java | 4 +- .../selenese/command/DragAndDropToObject.java | 4 +- .../selenese/command/EndLoopImpl.java | 5 ++- .../selenium/selenese/command/FireEvent.java | 4 +- .../vmi/selenium/selenese/command/Focus.java | 4 +- .../vmi/selenium/selenese/command/GoBack.java | 5 ++- .../vmi/selenium/selenese/command/GotoIf.java | 4 +- .../selenium/selenese/command/Gotolabel.java | 4 +- .../selenium/selenese/command/Highlight.java | 4 +- .../selenium/selenese/command/ICommand.java | 38 +++++++++++++++++- .../selenium/selenese/command/Include.java | 5 ++- .../selenium/selenese/command/KeyDown.java | 4 +- .../selenium/selenese/command/KeyPress.java | 4 +- .../vmi/selenium/selenese/command/KeyUp.java | 4 +- .../vmi/selenium/selenese/command/Label.java | 4 +- .../selenese/command/MetaKeyDown.java | 5 ++- .../selenium/selenese/command/MetaKeyUp.java | 5 ++- .../vmi/selenium/selenese/command/Open.java | 4 +- .../selenium/selenese/command/OpenWindow.java | 4 +- .../vmi/selenium/selenese/command/Pause.java | 4 +- .../selenium/selenese/command/Refresh.java | 5 ++- .../selenese/command/RemoveAllSelections.java | 4 +- .../selenese/command/RemoveSelection.java | 4 +- .../vmi/selenium/selenese/command/Rollup.java | 3 +- .../selenium/selenese/command/RunScript.java | 4 +- .../{result => command}/Screenshot.java | 2 +- .../vmi/selenium/selenese/command/Select.java | 4 +- .../selenese/command/SelectFrame.java | 4 +- .../selenese/command/SetCursorPosition.java | 4 +- .../selenium/selenese/command/SetSpeed.java | 4 +- .../selenium/selenese/command/SetTimeout.java | 4 +- .../selenese/command/ShiftKeyDown.java | 5 ++- .../selenium/selenese/command/ShiftKeyUp.java | 5 ++- .../selenese/command/StartMarker.java | 28 +++++++++++-- .../vmi/selenium/selenese/command/Submit.java | 4 +- .../vmi/selenium/selenese/command/Type.java | 6 +-- .../selenium/selenese/command/TypeKeys.java | 4 +- .../selenium/selenese/command/Uncheck.java | 4 +- .../selenese/command/UseXpathLibrary.java | 4 +- .../selenese/command/WaitForCondition.java | 4 +- .../selenese/command/WaitForPageToLoad.java | 6 +-- .../selenese/command/WindowFocus.java | 5 ++- .../selenese/command/WindowMaximize.java | 5 ++- .../inject/ScreenshotInterceptor.java | 4 +- .../selenese/result/CommandResult.java | 17 +++++++- .../selenese/result/CommandResultList.java | 13 ------ .../vmi/selenium/selenese/result/Result.java | 32 --------------- .../vmi/selenium/selenese/result/Success.java | 10 ++--- .../resources/jp/vmi/html/result/result.html | 10 ++--- .../selenese/command/CommandSequenceTest.java | 4 +- .../UserDefinedCommandFactoryTest.java | 4 +- 81 files changed, 299 insertions(+), 233 deletions(-) rename src/main/java/jp/vmi/selenium/selenese/{result => command}/Screenshot.java (86%) diff --git a/src/main/java/jp/vmi/html/result/HtmlResult.java b/src/main/java/jp/vmi/html/result/HtmlResult.java index a4eed00c3..e6ccadffe 100644 --- a/src/main/java/jp/vmi/html/result/HtmlResult.java +++ b/src/main/java/jp/vmi/html/result/HtmlResult.java @@ -26,7 +26,6 @@ import jp.vmi.selenium.selenese.result.CommandResult; import jp.vmi.selenium.selenese.result.CommandResultList; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Result.Level; import jp.vmi.selenium.selenese.utils.SystemInformation; /** @@ -56,24 +55,6 @@ public String eval(AnnotationToken token, TemplateContext context) { } } - // Usage: ${@tail VAR LIST_VAR} - private static class AnnoTail implements AnnotationProcessor { - - @Override - public String getType() { - return "tail"; - } - - @Override - public Level eval(AnnotationToken token, TemplateContext context) { - String[] args = token.getArguments().split("\\s+"); - List list = (List) context.model.get(args[1]); - Object tail = (list != null && !list.isEmpty()) ? list.get(list.size() - 1) : null; - context.model.put(args[0], tail); - return null; - } - } - private String[] commandLineArgs = null; private String htmlResultDir = null; private Engine engine = null; @@ -128,7 +109,6 @@ private Engine getEngine() { engine.registerRenderer(Result.class, new ResultRenderer()); engine.registerRenderer(Node.class, new NodeRenderer(engine, getTemplate("index-node.html"))); engine.registerAnnotationProcessor(new AnnoCommandResults()); - engine.registerAnnotationProcessor(new AnnoTail()); } return engine; } @@ -175,10 +155,8 @@ public TestSuiteSummary generate(TestSuite testSuite) { summary.numTestFailures++; break; } - CommandResultList resultList = testCase.getResultList(); for (ICommand command : testCase.getCommandList()) { - Result result = resultList.getLastResult(command); - switch (result.getLevel()) { + switch (command.getResult().getLevel()) { case UNEXECUTED: // no count break; diff --git a/src/main/java/jp/vmi/html/result/ResultRenderer.java b/src/main/java/jp/vmi/html/result/ResultRenderer.java index ae234d5cb..23252f631 100644 --- a/src/main/java/jp/vmi/html/result/ResultRenderer.java +++ b/src/main/java/jp/vmi/html/result/ResultRenderer.java @@ -13,6 +13,6 @@ public class ResultRenderer implements Renderer { @Override public String render(Result result, Locale locale) { - return result.getLevel().toString(); + return result.getClass().getSimpleName().toLowerCase(); } } diff --git a/src/main/java/jp/vmi/selenium/selenese/TestCase.java b/src/main/java/jp/vmi/selenium/selenese/TestCase.java index 05b262bb5..a0a00c298 100644 --- a/src/main/java/jp/vmi/selenium/selenese/TestCase.java +++ b/src/main/java/jp/vmi/selenium/selenese/TestCase.java @@ -16,12 +16,12 @@ import jp.vmi.selenium.selenese.inject.ExecuteTestCase; import jp.vmi.selenium.selenese.result.CommandResultList; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.utils.LogRecorder; import jp.vmi.selenium.selenese.utils.PathUtils; import jp.vmi.selenium.selenese.utils.StopWatch; import static jp.vmi.selenium.selenese.command.StartLoop.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * test-case object for execution. @@ -186,7 +186,7 @@ public void addCommand(ICommandFactory commandFactory, String name, String... ar @Override public Result execute(Selenese parent, Context context) { if (commandList.isEmpty()) - return cresultList.setResult(new Success()); + return cresultList.setResult(SUCCESS); if (parent instanceof TestCase) { try { context.setCurrentTestCase(this); diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AbstractCommand.java b/src/main/java/jp/vmi/selenium/selenese/command/AbstractCommand.java index 80eca7f75..96de5eafc 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AbstractCommand.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AbstractCommand.java @@ -1,6 +1,9 @@ package jp.vmi.selenium.selenese.command; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.List; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriverException; @@ -13,6 +16,7 @@ import jp.vmi.selenium.selenese.utils.LoggerUtils; import static jp.vmi.selenium.selenese.command.StartLoop.*; +import static jp.vmi.selenium.selenese.result.Unexecuted.*; /** * Base implementation of command. @@ -24,7 +28,9 @@ public abstract class AbstractCommand implements ICommand { private final String[] args; private final ArgumentType[] argTypes; private final int[] locatorIndexes; + private Result result = UNEXECUTED; private StartLoop startLoop = NO_START_LOOP; + private List screenshots = null; /** * Constructor. @@ -97,6 +103,12 @@ public String[] getArguments() { return args; } + @Override + @Deprecated + public String[] convertLocators(String[] args) { + return Arrays.stream(extractLocators(args)).map(Locator::toLocatorString).toArray(String[]::new); + } + @Override public Locator[] extractLocators(String[] args) { if (locatorIndexes.length == 0) @@ -140,12 +152,18 @@ public boolean mayUpdateScreen() { @Override public final Result execute(Context context, String... curArgs) { try { - return executeImpl(context, curArgs); + result = executeImpl(context, curArgs); } catch (TimeoutException e) { - return new Error("Timed out"); + result = new Error("Timed out"); } catch (WebDriverException e) { - return new Failure(e.getMessage().replaceAll("(\r?\n)+", " / ")); + result = new Failure(e.getMessage().replaceAll("(\r?\n)+", " / ")); } + return result; + } + + @Override + public Result getResult() { + return result; } @Override @@ -158,6 +176,22 @@ public StartLoop getStartLoop() { return startLoop; } + @Override + public void addScreenshot(String path, String label) { + if (path == null) + return; + if (screenshots == null) + screenshots = new ArrayList<>(); + screenshots.add(new Screenshot(path, label)); + } + + @Override + public List getScreenshots() { + if (screenshots == null) + return Collections.emptyList(); + return screenshots; + } + static String toString(int index, String name, String[] args) { StringBuilder s = new StringBuilder("Command#").append(index); s.append(": ").append(name).append("("); diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AddCollection.java b/src/main/java/jp/vmi/selenium/selenese/command/AddCollection.java index 290c2254b..adfad1873 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AddCollection.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AddCollection.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "addCollection". @@ -25,6 +25,6 @@ public boolean mayUpdateScreen() { @Override protected Result executeImpl(Context context, String... curArgs) { context.getCollectionMap().addCollection(curArgs[ARG_COLLECTION_NAME]); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AddLocationStrategy.java b/src/main/java/jp/vmi/selenium/selenese/command/AddLocationStrategy.java index cac1c0955..7caf2f5f6 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AddLocationStrategy.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AddLocationStrategy.java @@ -27,9 +27,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of AddLocationStrategy. @@ -49,6 +49,6 @@ protected Result executeImpl(Context context, String... curArgs) { + curArgs[ARG_DEFINITION] + " }).call(null, arguments[0], window, document)"; context.getElementFinder().add(curArgs[ARG_NAME], strategy); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AddSelection.java b/src/main/java/jp/vmi/selenium/selenese/command/AddSelection.java index 6b6267499..e3ab9e2ac 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AddSelection.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AddSelection.java @@ -3,9 +3,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.SeleneseRunnerRuntimeException; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "addSelection". @@ -25,6 +25,6 @@ protected Result executeImpl(Context context, String... curArgs) { if (!select.isMultiple) throw new SeleneseRunnerRuntimeException("You may only add a selection to a select that supports multiple selections"); select.selectOptions(curArgs[ARG_OPTION_LOCATOR], true); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AddToCollection.java b/src/main/java/jp/vmi/selenium/selenese/command/AddToCollection.java index e2b2aa194..d653d2930 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AddToCollection.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AddToCollection.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "addToCollection". @@ -26,6 +26,6 @@ public boolean mayUpdateScreen() { @Override protected Result executeImpl(Context context, String... curArgs) { context.getCollectionMap().addToCollection(curArgs[ARG_COLLECTION_NAME], curArgs[ARG_VALUE_TO_ADDING]); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AllowNativeXpath.java b/src/main/java/jp/vmi/selenium/selenese/command/AllowNativeXpath.java index 88a28d1e4..4ddb2c5e6 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AllowNativeXpath.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AllowNativeXpath.java @@ -28,10 +28,10 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Error; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.result.Warning; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of AllowNativeXPath. @@ -56,6 +56,6 @@ protected Result executeImpl(Context context, String... curArgs) { return new Error("You must set this value to 'true' or 'false'"); else if (!"true".equalsIgnoreCase(flag)) return new Warning("Supported XPath is native only"); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AltKeyDown.java b/src/main/java/jp/vmi/selenium/selenese/command/AltKeyDown.java index f65912b34..9d9e59e5f 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AltKeyDown.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AltKeyDown.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "altKeyDown". @@ -16,6 +17,6 @@ public class AltKeyDown extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getModifierKeyState().altKeyDown(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AltKeyUp.java b/src/main/java/jp/vmi/selenium/selenese/command/AltKeyUp.java index 661d21fd3..8308786a6 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AltKeyUp.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AltKeyUp.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "altKeyUp". @@ -16,6 +17,6 @@ public class AltKeyUp extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getModifierKeyState().altKeyUp(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AnswerOnNextPrompt.java b/src/main/java/jp/vmi/selenium/selenese/command/AnswerOnNextPrompt.java index 1201517bb..44cb7a6f2 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AnswerOnNextPrompt.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AnswerOnNextPrompt.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "answerOnNextPrompt". @@ -25,6 +25,6 @@ public boolean mayUpdateScreen() { @Override protected Result executeImpl(Context context, String... curArgs) { context.getJSLibrary().answerOnNextPrompt(context.getWrappedDriver(), curArgs[ARG_ANSWER]); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Assertion.java b/src/main/java/jp/vmi/selenium/selenese/command/Assertion.java index 08cee4d3a..4a07736e6 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Assertion.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Assertion.java @@ -11,12 +11,12 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Failure; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.result.Warning; import jp.vmi.selenium.selenese.subcommand.ISubCommand; import jp.vmi.selenium.selenese.utils.SeleniumUtils; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Commands of "assert*", "verify*", and "waitFor*". @@ -97,11 +97,11 @@ protected Result executeImpl(Context context, String... curArgs) { try { boolean result = (Boolean) getterSubCommand.execute(context, getterArgs); if (result ^ isInverse) - return new Success(); + return SUCCESS; message = String.format("Assertion failed (Result: [%s] / Expected: [%s])", result, !result); } catch (NotFoundException e) { if (isInverse) - return new Success(); + return SUCCESS; message = String.format("Assertion failed (%s)", e.getMessage()); found = false; } @@ -109,13 +109,13 @@ protected Result executeImpl(Context context, String... curArgs) { try { String resultString = SeleniumUtils.convertToString(getterSubCommand.execute(context, getterArgs)); if (SeleniumUtils.patternMatches(expected, resultString) ^ isInverse) - return new Success(); + return SUCCESS; message = String.format("Assertion failed (Result: [%s] / %sExpected: [%s])", StringEscapeUtils.escapeJava(resultString), isInverse ? "Not " : "", StringEscapeUtils.escapeJava(expected)); } catch (NotFoundException e) { if (isInverse) - return new Success(); + return SUCCESS; message = String.format("Assertion failed (%s)", e.getMessage()); found = false; } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AssignId.java b/src/main/java/jp/vmi/selenium/selenese/command/AssignId.java index 61cc6f08f..e53bce437 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AssignId.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AssignId.java @@ -29,9 +29,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of AssignId. @@ -54,6 +54,6 @@ public boolean mayUpdateScreen() { protected Result executeImpl(Context context, String... curArgs) { WebElement elem = context.findElement(curArgs[ARG_LOCATOR]); context.executeScript("arguments[0].id = arguments[1]", elem, curArgs[ARG_VALUE]); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/AttachFile.java b/src/main/java/jp/vmi/selenium/selenese/command/AttachFile.java index f6c48ea6c..fcce919bb 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/AttachFile.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/AttachFile.java @@ -39,10 +39,10 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Error; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.result.Warning; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of AttachFile. @@ -85,6 +85,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.findElement(curArgs[ARG_LOCATOR]); element.clear(); element.sendKeys(outputTo.getAbsolutePath()); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/BuiltInCommand.java b/src/main/java/jp/vmi/selenium/selenese/command/BuiltInCommand.java index 9463e2bbe..209cfcd5f 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/BuiltInCommand.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/BuiltInCommand.java @@ -8,6 +8,8 @@ import jp.vmi.selenium.selenese.subcommand.ISubCommand; import jp.vmi.selenium.selenese.utils.SeleniumUtils; +import static jp.vmi.selenium.selenese.result.Success.*; + /** * Commands implemented by WebDriverCommandProcessor or ISubCommand. */ @@ -36,6 +38,6 @@ protected Result executeImpl(Context context, String... curArgs) { int timeout = context.getTimeout(); WaitForPageToLoad.execute(context, timeout); } - return StringUtils.isNotEmpty(resultString) ? new Success(resultString) : new Success(); + return StringUtils.isNotEmpty(resultString) ? new Success(resultString) : SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/CaptureEntirePageScreenshot.java b/src/main/java/jp/vmi/selenium/selenese/command/CaptureEntirePageScreenshot.java index cf4bbd8a0..64fe4e6ad 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/CaptureEntirePageScreenshot.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/CaptureEntirePageScreenshot.java @@ -9,6 +9,7 @@ import jp.vmi.selenium.selenese.result.Warning; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "captureEntirePageScreenshot". @@ -37,9 +38,8 @@ protected Result executeImpl(Context context, String... curArgs) { if (handler.isIgnoredScreenshotCommand()) return new Success("captureEntirePageScreenshot is ignored."); try { - Result result = new Success("Success"); - result.addScreenshot(handler.takeScreenshot(filename), "cmd"); - return result; + addScreenshot(handler.takeScreenshot(filename), "cmd"); + return SUCCESS; } catch (UnsupportedOperationException e) { return new Warning(e.getMessage()); } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Check.java b/src/main/java/jp/vmi/selenium/selenese/command/Check.java index c52a04c1b..07f0b9801 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Check.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Check.java @@ -5,9 +5,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "check". @@ -28,6 +28,6 @@ protected Result executeImpl(Context context, String... curArgs) { context.getJSLibrary().replaceAlertMethod(driver, element); if (!element.isSelected()) element.click(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/ChooseCancelOnNextConfirmation.java b/src/main/java/jp/vmi/selenium/selenese/command/ChooseCancelOnNextConfirmation.java index 4731808e9..741ed5f52 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/ChooseCancelOnNextConfirmation.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/ChooseCancelOnNextConfirmation.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "echo". @@ -16,6 +17,6 @@ public class ChooseCancelOnNextConfirmation extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getJSLibrary().setNextConfirmationState(context.getWrappedDriver(), false); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/ChooseOkOnNextConfirmation.java b/src/main/java/jp/vmi/selenium/selenese/command/ChooseOkOnNextConfirmation.java index 9c90843dc..446fefe18 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/ChooseOkOnNextConfirmation.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/ChooseOkOnNextConfirmation.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "echo". @@ -16,6 +17,6 @@ public class ChooseOkOnNextConfirmation extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getJSLibrary().setNextConfirmationState(context.getWrappedDriver(), true); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Click.java b/src/main/java/jp/vmi/selenium/selenese/command/Click.java index 1044a9dfc..1441d8294 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Click.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Click.java @@ -9,6 +9,7 @@ import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "click". @@ -29,7 +30,7 @@ protected Result executeImpl(Context context, String... curArgs) { context.getJSLibrary().replaceAlertMethod(driver, element); try { element.click(); - return new Success(); + return SUCCESS; } catch (ElementNotVisibleException e) { context.executeScript("arguments[0].click()", element); return new Success("Success (the element is not visible)"); diff --git a/src/main/java/jp/vmi/selenium/selenese/command/ClickAt.java b/src/main/java/jp/vmi/selenium/selenese/command/ClickAt.java index 95e37ff49..9d585d446 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/ClickAt.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/ClickAt.java @@ -7,9 +7,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "clickAt". @@ -40,6 +40,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.getElementFinder().findElement(driver, locator); context.getJSLibrary().replaceAlertMethod(driver, element); new Actions(driver).moveToElement(element, coord.x, coord.y).click().perform(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Close.java b/src/main/java/jp/vmi/selenium/selenese/command/Close.java index c62620af5..a0c88973e 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Close.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Close.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "close". @@ -16,6 +17,6 @@ public class Close extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getWrappedDriver().close(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/CommandList.java b/src/main/java/jp/vmi/selenium/selenese/command/CommandList.java index b386414ca..bfb716828 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/CommandList.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/CommandList.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.regex.Matcher; @@ -121,6 +122,8 @@ public Result execute(Context context, CommandResultList cresultList) { while (isContinued && commandListIterator.hasNext()) { ICommand command = commandListIterator.next(); sequence.increment(command); + List 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); @@ -128,8 +131,15 @@ public Result execute(Context context, CommandResultList cresultList) { isContinued = false; else context.waitSpeed(); - CommandResult cresult = new CommandResult(sequence.toString(), command, result, cresultList.getEndTime(), System.currentTimeMillis()); + ss = command.getScreenshots(); + List 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(); diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Comment.java b/src/main/java/jp/vmi/selenium/selenese/command/Comment.java index 8d6f8b7e6..8a376fb9a 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Comment.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Comment.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * @@ -28,7 +28,7 @@ public boolean mayUpdateScreen() { @Override protected Result executeImpl(Context context, String... curArgs) { - return new Success(); + return SUCCESS; } @Override diff --git a/src/main/java/jp/vmi/selenium/selenese/command/ControlKeyDown.java b/src/main/java/jp/vmi/selenium/selenese/command/ControlKeyDown.java index bdb931c8e..fcfe62e22 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/ControlKeyDown.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/ControlKeyDown.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "controlKeyDown". @@ -16,6 +17,6 @@ public class ControlKeyDown extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getModifierKeyState().controlKeyDown(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/ControlKeyUp.java b/src/main/java/jp/vmi/selenium/selenese/command/ControlKeyUp.java index eafda7442..c5eef1e1c 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/ControlKeyUp.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/ControlKeyUp.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "controlKeyUp". @@ -16,6 +17,6 @@ public class ControlKeyUp extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getModifierKeyState().controlKeyUp(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/CreateCookie.java b/src/main/java/jp/vmi/selenium/selenese/command/CreateCookie.java index c439be854..c51ce0a45 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/CreateCookie.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/CreateCookie.java @@ -38,9 +38,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Error; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; import static jp.vmi.selenium.webdriver.WebDriverManager.*; /** @@ -104,6 +104,6 @@ protected Result executeImpl(Context context, String... curArgs) { throw e; } - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/DeleteAllVisibleCookies.java b/src/main/java/jp/vmi/selenium/selenese/command/DeleteAllVisibleCookies.java index 58944f89b..b12591fcc 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/DeleteAllVisibleCookies.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/DeleteAllVisibleCookies.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of DeleteAllVisibleCookies. @@ -21,6 +22,6 @@ public boolean mayUpdateScreen() { @Override protected Result executeImpl(Context context, String... curArgs) { context.getWrappedDriver().manage().deleteAllCookies(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/DoubleClick.java b/src/main/java/jp/vmi/selenium/selenese/command/DoubleClick.java index 48e9567a1..e12dcfeff 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/DoubleClick.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/DoubleClick.java @@ -6,9 +6,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "doubleClick". @@ -28,6 +28,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.getElementFinder().findElement(driver, locator); context.getJSLibrary().replaceAlertMethod(driver, element); new Actions(driver).doubleClick(element).perform(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/DragAndDrop.java b/src/main/java/jp/vmi/selenium/selenese/command/DragAndDrop.java index 9e1fba281..6d02fe2c8 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/DragAndDrop.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/DragAndDrop.java @@ -32,9 +32,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Error; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of DragAndDrop. @@ -62,6 +62,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebDriver driver = context.getWrappedDriver(); WebElement element = context.getElementFinder().findElement(driver, curArgs[ARG_LOCATOR]); new Actions(driver).dragAndDropBy(element, xDelta, yDelta).perform(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/DragAndDropToObject.java b/src/main/java/jp/vmi/selenium/selenese/command/DragAndDropToObject.java index 3f1f6fcf8..24f734254 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/DragAndDropToObject.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/DragAndDropToObject.java @@ -32,9 +32,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.locator.WebDriverElementFinder; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of DragAndDropToObject. @@ -55,6 +55,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement elementFrom = finder.findElement(driver, curArgs[ARG_LOCATOR_FROM]); WebElement elementTo = finder.findElement(driver, curArgs[ARG_LOCATOR_TO]); new Actions(driver).dragAndDrop(elementFrom, elementTo).perform(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/EndLoopImpl.java b/src/main/java/jp/vmi/selenium/selenese/command/EndLoopImpl.java index 9816aecf5..3e8f4c361 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/EndLoopImpl.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/EndLoopImpl.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Default implementation for EndLoop. @@ -22,6 +23,6 @@ public boolean mayUpdateScreen() { protected Result executeImpl(Context context, String... curArgs) { StartLoop startLoop = getStartLoop(); context.getCommandListIterator().jumpTo(startLoop); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/FireEvent.java b/src/main/java/jp/vmi/selenium/selenese/command/FireEvent.java index 6c7d1d8bf..0a640f311 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/FireEvent.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/FireEvent.java @@ -4,9 +4,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of FireEvent. @@ -24,6 +24,6 @@ public class FireEvent extends AbstractCommand { protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.findElement(curArgs[ARG_LOCATOR]); context.getJSLibrary().fireEvent(context.getWrappedDriver(), element, curArgs[ARG_EVENT_NAME]); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Focus.java b/src/main/java/jp/vmi/selenium/selenese/command/Focus.java index 145443b0e..70dd942a5 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Focus.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Focus.java @@ -6,9 +6,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "focus". @@ -26,6 +26,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebDriver driver = context.getWrappedDriver(); WebElement element = context.getElementFinder().findElement(driver, curArgs[ARG_LOCATOR]); new Actions(driver).moveToElement(element).perform(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/GoBack.java b/src/main/java/jp/vmi/selenium/selenese/command/GoBack.java index dd911f230..847278a24 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/GoBack.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/GoBack.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of GoBack. @@ -16,6 +17,6 @@ public class GoBack extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getWrappedDriver().navigate().back(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/GotoIf.java b/src/main/java/jp/vmi/selenium/selenese/command/GotoIf.java index 67e10c9d0..dc9c6c199 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/GotoIf.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/GotoIf.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "gotoIf". @@ -27,6 +27,6 @@ public boolean mayUpdateScreen() { public Result executeImpl(Context context, String... curArgs) { if (context.isTrue(curArgs[ARG_EXPRESSION])) context.getCommandListIterator().jumpTo(curArgs[ARG_LABEL]); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Gotolabel.java b/src/main/java/jp/vmi/selenium/selenese/command/Gotolabel.java index 838251bb4..7c5e9d07e 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Gotolabel.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Gotolabel.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "gotolabel". @@ -25,6 +25,6 @@ public boolean mayUpdateScreen() { @Override protected Result executeImpl(Context context, String... curArgs) { context.getCommandListIterator().jumpTo(curArgs[ARG_LABEL]); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Highlight.java b/src/main/java/jp/vmi/selenium/selenese/command/Highlight.java index a26fb15c0..690d49d2b 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Highlight.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Highlight.java @@ -5,9 +5,9 @@ import jp.vmi.selenium.selenese.highlight.HighlightStyle; import jp.vmi.selenium.selenese.locator.Locator; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "highlight". @@ -24,6 +24,6 @@ public class Highlight extends AbstractCommand { protected Result executeImpl(Context context, String... curArgs) { if (context instanceof Runner) ((Runner) context).highlight(new Locator(curArgs[ARG_LOCATOR]), HighlightStyle.ELEMENT_STYLES[0]); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/ICommand.java b/src/main/java/jp/vmi/selenium/selenese/command/ICommand.java index 0703c1bfc..16904c89a 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/ICommand.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/ICommand.java @@ -1,5 +1,8 @@ package jp.vmi.selenium.selenese.command; +import java.util.Arrays; +import java.util.List; + import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.locator.Locator; import jp.vmi.selenium.selenese.result.Result; @@ -37,13 +40,24 @@ public interface ICommand { */ String getName(); + /** + * Convert locators from arguments. + * + * @param args the command arguments. + * @return converted locators. + */ + @Deprecated + String[] convertLocators(String[] args); + /** * Extract locators from arguments. * * @param args the command arguments. * @return extracted parsed locators. */ - Locator[] extractLocators(String[] args); + default Locator[] extractLocators(String[] args) { + return Arrays.stream(convertLocators(args)).map(Locator::new).toArray(Locator[]::new); + } /** * May the command update screen? @@ -63,6 +77,14 @@ public interface ICommand { * @return the command result. */ Result execute(Context context, String... curArgs); + + /** + * Get the command result. + * + * @return the command result. + */ + Result getResult(); + /** * Set beginning-of-loop command. * @@ -77,4 +99,18 @@ public interface ICommand { */ StartLoop getStartLoop(); + /** + * Add screenshot image. + * + * @param path image path. + * @param label image label. + */ + void addScreenshot(String path, String label); + + /** + * Get list of screenshot images. + * + * @return list of image path of sreenshot. + */ + List getScreenshots(); } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Include.java b/src/main/java/jp/vmi/selenium/selenese/command/Include.java index 6a9bdfcc3..bc008f0d1 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Include.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Include.java @@ -13,6 +13,7 @@ import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "include". @@ -38,11 +39,11 @@ protected Result executeImpl(Context context, String... curArgs) { String seq = context.getCommandListIterator().getCommandSequence().toString(); StartMarker marker = new StartMarker(this, "Start: " + filename); long now = System.currentTimeMillis(); - CommandResult markerResult = new CommandResult(seq, marker, new Success(), now, now); + CommandResult markerResult = new CommandResult(seq, marker, marker.getScreenshots(), marker.getResult(), now, now); current.getResultList().add(markerResult); try { Result result = child.execute(current, context); - return result.isSuccess() ? new Success("Success: " + filename) : result; + return result == SUCCESS ? new Success("Success: " + filename) : result; } catch (InvalidSeleneseException e) { return new Error(e); } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/KeyDown.java b/src/main/java/jp/vmi/selenium/selenese/command/KeyDown.java index afcf25f57..e84c4f7b0 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/KeyDown.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/KeyDown.java @@ -7,9 +7,9 @@ import jp.vmi.selenium.selenese.ModifierKeyState; import jp.vmi.selenium.selenese.javascript.JSLibrary.KeyEventType; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "keyDown". @@ -31,6 +31,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.getElementFinder().findElement(driver, locator); ModifierKeyState keyState = context.getModifierKeyState(); context.getJSLibrary().triggerKeyEvent(driver, element, KeyEventType.KEYDOWN, keySequence, keyState); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/KeyPress.java b/src/main/java/jp/vmi/selenium/selenese/command/KeyPress.java index 6df3de6aa..a3c39634a 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/KeyPress.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/KeyPress.java @@ -7,9 +7,9 @@ import jp.vmi.selenium.selenese.ModifierKeyState; import jp.vmi.selenium.selenese.javascript.JSLibrary.KeyEventType; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "keyDown". @@ -31,6 +31,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.getElementFinder().findElement(driver, locator); ModifierKeyState keyState = context.getModifierKeyState(); context.getJSLibrary().triggerKeyEvent(driver, element, KeyEventType.KEYPRESS, keySequence, keyState); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/KeyUp.java b/src/main/java/jp/vmi/selenium/selenese/command/KeyUp.java index 66042f0fb..8e40ec91b 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/KeyUp.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/KeyUp.java @@ -7,9 +7,9 @@ import jp.vmi.selenium.selenese.ModifierKeyState; import jp.vmi.selenium.selenese.javascript.JSLibrary.KeyEventType; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "keyUp". @@ -31,6 +31,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.getElementFinder().findElement(driver, locator); ModifierKeyState keyState = context.getModifierKeyState(); context.getJSLibrary().triggerKeyEvent(driver, element, KeyEventType.KEYUP, keySequence, keyState); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Label.java b/src/main/java/jp/vmi/selenium/selenese/command/Label.java index abde7909a..fbfe59599 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Label.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Label.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "label". @@ -34,6 +34,6 @@ public String getLabel() { @Override protected Result executeImpl(Context context, String... curArgs) { - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/MetaKeyDown.java b/src/main/java/jp/vmi/selenium/selenese/command/MetaKeyDown.java index 81ccc5646..049a38034 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/MetaKeyDown.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/MetaKeyDown.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "metaKeyDown". @@ -16,6 +17,6 @@ public class MetaKeyDown extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getModifierKeyState().metaKeyDown(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/MetaKeyUp.java b/src/main/java/jp/vmi/selenium/selenese/command/MetaKeyUp.java index 06c6659a9..26cd93b97 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/MetaKeyUp.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/MetaKeyUp.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "metaKeyUp". @@ -16,6 +17,6 @@ public class MetaKeyUp extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getModifierKeyState().metaKeyUp(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Open.java b/src/main/java/jp/vmi/selenium/selenese/command/Open.java index 22440f4dd..f7bcf0926 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Open.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Open.java @@ -6,9 +6,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.SeleneseRunnerRuntimeException; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "open". @@ -35,6 +35,6 @@ protected Result executeImpl(Context context, String... curArgs) { } } context.getWrappedDriver().get(url); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/OpenWindow.java b/src/main/java/jp/vmi/selenium/selenese/command/OpenWindow.java index edfea7879..95adb735a 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/OpenWindow.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/OpenWindow.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * An implementation of the "openWindow" method from Selenium. @@ -22,6 +22,6 @@ public class OpenWindow extends AbstractCommand { protected Result executeImpl(Context context, String... curArgs) { String script = String.format("window.open('%s', '%s'); null;", curArgs[ARG_URL], curArgs[ARG_WINDOW_ID]); context.getEval().eval(context, script); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Pause.java b/src/main/java/jp/vmi/selenium/selenese/command/Pause.java index 1615f8433..8fad62199 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Pause.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Pause.java @@ -5,10 +5,10 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Failure; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.result.Warning; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "pause". @@ -28,7 +28,7 @@ protected Result executeImpl(Context context, String... curArgs) { return new Warning("pause is ignored: empty time."); try { Thread.sleep(Long.parseLong(pauseMSec)); - return new Success(); + return SUCCESS; } catch (NumberFormatException e) { return new Warning("pause is ignored: invalid time: " + pauseMSec); } catch (InterruptedException e) { diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Refresh.java b/src/main/java/jp/vmi/selenium/selenese/command/Refresh.java index 648decc27..568445de6 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Refresh.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Refresh.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of Refresh. @@ -16,6 +17,6 @@ public class Refresh extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getWrappedDriver().navigate().refresh(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/RemoveAllSelections.java b/src/main/java/jp/vmi/selenium/selenese/command/RemoveAllSelections.java index 155e0bd05..ec5f384c5 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/RemoveAllSelections.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/RemoveAllSelections.java @@ -27,10 +27,10 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.result.Warning; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of RemoveAllSelections. @@ -49,6 +49,6 @@ protected Result executeImpl(Context context, String... curArgs) { if (!select.isMultiple) return new Warning("The specified \"select\" is not multiple."); select.unsetOptions(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/RemoveSelection.java b/src/main/java/jp/vmi/selenium/selenese/command/RemoveSelection.java index cc4fd2d74..88bf64d7d 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/RemoveSelection.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/RemoveSelection.java @@ -3,9 +3,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.SeleneseRunnerRuntimeException; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "removeSelection". @@ -25,6 +25,6 @@ protected Result executeImpl(Context context, String... curArgs) { if (!select.isMultiple) throw new SeleneseRunnerRuntimeException("You may only add a selection to a select that supports multiple selections"); select.selectOptions(curArgs[ARG_OPTION_LOCATOR], false); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Rollup.java b/src/main/java/jp/vmi/selenium/selenese/command/Rollup.java index 74da76a9f..880ba7be3 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Rollup.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Rollup.java @@ -15,6 +15,7 @@ import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "rollup". @@ -68,6 +69,6 @@ protected Result executeImpl(Context context, String... curArgs) { return new Error("No such rollup rule: " + rollupName); CommandList commandList = rollupRule.getExpandedCommands(context, kwArgsMap); Result result = commandList.execute(context, new CommandResultList()); - return result.isSuccess() ? new Success("Success: " + rollupRule.getName()) : result; + return result == SUCCESS ? new Success("Success: " + rollupRule.getName()) : result; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/RunScript.java b/src/main/java/jp/vmi/selenium/selenese/command/RunScript.java index ef34cf685..b04ec06ec 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/RunScript.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/RunScript.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * An implementation of the "runScript" method from Selenium. @@ -25,6 +25,6 @@ public class RunScript extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getEval().eval(context, curArgs[ARG_SCRIPT]); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/result/Screenshot.java b/src/main/java/jp/vmi/selenium/selenese/command/Screenshot.java similarity index 86% rename from src/main/java/jp/vmi/selenium/selenese/result/Screenshot.java rename to src/main/java/jp/vmi/selenium/selenese/command/Screenshot.java index 127f3ea0c..87c61ceb2 100644 --- a/src/main/java/jp/vmi/selenium/selenese/result/Screenshot.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Screenshot.java @@ -1,4 +1,4 @@ -package jp.vmi.selenium.selenese.result; +package jp.vmi.selenium.selenese.command; /** * Screenshot information. diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Select.java b/src/main/java/jp/vmi/selenium/selenese/command/Select.java index 9eafaffaf..4366f90c6 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Select.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Select.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "select". @@ -24,6 +24,6 @@ protected Result executeImpl(Context context, String... curArgs) { if (select.isMultiple) select.unsetOptions(); select.selectOptions(curArgs[ARG_OPTION_LOCATOR], true); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/SelectFrame.java b/src/main/java/jp/vmi/selenium/selenese/command/SelectFrame.java index 2e9005bf7..5c46ce09a 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/SelectFrame.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/SelectFrame.java @@ -2,9 +2,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "selectFrame". @@ -21,6 +21,6 @@ public class SelectFrame extends AbstractCommand { protected Result executeImpl(Context context, String... curArgs) { String locator = curArgs[ARG_LOCATOR]; context.getElementFinder().selectFrame(context.getWrappedDriver(), locator); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/SetCursorPosition.java b/src/main/java/jp/vmi/selenium/selenese/command/SetCursorPosition.java index 2c1401875..b66367209 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/SetCursorPosition.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/SetCursorPosition.java @@ -30,9 +30,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Error; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of SetCursorPosition. @@ -56,6 +56,6 @@ protected Result executeImpl(Context context, String... curArgs) { return new Error("Position is not a number: " + curArgs[ARG_POSITION]); } context.getJSLibrary().setCursorPosition(context.getWrappedDriver(), element, position); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/SetSpeed.java b/src/main/java/jp/vmi/selenium/selenese/command/SetSpeed.java index 2c04eddbc..7e517881b 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/SetSpeed.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/SetSpeed.java @@ -4,10 +4,10 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.result.Warning; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "setSpeed". @@ -32,7 +32,7 @@ protected Result executeImpl(Context context, String... curArgs) { return new Warning("the argument of setSpeed is ignored: empty."); try { context.setSpeed(Long.parseLong(speed)); - return new Success(); + return SUCCESS; } catch (NumberFormatException e) { return new Warning("the argument of setSpeed is ignored: invalid number format: " + speed); } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/SetTimeout.java b/src/main/java/jp/vmi/selenium/selenese/command/SetTimeout.java index f805e2558..4eaf352fb 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/SetTimeout.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/SetTimeout.java @@ -4,10 +4,10 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.result.Warning; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "setTimeout". @@ -32,7 +32,7 @@ protected Result executeImpl(Context context, String... curArgs) { return new Warning("the argument of setTimeout is ignored: empty."); try { context.setTimeout(Integer.parseInt(timeout)); - return new Success(); + return SUCCESS; } catch (NumberFormatException e) { return new Warning("the argument of setTimeout is ignored: invalid number format: " + timeout); } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/ShiftKeyDown.java b/src/main/java/jp/vmi/selenium/selenese/command/ShiftKeyDown.java index 5f0b74cfd..3aeb826d2 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/ShiftKeyDown.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/ShiftKeyDown.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "shiftKeyDown". @@ -16,6 +17,6 @@ public class ShiftKeyDown extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getModifierKeyState().shiftKeyDown(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/ShiftKeyUp.java b/src/main/java/jp/vmi/selenium/selenese/command/ShiftKeyUp.java index 2ee866ef9..ba0527f70 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/ShiftKeyUp.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/ShiftKeyUp.java @@ -2,7 +2,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "shiftKeyUp". @@ -16,6 +17,6 @@ public class ShiftKeyUp extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { context.getModifierKeyState().shiftKeyUp(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/StartMarker.java b/src/main/java/jp/vmi/selenium/selenese/command/StartMarker.java index fe4ecf614..6b64f24a2 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/StartMarker.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/StartMarker.java @@ -1,8 +1,11 @@ package jp.vmi.selenium.selenese.command; +import java.util.Collections; +import java.util.List; + import jp.vmi.selenium.selenese.Context; -import jp.vmi.selenium.selenese.locator.Locator; import jp.vmi.selenium.selenese.result.Result; +import jp.vmi.selenium.selenese.result.Success; /** * Start marker for result sequence. @@ -10,6 +13,7 @@ public class StartMarker implements ICommand { private final ICommand command; + private final Result result; /** * Constructor. @@ -19,6 +23,7 @@ public class StartMarker implements ICommand { */ public StartMarker(ICommand command, String message) { this.command = command; + this.result = new Success(message); } @Override @@ -43,8 +48,8 @@ public String getName() { @Deprecated @Override - public Locator[] extractLocators(String[] args) { - return this.command.extractLocators(args); + public String[] convertLocators(String[] args) { + throw new UnsupportedOperationException(); } @Override @@ -57,6 +62,11 @@ public Result execute(Context context, String... curArgs) { throw new UnsupportedOperationException(); } + @Override + public Result getResult() { + return result; + } + @Override public void setStartLoop(StartLoop startLoop) { throw new UnsupportedOperationException(); @@ -66,4 +76,14 @@ public void setStartLoop(StartLoop startLoop) { public StartLoop getStartLoop() { throw new UnsupportedOperationException(); } -} + + @Override + public void addScreenshot(String path, String label) { + throw new UnsupportedOperationException(); + } + + @Override + public List getScreenshots() { + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Submit.java b/src/main/java/jp/vmi/selenium/selenese/command/Submit.java index d9a0a0a67..6e6d60e83 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Submit.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Submit.java @@ -5,9 +5,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "submit". @@ -27,6 +27,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.getElementFinder().findElement(driver, locator); context.getJSLibrary().replaceAlertMethod(driver, element); element.submit(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Type.java b/src/main/java/jp/vmi/selenium/selenese/command/Type.java index a536139e7..d6b00bcb6 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Type.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Type.java @@ -8,10 +8,10 @@ import jp.vmi.selenium.selenese.ModifierKeyState; import jp.vmi.selenium.selenese.SeleneseRunnerRuntimeException; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.result.Warning; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "type". @@ -39,7 +39,7 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.getElementFinder().findElement(driver, locator); context.getJSLibrary().replaceAlertMethod(driver, element); String tagName = element.getTagName().toLowerCase(); - Result result = null; + Result result = SUCCESS; switch (tagName) { case "input": String type = element.getAttribute("type"); @@ -54,6 +54,6 @@ protected Result executeImpl(Context context, String... curArgs) { break; } context.getJSLibrary().fireEvent(driver, element, "change"); - return result != null ? result : new Success(); + return result; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/TypeKeys.java b/src/main/java/jp/vmi/selenium/selenese/command/TypeKeys.java index 2b57450e4..9e9ec21fe 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/TypeKeys.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/TypeKeys.java @@ -6,9 +6,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "typeKeys". @@ -38,6 +38,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebElement element = context.getElementFinder().findElement(driver, locator); context.getJSLibrary().replaceAlertMethod(driver, element); element.sendKeys(value); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/Uncheck.java b/src/main/java/jp/vmi/selenium/selenese/command/Uncheck.java index 0978c97a2..a511bc4b7 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/Uncheck.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/Uncheck.java @@ -5,9 +5,9 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "uncheck". @@ -28,6 +28,6 @@ protected Result executeImpl(Context context, String... curArgs) { context.getJSLibrary().replaceAlertMethod(driver, element); if (element.isSelected()) element.click(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/UseXpathLibrary.java b/src/main/java/jp/vmi/selenium/selenese/command/UseXpathLibrary.java index 8d2939f77..db4a60c1e 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/UseXpathLibrary.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/UseXpathLibrary.java @@ -27,10 +27,10 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.result.Warning; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of UseXpathLibrary. @@ -52,7 +52,7 @@ public boolean mayUpdateScreen() { protected Result executeImpl(Context context, String... curArgs) { switch (curArgs[ARG_LIBRARY_NAME]) { case "javascript-xpath": - return new Success(); + return SUCCESS; default: return new Warning("XPath library to use must be 'javascript-xpath'"); } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/WaitForCondition.java b/src/main/java/jp/vmi/selenium/selenese/command/WaitForCondition.java index 5f5c84f4e..62f2cf83f 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/WaitForCondition.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/WaitForCondition.java @@ -3,11 +3,11 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Error; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.utils.Wait; import jp.vmi.selenium.selenese.utils.Wait.StopCondition; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * An implementation of "waitForCondition". @@ -46,7 +46,7 @@ else if (result instanceof Boolean) } }); if (waitResult) - return new Success(); + return SUCCESS; else return new Error("Timed out after " + timeout + "ms"); } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/WaitForPageToLoad.java b/src/main/java/jp/vmi/selenium/selenese/command/WaitForPageToLoad.java index 16d894f31..ca671c62a 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/WaitForPageToLoad.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/WaitForPageToLoad.java @@ -39,11 +39,11 @@ import jp.vmi.selenium.selenese.SeleneseCommandErrorException; import jp.vmi.selenium.selenese.result.Error; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.selenese.utils.Wait; import jp.vmi.selenium.selenese.utils.Wait.StopCondition; import static jp.vmi.selenium.selenese.command.ArgumentType.*; +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of "waitForPageToLoad". @@ -91,7 +91,7 @@ public static Result execute(Context context, long timeout) { if (timeout < 0) return new Error("Illegal timeout parameter: " + timeout); else if (timeout == 0) - return new Success(); + return SUCCESS; long startTime = System.currentTimeMillis(); WebDriver driver = context.getWrappedDriver(); if (!(driver instanceof JavascriptExecutor)) @@ -99,7 +99,7 @@ else if (timeout == 0) StopCondition condition = isReadyStateSupported(driver) ? checkByReadyState(driver) : checkByBodyLength(driver); if (!Wait.defaultInterval.wait(startTime, timeout, condition)) return new Error("Failed to load page within " + timeout + " ms"); - return new Success(); + return SUCCESS; } private static boolean isReadyStateSupported(WebDriver driver) { diff --git a/src/main/java/jp/vmi/selenium/selenese/command/WindowFocus.java b/src/main/java/jp/vmi/selenium/selenese/command/WindowFocus.java index ab547698a..1d76ee68f 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/WindowFocus.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/WindowFocus.java @@ -27,7 +27,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Re-implementation of WindowFocus. @@ -46,6 +47,6 @@ public boolean mayUpdateScreen() { @Override protected Result executeImpl(Context context, String... curArgs) { context.executeScript("window.focus()"); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/command/WindowMaximize.java b/src/main/java/jp/vmi/selenium/selenese/command/WindowMaximize.java index 8c3a0a80e..50704e66b 100644 --- a/src/main/java/jp/vmi/selenium/selenese/command/WindowMaximize.java +++ b/src/main/java/jp/vmi/selenium/selenese/command/WindowMaximize.java @@ -5,7 +5,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; + +import static jp.vmi.selenium.selenese.result.Success.*; /** * Command "windowMaximize". @@ -21,6 +22,6 @@ protected Result executeImpl(Context context, String... curArgs) { WebDriver driver = context.getWrappedDriver(); Window window = driver.manage().window(); window.maximize(); - return new Success(); + return SUCCESS; } } diff --git a/src/main/java/jp/vmi/selenium/selenese/inject/ScreenshotInterceptor.java b/src/main/java/jp/vmi/selenium/selenese/inject/ScreenshotInterceptor.java index c7d305a8c..a22b0063e 100644 --- a/src/main/java/jp/vmi/selenium/selenese/inject/ScreenshotInterceptor.java +++ b/src/main/java/jp/vmi/selenium/selenese/inject/ScreenshotInterceptor.java @@ -20,9 +20,9 @@ protected Result invoke(MethodInvocation invocation, Context context, ICommand c ScreenshotHandler handler = (ScreenshotHandler) context; String baseName = context.getCurrentTestCase().getBaseName(); try { - result.addScreenshot(handler.takeScreenshotAll(baseName, command.getIndex()), "all"); + command.addScreenshot(handler.takeScreenshotAll(baseName, command.getIndex()), "all"); if (!result.isSuccess()) - result.addScreenshot(handler.takeScreenshotOnFail(baseName, command.getIndex()), "fail"); + command.addScreenshot(handler.takeScreenshotOnFail(baseName, command.getIndex()), "fail"); } catch (WebDriverException e) { // ignore if failed to capturing. } diff --git a/src/main/java/jp/vmi/selenium/selenese/result/CommandResult.java b/src/main/java/jp/vmi/selenium/selenese/result/CommandResult.java index a12ec74fd..19a541ddc 100644 --- a/src/main/java/jp/vmi/selenium/selenese/result/CommandResult.java +++ b/src/main/java/jp/vmi/selenium/selenese/result/CommandResult.java @@ -1,6 +1,9 @@ package jp.vmi.selenium.selenese.result; +import java.util.List; + import jp.vmi.selenium.selenese.command.ICommand; +import jp.vmi.selenium.selenese.command.Screenshot; /** * Pair of command and result. @@ -9,6 +12,7 @@ public class CommandResult { private final String sequence; private final ICommand command; + private final List screenshots; private final Result result; private final long startTime; // ms private final long endTime; // ms @@ -18,13 +22,15 @@ public class CommandResult { * * @param sequence sequence. * @param command command. + * @param screenshots list of screenshot information. * @param result the result of above command. * @param startTime start time. * @param endTime end time. */ - public CommandResult(String sequence, ICommand command, Result result, long startTime, long endTime) { + public CommandResult(String sequence, ICommand command, List screenshots, Result result, long startTime, long endTime) { this.sequence = sequence; this.command = command; + this.screenshots = screenshots; this.result = result; this.startTime = startTime; this.endTime = endTime; @@ -48,6 +54,15 @@ public ICommand getCommand() { return command; } + /** + * Get list of screenshot information. + * + * @return list of screenshot information. + */ + public List getScreenshots() { + return screenshots; + } + /** * Get result. * diff --git a/src/main/java/jp/vmi/selenium/selenese/result/CommandResultList.java b/src/main/java/jp/vmi/selenium/selenese/result/CommandResultList.java index 64735d308..1079748c5 100644 --- a/src/main/java/jp/vmi/selenium/selenese/result/CommandResultList.java +++ b/src/main/java/jp/vmi/selenium/selenese/result/CommandResultList.java @@ -123,19 +123,6 @@ public List getResults(ICommand command) { return map.get(command); } - /** - * Get last result of the command. - * - * @param command command. - * @return result. - */ - public Result getLastResult(ICommand command) { - List results = getResults(command); - if (results == null || results.isEmpty()) - return UNEXECUTED; - return results.get(results.size() - 1).getResult(); - } - /** * Set end time. * diff --git a/src/main/java/jp/vmi/selenium/selenese/result/Result.java b/src/main/java/jp/vmi/selenium/selenese/result/Result.java index 61afd7e2c..25aaebb26 100644 --- a/src/main/java/jp/vmi/selenium/selenese/result/Result.java +++ b/src/main/java/jp/vmi/selenium/selenese/result/Result.java @@ -1,8 +1,5 @@ package jp.vmi.selenium.selenese.result; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import java.util.regex.Pattern; /** @@ -26,11 +23,6 @@ private Level(int value, int exitCode, int strictExitCode) { this.exitCode = exitCode; this.strictExitCode = strictExitCode; } - - @Override - public String toString() { - return name().toLowerCase(); - } } private static final Pattern SKIP_RE = Pattern.compile("ByGuice" @@ -41,7 +33,6 @@ public String toString() { + "|^org\\.eclipse\\.jdt\\."); private final String message; - private List screenshots = null; /** * Constructor. @@ -149,29 +140,6 @@ public String getMessage() { return message; } - /** - * Add screenshot information. - * - * @param path image path. - * @param label label. - */ - public void addScreenshot(String path, String label) { - if (path == null) - return; - if (screenshots == null) - screenshots = new ArrayList<>(); - screenshots.add(new Screenshot(path, label)); - } - - /** - * Get map of screenshots. - * - * @return map of screenshots. key is label, and value is path. - */ - public List getScreenshots() { - return screenshots != null ? screenshots : Collections.emptyList(); - } - /** * Is result of success? * diff --git a/src/main/java/jp/vmi/selenium/selenese/result/Success.java b/src/main/java/jp/vmi/selenium/selenese/result/Success.java index 50b6f9048..26c66815b 100644 --- a/src/main/java/jp/vmi/selenium/selenese/result/Success.java +++ b/src/main/java/jp/vmi/selenium/selenese/result/Success.java @@ -5,6 +5,9 @@ */ public class Success extends Result { + /** Default success */ + public static final Success SUCCESS = new Success("Success"); + /** * Constructor. * @@ -14,13 +17,6 @@ public Success(String message) { super(message); } - /** - * Constructor. - */ - public Success() { - this("Success"); - } - @Override public Level getLevel() { return Level.SUCCESS; diff --git a/src/main/resources/jp/vmi/html/result/result.html b/src/main/resources/jp/vmi/html/result/result.html index 6d85fe49c..851d877bb 100644 --- a/src/main/resources/jp/vmi/html/result/result.html +++ b/src/main/resources/jp/vmi/html/result/result.html @@ -334,14 +334,14 @@

${title;h}

#${selenese.name;h}Δt(ms)Screenshot - ${foreach selenese.commandList command}${@commandResults results selenese command}${@tail lastResult results} - + ${foreach selenese.commandList command} + ${command.index;i} ${foreach command.source item} ${item;h} ${end} - ${foreach results result , }${result.duration;n}${end} - ${foreach results result}${foreach result.result.screenshots screenshot}${if first_result}${if first_screenshot}${else}, ${end}${else}, ${end}${index_screenshot}:${screenshot.label;h}${end}${end} + ${@commandResults results selenese command}${foreach results result , }${result.duration;n}${end} + ${foreach command.screenshots screenshot , }${index_screenshot}:${screenshot.label;h}${end} ${end} @@ -372,7 +372,7 @@

${title;h}

${item;h} ${end} ${result.result;s} - ${foreach result.result.screenshots screenshot , }${index_screenshot}:${screenshot.label;h}${end} + ${foreach result.screenshots screenshot , }${index_screenshot}:${screenshot.label;h}${end} ${end} diff --git a/src/test/java/jp/vmi/selenium/selenese/command/CommandSequenceTest.java b/src/test/java/jp/vmi/selenium/selenese/command/CommandSequenceTest.java index 29e01267b..2ec02dd72 100644 --- a/src/test/java/jp/vmi/selenium/selenese/command/CommandSequenceTest.java +++ b/src/test/java/jp/vmi/selenium/selenese/command/CommandSequenceTest.java @@ -10,8 +10,8 @@ import jp.vmi.selenium.selenese.Context; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; +import static jp.vmi.selenium.selenese.result.Success.*; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.*; @@ -29,7 +29,7 @@ public DummyCommand(int index, String name, StartLoop startLoop) { @Override protected Result executeImpl(Context context, String... curArgs) { - return new Success(); + return SUCCESS; } } diff --git a/src/test/java/jp/vmi/selenium/selenese/command/UserDefinedCommandFactoryTest.java b/src/test/java/jp/vmi/selenium/selenese/command/UserDefinedCommandFactoryTest.java index 6e8495d2b..325a913c6 100644 --- a/src/test/java/jp/vmi/selenium/selenese/command/UserDefinedCommandFactoryTest.java +++ b/src/test/java/jp/vmi/selenium/selenese/command/UserDefinedCommandFactoryTest.java @@ -7,9 +7,9 @@ import jp.vmi.selenium.selenese.TestCase; import jp.vmi.selenium.selenese.inject.Binder; import jp.vmi.selenium.selenese.result.Result; -import jp.vmi.selenium.selenese.result.Success; import jp.vmi.selenium.testutils.TestBase; +import static jp.vmi.selenium.selenese.result.Success.*; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; @@ -26,7 +26,7 @@ private static class TestCommandNew extends AbstractCommand { @Override protected Result executeImpl(Context context, String... curArgs) { - return new Success(); + return SUCCESS; } }