diff --git a/RELEASENOTE.md b/RELEASENOTE.md index e31e9d4cf..afe8e0395 100644 --- a/RELEASENOTE.md +++ b/RELEASENOTE.md @@ -1,6 +1,10 @@ Selenese Runner Java Relase Note ================================ +### 3.33.0 + +* Fix not to replace undefined variables. (#324) + ### 3.32.0 * Change not to retry the composite command if an error occurs. (#320) diff --git a/src/main/java/jp/vmi/selenium/selenese/VarsMap.java b/src/main/java/jp/vmi/selenium/selenese/VarsMap.java index ac1ba8803..55b55299c 100644 --- a/src/main/java/jp/vmi/selenium/selenese/VarsMap.java +++ b/src/main/java/jp/vmi/selenium/selenese/VarsMap.java @@ -98,11 +98,15 @@ public String replaceVars(boolean isScript, String expr) { if (prevEnd < nextStart) result.append(expr.substring(prevEnd, nextStart)); String name = matcher.group("name"); - Object rawValue = get(name); - if (isScript) - result.append(new Gson().toJson(rawValue)); - else - result.append(SeleniumUtils.convertToString(rawValue)); + if (containsKey(name)) { + Object rawValue = get(name); + if (isScript) + result.append(new Gson().toJson(rawValue)); + else + result.append(SeleniumUtils.convertToString(rawValue)); + } else { + result.append(matcher.group()); + } prevEnd = matcher.end(); } if (prevEnd < expr.length()) diff --git a/src/test/java/jp/vmi/selenium/selenese/DriverDependentTest.java b/src/test/java/jp/vmi/selenium/selenese/DriverDependentTest.java index f1ca8763b..36dcfba97 100644 --- a/src/test/java/jp/vmi/selenium/selenese/DriverDependentTest.java +++ b/src/test/java/jp/vmi/selenium/selenese/DriverDependentTest.java @@ -501,4 +501,12 @@ public void testNoReplaceAlertMethod() { runner.setReplaceAlertMethod(true); } + + @Test + public void issue324() { + assumeNot(PHANTOMJS, HTMLUNIT, IE); + execute("testcase_issue324.side"); + assertThat(result, is(instanceOf(Success.class))); + } + } diff --git a/src/test/resources/selenese/testcase_issue324.side b/src/test/resources/selenese/testcase_issue324.side new file mode 100644 index 000000000..730a42418 --- /dev/null +++ b/src/test/resources/selenese/testcase_issue324.side @@ -0,0 +1,56 @@ +{ + "id": "e55b5d28-ec31-4401-8d2a-5b7829f36d82", + "version": "2.0", + "name": "test", + "url": "http://localhost/", + "tests": [{ + "id": "834b529f-c7fc-4d43-bbdf-0cfabe285c75", + "name": "issue324", + "commands": [{ + "id": "839bb8c7-14da-49dd-9554-e593be46fd3e", + "comment": "", + "command": "open", + "target": "http://localhost/", + "targets": [], + "value": "" + }, { + "id": "392e5b60-ed91-445b-9827-001d5695fece", + "comment": "", + "command": "store", + "target": "hello", + "targets": [], + "value": "var_side01" + }, { + "id": "2cdd69da-89eb-4c45-9265-3f4497c8d632", + "comment": "", + "command": "executeScript", + "target": "const var_js = ${var_side01}; return `${var_js} world`;", + "targets": [], + "value": "var_side02" + }, { + "id": "7c5e78e4-f6fd-4a21-8e0b-c8a29633abeb", + "comment": "", + "command": "echo", + "target": "var_side01=${var_side01}, var_side02=${var_side02}", + "targets": [], + "value": "" + }, { + "id": "846d5221-9f82-48f3-8b65-5711614b163f", + "comment": "", + "command": "assert", + "target": "var_side02", + "targets": [], + "value": "hello world" + }] + }], + "suites": [{ + "id": "e7b7100f-dcc5-4d14-a6cc-7987a9d6f804", + "name": "Default Suite", + "persistSession": false, + "parallel": false, + "timeout": 300, + "tests": ["834b529f-c7fc-4d43-bbdf-0cfabe285c75"] + }], + "urls": ["http://localhost/"], + "plugins": [] +} \ No newline at end of file