Changing the scope of a variable to be available within a Method
After reading the value from a dropdown, I wanted to use that piece of information for a comparison test in another part of the Test Case. That's not a problem, except that I want to use the variable within a defined Method within the test case. I've done this sort of thing before and passed the needed values to the method. The Method didn't need any parameters, so I looked for another way to make that variable more "global" in scope. Turns out this can be done using @Field The first step is to import the correct library import groovy.transform.Field From there, "flag" the corresponding variable and change it's scope. @Field String quoteBranchName quoteBranchName=allQuoteBranchesList[0] log.logWarning('The listed Branch in the quote is: ' + quoteBranchName) That variable can now be referenced within a Method defined within that same Test Case def addInventoryItem() { log.logWarning('The listed Branch in the quote is: ' + quoteBranchName) if (inventoryLocations.contains(quoteBranchName)==false){ log.logError("The Inventory Item does not match […]
Recent Comments