Navigation Menu

Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #116 from xebia/ide_ensure_check
Browse files Browse the repository at this point in the history
Selenium 'verifyText' becomes 'check is getText'
  • Loading branch information
raboof committed Jun 28, 2015
2 parents dd5e71b + f0b2176 commit 4d74eea
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
24 changes: 15 additions & 9 deletions src/main/ide/chrome/content/formats/xebiumformatter.js
Expand Up @@ -56,7 +56,6 @@ function formatCommands(commands) {
return commandsText;
}


function getSourceForCommand(commandObj) {
// For some commands, Xebium performs an extra "isElementPresent" check. See the LocatorCheck.java.
var locatorCheck = {
Expand Down Expand Up @@ -124,9 +123,9 @@ function getSourceForCommand(commandObj) {
if (/^is/.test(def.name)) {
return "| ensure | do | " + command + " | on | " + escape(target) + " |";
} else if (value) {
return "| check | is | " + command + " | on | " + escape(target) + " | " + escape(value, "check") + " |";
return "| check | is | " + command.replace(/^verify/, "get") + " | on | " + escape(target) + " | " + escape(value, "check") + " |";
} else {
return "| check | is | " + command + " | " + escape(target, "check") + " |";
return "| check | is | " + command.replace(/^verify/, "get") + " | " + escape(target, "check") + " |";
}
} else {
return ((locatorCheck[def.name] || /^waitFor/.test(command)) ? "| ensure " : "") + "| do | " + command + " | on | " + escape(target) + (value === '' ? "" : " | with | " + escape(value)) + " |";
Expand Down Expand Up @@ -222,12 +221,19 @@ function getCommandForSource(line) {

var match;

// | check/ensure | is/do | ${command} |[ on | ]${target} |[ [with |] ${value} |]
if (match = /^\|\s*(?:(ensure|check)\s*\|\s*|)(?:do|is)\s*\|\s*([^\|\s]+)\s*\|\s*(?:on\s*\|(?:\s*((?:!-.*?-!)?|[^\|]+?)\s*\|(?:\s*(?:with\s*\|\s*|)((?:!-.*?-!)|[^\|]+?)\s*\||)|)|((?:!-.*?-!)|[^\|]+?)\s*\|)/.exec(line)) {
return new Command(match[2],
match[3] ? unescape(match[3])
: (match[5] ? unescape(match[5]) : undefined),
match[4] ? unescape(match[4], match[1]) : undefined);
// | check | is/do | ${command} |[ on | ]${target} |[ [with |] ${value} |]
if (match = /^\|\s*(?:check\s*\|\s*|)(?:do|is)\s*\|\s*([^\|\s]+)\s*\|\s*(?:on\s*\|(?:\s*((?:!-.*?-!)?|[^\|]+?)\s*\|(?:\s*(?:with\s*\|\s*|)((?:!-.*?-!)|[^\|]+?)\s*\||)|)|((?:!-.*?-!)|[^\|]+?)\s*\|)/.exec(line)) {
return new Command(match[1].replace(/^get/, 'verify'),
match[2] ? unescape(match[2])
: (match[4] ? unescape(match[4]) : undefined),
match[3] ? unescape(match[3], 'check') : undefined);

// | ensure | is/do | ${command} |[ on | ]${target} |[ [with |] ${value} |]
} else if (match = /^\|\s*(?:ensure\s*\|\s*|)(?:do|is)\s*\|\s*([^\|\s]+)\s*\|\s*(?:on\s*\|(?:\s*((?:!-.*?-!)?|[^\|]+?)\s*\|(?:\s*(?:with\s*\|\s*|)((?:!-.*?-!)|[^\|]+?)\s*\||)|)|((?:!-.*?-!)|[^\|]+?)\s*\|)/.exec(line)) {
return new Command(match[1],
match[2] ? unescape(match[2])
: (match[4] ? unescape(match[4]) : undefined),
match[3] ? unescape(match[3], 'ensure') : undefined);

// format: | $value= | is | ${command} | on | ${target} |
} else if (match = /^\|\s*\$([^\|\s]+)=\s*\|\s*is\s*\|\s*([^\|\s]+)\s*\|\s*on\s*\|\s*((!-.*-!)|[^\|]+?)\s*\|/.exec(line)) {
Expand Down
53 changes: 37 additions & 16 deletions src/test/java/com/xebia/fitnesse/selenium/JavascriptTestCase.java
Expand Up @@ -344,7 +344,7 @@ public void shouldStoreCommandOnTargetToFitnesse() {
"| start browser | firefox | on url | http://example.com |\n" +
"| $locVar= | is | storeLocation |\n" +
"| $bar= | is | storeTest | on | foo |\n" +
"| check | is | verifyText | on | foo | $locVar |\n" +
"| check | is | getText | on | foo | $locVar |\n" +
"| stop browser |\n"
, result);
}
Expand Down Expand Up @@ -406,7 +406,7 @@ public void shouldParseRightActionToFitnesse() {
"| script | selenium driver fixture |\n" +
"| start browser | firefox | on url | http://example.com |\n" +
"| do | open | on | !-http://example.com-! |\n" +
"| check | is | verifyText | on | css=h1 | Header |\n" +
"| check | is | getText | on | css=h1 | Header |\n" +
"| ensure | do | waitForTextNotPresent | on | //c[blah=*]/d/e |\n" +
"| ensure | do | focus | on | input |\n" +
"| stop browser |\n"
Expand All @@ -424,7 +424,7 @@ public void shoudlParseVariablesInText() {
assertEquals(
"| script | selenium driver fixture |\n" +
"| start browser | firefox | on url | http://example.com |\n" +
"| check | is | verifyText | on | link=$myVariable | Text$myVariable Text |\n" +
"| check | is | getText | on | link=$myVariable | Text$myVariable Text |\n" +
"| stop browser |\n"
, result);
}
Expand All @@ -439,7 +439,7 @@ public void shoudlEscapeBars() {
assertEquals(
"| script | selenium driver fixture |\n" +
"| start browser | firefox | on url | http://example.com |\n" +
"| check | is | verifyText | on | !-Some | text-! | !-more | text-! |\n" +
"| check | is | getText | on | !-Some | text-! | !-more | text-! |\n" +
"| stop browser |\n"
, result);
}
Expand All @@ -454,7 +454,7 @@ public void shoudlConvertExact() {
assertEquals(
"| script | selenium driver fixture |\n" +
"| start browser | firefox | on url | http://example.com |\n" +
"| check | is | verifyText | on | field | Out* |\n" +
"| check | is | getText | on | field | Out* |\n" +
"| stop browser |\n"
, result);
}
Expand All @@ -474,11 +474,11 @@ public void shoudlConvertGlob() {
assertEquals(
"| script | selenium driver fixture |\n" +
"| start browser | firefox | on url | http://example.com |\n" +
"| check | is | verifyText | on | field | Test |\n" +
"| check | is | verifyText | on | field | =~/Test.*Te\\?\\[\\]\\{\\}\\(\\)\\..*\\+\\^\\$st/ |\n" +
"| check | is | verifyText | on | field | Test |\n" +
"| check | is | verifyText | on | field | =~/Test.*Test.*Test/ |\n" +
"| check | is | verifyText | on | field | =~/X\\[ea\\]b.*ium/ |\n" +
"| check | is | getText | on | field | Test |\n" +
"| check | is | getText | on | field | =~/Test.*Te\\?\\[\\]\\{\\}\\(\\)\\..*\\+\\^\\$st/ |\n" +
"| check | is | getText | on | field | Test |\n" +
"| check | is | getText | on | field | =~/Test.*Test.*Test/ |\n" +
"| check | is | getText | on | field | =~/X\\[ea\\]b.*ium/ |\n" +
"| stop browser |\n"
, result);
}
Expand All @@ -495,7 +495,7 @@ public void shouldAlwaysMakeEnsureCommandsForWaitForCommands() {
assertEquals(
"| script | selenium driver fixture |\n" +
"| start browser | firefox | on url | http://example.com |\n" +
"| check | is | verifyText | on | field | Test |\n" +
"| check | is | getText | on | field | Test |\n" +
"| ensure | do | waitForText | on | field | with | Test |\n" +
"| stop browser |\n"
, result);
Expand All @@ -514,9 +514,9 @@ public void shoudlConvertRegexp() {
assertEquals(
"| script | selenium driver fixture |\n" +
"| start browser | firefox | on url | http://example.com |\n" +
"| check | is | verifyText | on | field | =~/.*A.*/ |\n" +
"| check | is | verifyText | on | field | =~/.*A.*/ |\n" +
"| check | is | verifyText | on | field | =~/.*AsdFgh.*/ |\n" +
"| check | is | getText | on | field | =~/.*A.*/ |\n" +
"| check | is | getText | on | field | =~/.*A.*/ |\n" +
"| check | is | getText | on | field | =~/.*AsdFgh.*/ |\n" +
"| stop browser |\n"
, result);
}
Expand Down Expand Up @@ -707,7 +707,7 @@ public void shouldParseSubstitutedVariables() {
public void shouldParseFailedCheckCommands() {
eval("var fittable = 'ensure\tdo\twaitForElementPresent\t[false] expected [link=Xebium]\\n' +" +
"'check\tis\tverifyText\ton\tlink=Xebium\t[Execution of command failed: Element link=Xebium not found] expected [Xebium]\\n' +" +
"'check\tis\twaitForTitle\t[Google] expected [xebia/Xebium á GitHub[?]]\\n' +" +
"'check\tis\twaitForTitle\t[Google] expected [xebia/Xebium á GitHub[?]]\\n' +" +
"'check\tis\tverifyText\ton\tcss=h1\t/.*Page[a-z]?/ found in: FrontPage\\n' +" +
"'check\tis\tverifyText\ton\tcss=h1\t/.*Page[a-z]?/ not found in: FrontPage';");

Expand All @@ -726,7 +726,7 @@ public void shouldParseFailedCheckCommands() {
assertEquals("Xebium", eval("commands[1].value"));

assertEquals(eval("commands[2].comment").toString(), "waitForTitle", eval("commands[2].command"));
assertEquals("xebia/Xebium á GitHub[?]", eval("commands[2].target"));
assertEquals("xebia/Xebium á GitHub[?]", eval("commands[2].target"));
assertEquals("", eval("commands[2].value"));

assertEquals(eval("commands[3].comment").toString(), "verifyText", eval("commands[3].command"));
Expand All @@ -738,4 +738,25 @@ public void shouldParseFailedCheckCommands() {
assertEquals("regexp:.*Page[a-z]?", eval("commands[4].value"));

}

@Test
public void testCheckIsRoundtrip() {
eval("var tc = new TestCase(); tc.baseUrl = 'http://example.com';");
eval("var commands = [];");
eval("commands.push(new Command('verifyText', 'loc', 'http://myurl.com'))");
eval("tc.commands = commands;");
eval("var formatted = format(tc, 'name');");
String result = (String) eval("formatted");
assertEquals(
"| script | selenium driver fixture |\n" +
"| start browser | firefox | on url | http://example.com |\n" +
"| check | is | getText | on | loc | !-http://myurl.com-! |\n" +
"| stop browser |\n"
, result);

eval("var tc2 = new TestCase()");
eval("parse(tc2, formatted)");
assertEquals(1.0, eval("tc2.commands.length"));
assertEquals("verifyText", eval("tc2.commands[0].command"));
}
}

0 comments on commit 4d74eea

Please sign in to comment.