weixin_39722692
weixin_39722692
2020-11-29 04:53

Can't use fixture-defined variable in an expected value check

I have a variable defined in a top-level SuiteSetup page which calls a groovy util to populate it:

|$idString= | getIdPattern |

Later, in my test, I want to use this variable in a script table that uses the check method:

| check | value is | =~/searches\/mobee\/navigations\/products\/${$idString}/ |

When executed, this test throws the following Java exception: nternal Exceptions: java.util.regex.PatternSyntaxException: Illegal repetition near index 20 navigations\/mobee\/${$idString} ^ java.util.regex.Pattern.error(Pattern.java:1713) java.util.regex.Pattern.closure(Pattern.java:2775) java.util.regex.Pattern.sequence(Pattern.java:1889) java.util.regex.Pattern.expr(Pattern.java:1752) java.util.regex.Pattern.compile(Pattern.java:1460) java.util.regex.Pattern.(Pattern.java:1133) java.util.regex.Pattern.compile(Pattern.java:823) fitnesse.slimTables.SlimTable$Comparator.evaluateRegularExpression(SlimTable.java:795) fitnesse.slimTables.SlimTable$Comparator.evaluateRegularExpressionIfPresent(SlimTable.java:788) fitnesse.slimTables.SlimTable$Comparator.evaluate(SlimTable.java:768) fitnesse.slimTables.SlimTable$ReturnedValueExpectation.createEvaluationMessage(SlimTable.java:655) fitnesse.slimTables.SlimTable$Expectation.evaluationMessage(SlimTable.java:479) fitnesse.slimTables.SlimTable$Expectation.evaluateExpectation(SlimTable.java:466) fitnesse.responders.run.slimResponder.SlimTestSystem.evaluateExpectations(SlimTestSystem.java:376) fitnesse.responders.run.slimResponder.SlimTestSystem.evaluateTables(SlimTestSystem.java:385) fitnesse.responders.run.slimResponder.HtmlSlimTestSystem.createHtmlResults(HtmlSlimTestSystem.java:40) fitnesse.responders.run.slimResponder.SlimTestSystem.processTablesAndGetHtml(SlimTestSystem.java:307) fitnesse.responders.run.slimResponder.SlimTestSystem.processAllTablesOnPage(SlimTestSystem.java:290) fitnesse.responders.run.slimResponder.SlimTestSystem.runTestsAndGenerateHtml(SlimTestSystem.java:234) fitnesse.responders.run.MultipleTestsRunner.executeTestSystemPages(MultipleTestsRunner.java:140) fitnesse.responders.run.MultipleTestsRunner.startTestSystemAndExecutePages(MultipleTestsRunner.java:120) fitnesse.responders.run.MultipleTestsRunner.executePagesInTestSystem(MultipleTestsRunner.java:106) fitnesse.responders.run.MultipleTestsRunner.internalExecuteTestPages(MultipleTestsRunner.java:86) fitnesse.responders.run.MultipleTestsRunner.executeTestPages(MultipleTestsRunner.java:58) fitnesse.responders.run.TestResponder.performExecution(TestResponder.java:145) fitnesse.responders.run.TestResponder.doSending(TestResponder.java:45) fitnesse.responders.ChunkingResponder.startSending(ChunkingResponder.java:67) fitnesse.responders.ChunkingResponder.access$000(ChunkingResponder.java:17) fitnesse.responders.ChunkingResponder$RespondingRunnable.run(ChunkingResponder.java:106) java.lang.Thread.run(Thread.java:680)

Now, we tried removing the expando directive to this:

| check | value is | =~/searches\/mobee\/navigations\/products\/$idString/ |

However the variable was not expanded in the check. Our workaround is to prefix every test with this:

| $idString= | echo | $idString |

Not pretty. Is there a better way?

该提问来源于开源项目:unclebob/fitnesse

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39709262 weixin_39709262 5月前

    Hi Woody , thanks for your reply. I'm a coworker of Matt and would like to ask a follow on question.

    We have Symbols that are defined by the output of a method on a fixture, and we would like to use them across hundreds of test pages.

    You stated that Symbols should be initialized in each test page, but we still would like to put them in a centralized place to avoid having to maintain them in hundreds of tests. Where would you recommend we put the Symbol initialization so they could be used across these test pages?

    Thanks!

    点赞 评论 复制链接分享
  • weixin_39762348 weixin_39762348 5月前

    If you have a substantial number of symbols that need to be initialized in each page and you want to share those accross pages, there are two possible solutions to consider: 1. Create a static page that has a table including all of the common symbols that need to be initialized and the stuff you need to initialiize it with. Then use "!include -c CommonSymbolDefs" in each page or the SetUp that the pages share. 2. Create a Scenario that does all of the definitions and put it in your ScenarioLibrary. Then call that scenario in each test. (this option only works with Slim).

    Either of these options would allow you to centralize the management of the symbol definitions without having to do a lot of maintenance.

    点赞 评论 复制链接分享
  • weixin_39709262 weixin_39709262 5月前

    Thanks Woody, that would take care of centralizing the symbol definitions. Another factor is that we want to also optimize the number of calls we had to make to the SUT. Since the Symbol definition is not going to change across those test pages, we are hoping there's a way it could be defined once, and than used across multiple tests, would that be possible? Thanks!

    点赞 评论 复制链接分享
  • weixin_39762348 weixin_39762348 5月前

    If these are values that never change, you could create a singleton that does a smart fetch of the values. So the first time it needs to fetch, it hits the system; and on the second time it uses a value cached in the singleton. This is pretty safe unless you have some volatility of the values and want to run multiple tests in parallel on the same wiki.

    点赞 评论 复制链接分享

相关推荐