Permalink
Browse files

re-enabled alert/confirm commands (#32) and add new supported command…

…s for prompt. (#192)
  • Loading branch information...
1 parent 477776d commit c77cb1acf27bdb387bf1455e7d2bf93edac1a61d @vmi committed Apr 3, 2016
View
@@ -1,6 +1,26 @@
Selenese Runner Java Relase Note
================================
+### 2.7.0
+
+* Re-enabled alert/confirm commands because Selenium supported the feature with `localStorage`. (#32)
+* Add new supported commands for prompt. (#192)
+ * `answerOnNextPrompt`
+ * `assertNotPrompt`
+ * `assertPrompt`
+ * `assertPromptNotPresent`
+ * `assertPromptPresent`
+ * `storePrompt`
+ * `storePromptPresent`
+ * `verifyNotPrompt`
+ * `verifyPrompt`
+ * `verifyPromptNotPresent`
+ * `verifyPromptPresent`
+ * `waitForNotPrompt`
+ * `waitForPrompt`
+ * `waitForPromptNotPresent`
+ * `waitForPromptPresent`
+
### 2.6.0
* Catch up Selenium 2.53.0.
@@ -6,6 +6,7 @@ addToCollection
allowNativeXpath
altKeyDown
altKeyUp
+answerOnNextPrompt
assertAlert
assertAlertNotPresent
assertAlertPresent
@@ -63,6 +64,7 @@ assertNotExpression
assertNotHtmlSource
assertNotLocation
assertNotOrdered
+assertNotPrompt
assertNotSelectOptions
assertNotSelectedId
assertNotSelectedIds
@@ -81,6 +83,9 @@ assertNotValue
assertNotVisible
assertNotXpathCount
assertOrdered
+assertPrompt
+assertPromptNotPresent
+assertPromptPresent
assertSelectOptions
assertSelectedId
assertSelectedIds
@@ -192,6 +197,8 @@ storeFor
storeHtmlSource
storeLocation
storeOrdered
+storePrompt
+storePromptPresent
storeSelectOptions
storeSelectedId
storeSelectedIds
@@ -272,6 +279,7 @@ verifyNotExpression
verifyNotHtmlSource
verifyNotLocation
verifyNotOrdered
+verifyNotPrompt
verifyNotSelectOptions
verifyNotSelectedId
verifyNotSelectedIds
@@ -290,6 +298,9 @@ verifyNotValue
verifyNotVisible
verifyNotXpathCount
verifyOrdered
+verifyPrompt
+verifyPromptNotPresent
+verifyPromptPresent
verifySelectOptions
verifySelectedId
verifySelectedIds
@@ -368,6 +379,7 @@ waitForNotExpression
waitForNotHtmlSource
waitForNotLocation
waitForNotOrdered
+waitForNotPrompt
waitForNotSelectOptions
waitForNotSelectedId
waitForNotSelectedIds
@@ -388,6 +400,9 @@ waitForNotXpathCount
waitForOrdered
waitForPageToLoad
waitForPopUp
+waitForPrompt
+waitForPromptNotPresent
+waitForPromptPresent
waitForSelectOptions
waitForSelectedId
waitForSelectedIds
@@ -1,6 +1,5 @@
[Unsupported command]
addScript
-answerOnNextPrompt
assertAllWindowIds
assertCursorPosition
assertErrorOnNext
@@ -11,13 +10,9 @@ assertNotCursorPosition
assertNotErrorOnNext
assertNotFailureOnNext
assertNotMouseSpeed
-assertNotPrompt
assertNotSelected
assertNotWhetherThisFrameMatchFrameExpression
assertNotWhetherThisWindowMatchWindowExpression
-assertPrompt
-assertPromptNotPresent
-assertPromptPresent
assertSelected
assertWhetherThisFrameMatchFrameExpression
assertWhetherThisWindowMatchWindowExpression
@@ -39,8 +34,6 @@ storeCursorPosition
storeErrorOnNext
storeFailureOnNext
storeMouseSpeed
-storePrompt
-storePromptPresent
storeSelected
storeWhetherThisFrameMatchFrameExpression
storeWhetherThisWindowMatchWindowExpression
@@ -54,13 +47,9 @@ verifyNotCursorPosition
verifyNotErrorOnNext
verifyNotFailureOnNext
verifyNotMouseSpeed
-verifyNotPrompt
verifyNotSelected
verifyNotWhetherThisFrameMatchFrameExpression
verifyNotWhetherThisWindowMatchWindowExpression
-verifyPrompt
-verifyPromptNotPresent
-verifyPromptPresent
verifySelected
verifyWhetherThisFrameMatchFrameExpression
verifyWhetherThisWindowMatchWindowExpression
@@ -74,13 +63,9 @@ waitForNotCursorPosition
waitForNotErrorOnNext
waitForNotFailureOnNext
waitForNotMouseSpeed
-waitForNotPrompt
waitForNotSelected
waitForNotWhetherThisFrameMatchFrameExpression
waitForNotWhetherThisWindowMatchWindowExpression
-waitForPrompt
-waitForPromptNotPresent
-waitForPromptPresent
waitForSelected
waitForWhetherThisFrameMatchFrameExpression
waitForWhetherThisWindowMatchWindowExpression
@@ -180,14 +180,6 @@ public ICommand newCommand(int index, String name, String... args) {
if (subCommand != null)
return new BuiltInCommand(index, name, args, subCommand, andWait);
- // FIXME #32 workaround alert command handling.
- if (realName.matches("(?i)(?:assert|verify|waitFor)(?:Alert|Confirmation|Prompt)(?:(?:Not)?Present)?")) {
- StringBuilder echo = new StringBuilder(name);
- for (String arg : args)
- echo.append(" ").append(arg);
- return new Echo(index, name, echo.toString());
- }
-
// See: http://selenium.googlecode.com/svn/trunk/ide/main/src/content/selenium-core/reference.html
// Assertion or Accessor
Matcher matcher = COMMAND_PATTERN.matcher(name);
@@ -0,0 +1,29 @@
+package jp.vmi.selenium.selenese.subcommand;
+
+import jp.vmi.selenium.selenese.Context;
+import jp.vmi.selenium.selenese.command.ArgumentType;
+import jp.vmi.selenium.selenese.utils.DialogOverride;
+
+/**
+ * Command "answerOnNextPrompt".
+ */
+public class AnswerOnNextPrompt extends AbstractSubCommand<Void> {
+
+ private final DialogOverride dialogOverride;
+
+ /**
+ * Constructor.
+ *
+ * @param dialogOverride dialog override.
+ */
+ public AnswerOnNextPrompt(DialogOverride dialogOverride) {
+ super(ArgumentType.VALUE);
+ this.dialogOverride = dialogOverride;
+ }
+
+ @Override
+ public Void execute(Context context, String... args) {
+ dialogOverride.answerOnNextPrompt(context.getWrappedDriver(), args[0]);
+ return null;
+ }
+}
@@ -0,0 +1,27 @@
+package jp.vmi.selenium.selenese.subcommand;
+
+import jp.vmi.selenium.selenese.Context;
+import jp.vmi.selenium.selenese.utils.DialogOverride;
+
+/**
+ * Command "getPrompt".
+ */
+public class GetPrompt extends AbstractSubCommand<String> {
+
+ private final DialogOverride dialogOverride;
+
+ /**
+ * Constructor.
+ *
+ * @param dialogOverride dialog override.
+ */
+ public GetPrompt(DialogOverride dialogOverride) {
+ super();
+ this.dialogOverride = dialogOverride;
+ }
+
+ @Override
+ public String execute(Context context, String... args) {
+ return dialogOverride.getNextPrompt(context.getWrappedDriver());
+ }
+}
@@ -0,0 +1,27 @@
+package jp.vmi.selenium.selenese.subcommand;
+
+import jp.vmi.selenium.selenese.Context;
+import jp.vmi.selenium.selenese.utils.DialogOverride;
+
+/**
+ * Command "IsPromptPresent".
+ */
+public class IsPromptPresent extends AbstractSubCommand<Boolean> {
+
+ private final DialogOverride dialogOverride;
+
+ /**
+ * Constructor.
+ *
+ * @param dialogOverride dialog override.
+ */
+ public IsPromptPresent(DialogOverride dialogOverride) {
+ super();
+ this.dialogOverride = dialogOverride;
+ }
+
+ @Override
+ public Boolean execute(Context context, String... args) {
+ return dialogOverride.isPromptPresent(context.getWrappedDriver());
+ }
+}
@@ -12,6 +12,7 @@
import jp.vmi.selenium.selenese.command.ArgumentType;
import jp.vmi.selenium.selenese.locator.WebDriverElementFinder;
import jp.vmi.selenium.selenese.subcommand.MouseEventHandler.MouseEventType;
+import jp.vmi.selenium.selenese.utils.DialogOverride;
import static jp.vmi.selenium.selenese.command.ArgumentType.*;
@@ -21,11 +22,10 @@
public class SubCommandMap {
private final Map<String, ISubCommand<?>> subCommands = Maps.newHashMap();
- private final boolean enableAlertOverrides = true;
private final JavascriptLibrary javascriptLibrary;
private final KeyState keyState;
- private final AlertOverride alertOverride;
+ private final DialogOverride alertOverride;
private final SeleneseRunnerWindows windows;
private final Context context;
@@ -46,7 +46,7 @@ public SubCommandMap(Context context) {
this.context = context;
this.javascriptLibrary = new JavascriptLibrary();
this.keyState = new KeyState();
- this.alertOverride = new AlertOverride(enableAlertOverrides);
+ this.alertOverride = new DialogOverride();
this.windows = new SeleneseRunnerWindows(context);
setUpSubCommands();
}
@@ -65,6 +65,9 @@ public Context getContext() {
private void setUpSubCommands() {
WebDriverElementFinder elementFinder = context.getElementFinder();
+
+ //// Selenium webdriven commands:
+
register(new AddLocationStrategy(elementFinder), "addLocationStrategy", VALUE, VALUE);
register(new AddSelection(javascriptLibrary, elementFinder), "addSelection", LOCATOR, OPTION_LOCATOR);
register(new AllowNativeXPath(), "allowNativeXpath", VALUE);
@@ -178,15 +181,19 @@ private void setUpSubCommands() {
register(new WindowFocus(javascriptLibrary), "windowFocus");
// windowMaximize
- // Customized methods.
+ //// Customized commands:
+
// "openWindow"
// "runScript"
-
register(new GetEval());
register(new GetCssCount());
register(new GetSpeed());
register(new IsSomethingSelected());
register(new WaitForCondition());
+ register(new AnswerOnNextPrompt(alertOverride));
+ register(new GetPrompt(alertOverride));
+ register(new IsPromptPresent(alertOverride));
+
register(new GetSelected(GetSelected.Type.LABEL, false));
register(new GetSelected(GetSelected.Type.LABEL, true));
register(new GetSelected(GetSelected.Type.VALUE, false));
@@ -0,0 +1,74 @@
+package jp.vmi.selenium.selenese.utils;
+
+import java.util.Map;
+
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.WebDriver;
+
+import com.thoughtworks.selenium.SeleniumException;
+import com.thoughtworks.selenium.webdriven.commands.AlertOverride;
+
+/**
+ * Add prompt handler.
+ */
+public class DialogOverride extends AlertOverride {
+
+ private static final String replaceAlertMethod;
+ private static final String answerOnNextPrompt;
+ private static final String getNextPrompt;
+ private static final String isPromptPresent;
+
+ static {
+ Map<String, String> jsMap = SeleniumUtils.loadJS(DialogOverride.class.getResourceAsStream("DialogOverride.js"));
+ replaceAlertMethod = jsMap.get("replaceAlertMethod");
+ answerOnNextPrompt = jsMap.get("answerOnNextPrompt");
+ getNextPrompt = jsMap.get("getNextPrompt");
+ isPromptPresent = jsMap.get("isPromptPresent");
+ }
+
+ /**
+ * Constructor.
+ */
+ public DialogOverride() {
+ super(true);
+ }
+
+ @Override
+ public void replaceAlertMethod(WebDriver driver) {
+ super.replaceAlertMethod(driver);
+ ((JavascriptExecutor) driver).executeScript(replaceAlertMethod);
+ }
+
+ /**
+ * Set answer message for prompt.
+ *
+ * @param driver WebDriver object.
+ * @param msg answer message used on next prompt.
+ */
+ public void answerOnNextPrompt(WebDriver driver, String msg) {
+ ((JavascriptExecutor) driver).executeScript(answerOnNextPrompt, msg);
+ }
+
+ /**
+ * Get next prompt.
+ *
+ * @param driver WebDriver object.
+ * @return prompt.
+ */
+ public String getNextPrompt(WebDriver driver) {
+ String result = (String) ((JavascriptExecutor) driver).executeScript(getNextPrompt);
+ if (result == null)
+ throw new SeleniumException("There were no prompts");
+ return result;
+ }
+
+ /**
+ * Test of whether a prompt was displayed.
+ *
+ * @param driver WebDriver object.
+ * @return prompt is dislayed if true.
+ */
+ public boolean isPromptPresent(WebDriver driver) {
+ return Boolean.TRUE.equals(((JavascriptExecutor) driver).executeScript(isPromptPresent));
+ }
+}
Oops, something went wrong.

0 comments on commit c77cb1a

Please sign in to comment.