Marking tests as Passed, Failed or in Error using MarkFailed, MarkPassed, MarkError in Katalon Studio

We previously looked at the idea of writing information to the log files. This included the output of variable values and status messages. But, what if you need to stop the test and mark it as failed because the data you needed wasn’t there, or the information you did read indicates a more serious problem? Katalon Studio will mark a test as failed if the command fails to execute, but there is a way to fail the test because of other errors. Again, it takes a little digging to find the right command, but they certainly exist. To start, an import statement is needed at the top of the project: import com.kms.katalon.core.util.KeywordUtil Once that’s in place, a test can be flagged in several ways using one of these commands: KeywordUtil.markPassed KeywordUtil.markFailed KeywordUtil.markError KeywordUtil.markWarning * https://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/util/KeywordUtil.html With these KeywordUtil commands, you have a great deal of flexibility in controlling the execution of your tests. For this small snippet, the two values […]

Output status messages and test information by writing to the Log File Viewer in Katalon Studio

One of my more heavily used functions in the Selenium IDE was writing to the LOG file. It was an excellent way of debugging code and displaying what values were read. It was also used to show which test was running and other status information. As a comparison, writing to the log file in the IDE looked like: LOG.warn(“– Begin name of test Script  –“); LOG.warn(“The calculated value is ” + storedVars[‘variable’] + ” — The site value is ” + storedVars[‘variable’]); Katalon has a similar log view, that looks like the following: While Katalon Studio has a log file, several of them in fact, finding out how to write to them takes some digging. To get right to it, there is an import file and a keyword definition that need to be added to your Test Case. The following import statement needs to be added: import com.kms.katalon.core.logging.KeywordLogger as KeywordLogger At the end of the import statements, add the following […]

Round and Round with the For..Next in Katalon Studio

Another big improvement with Katalon Studio is the looping mechanisms. The Selenium IDE could use loops with the addition of the SelBlocks plugin, but Katalon and Groovy support that natively and I use it frequently to read values from a table. From the old BASIC days, the FOR loop is: For A=1 to 5 (Step 1) Print(“hello world”) Next A We have quite a few shortcuts and it now looks like this: for (loop = 1; loop <=5; loop++) {   println(“hello world”) } To get started, Katalon offers a way to set up a FOR loop in Manual view. If you click the down arrow next to Add, there is an option for Looping Statements and within there, For Loop Statement. Choosing this option, creates a FOR loop that looks like: for (def index : (0..0)) { } While either format is acceptable, I actually prefer: for (loop = 1; loop <=5; loop++) For my inexperienced mind, it’s a […]

Conditional Statements – IF .. ELSE IF in Katalon Studio

One of the big advantages of using Katalon Studio is the ability to use the underlying Groovy subsystem. And with that comes the means to do conditional branching, the ubiquitous IF and IF .. ELSE statement. This allows you to perform all sorts of actions based on what values are read from the site. In my case, if a value is less than 0, it could mean the data import didn’t succeed. That can easily be expressed as: if (salesPlan <= 0) {     log.logWarning(‘ERROR: The Sales Plan Value is $0 or less. A problem may have occurred with the import’) } The IF statement can be entered directly into the Script editor, but it can also be constructed using the Manual view. If you click the down arrow next to Add, there is an option for Decision-making Statements, and within there is IF, Else, and Else If. This is very handy to get started the first couple of […]

Getting the Length of a String and the Size of a List

Keeping with the theme of working with Strings, there are many times when you need to know the length of that string. For example, when using substring, you want to know how many characters are in the text you just read from the site. Of you want to make sure the text actually has a length or else there is nothing to act upon. For example, take this small snippet of code: String address=”1650 E WASHINGTON AVE, NORTH LITTLE ROCK, AR 72114″ println(address.length()) The result would be 50 as there are 50 characters in the line. The length includes the commas. This could be used to verify the length of a state abbreviation is 2 characters. It could also be used to verify a phone number is 10 digits or that a name is less than 25 characters, such as: if (address.length()==0) if (address.length()<2) In conjunction with the length of a string, it’s possible to get the size of a […]