Convert from String to Integer to Float and back again

As you read values off a site, there will come a time when you need to manipulate them, such as performing calculations or making comparisons. That doesn’t seem to be problem until you end up with Strings being compared to Integers. For the most part, a value read off a page will be a string because you don’t always know what it contains. For example, “New Sales Company” is a string of characters. On the other side, 537273 is a number. However, $537,273, which you can identify as numbers is actually a  String value as far as the code is concerned. Even after you remove the dollar sign and comma, the value type will still be treated as a string because that’s how it was initially read. Comparing a string to an integer will cause a mismatch, but there is a simple way to handle that. The ValueOf() statement allows the comparison of values as a certain type. Taking the […]

Filling forms with random numbers in Katalon Studio

If you’re filling in forms, inevitably there will be a need to use random numbers. For me, since I’m dealing with a sales dashboard, this means entering dollar figures and percentage values. It’s certainly possible to enter the same figure over and over again, but it’s just as easy to use a few lines of code and generate some random data. A basic form of the random number command can look like this: randomNumber=rnd.nextInt(10) – A random number between 0 and 10 This will create a simple random number between 0 and 10. That unto itself is quite fine and can be used for any number of applications. It could be appended to the end of text to make a Title, Subject or similar a little more random. It’s a good start, but there is certainly more that can be done. To return my example, I want to enter sales figures that range from 100,000 to 250,000. I also want […]

Working with Dates and Date Formatting in Katalon Studio

Working with dates in Groovy is actually quite easy, once you understand the proper formatting. For my tests, I use the date to check when an import was run. Another use is to append the date to company names, prospect names and task subjects so I know when they were created and give each entry a slight bit of uniqueness. To start, a variable needs to be set to the Date. mydate = new Date() – Returns a full string of – Sun Jan 28 11:45:13 EST 2018 Once the date has been calculated from the system, it’s time to parse it into it’s competent pieces. The formatting looks similar to those used in spreadsheets. Here are some examples and the returned results. formattedDate = mydate.format(“MM/dd/yyyy”) – month, day, year 01/28/2018 formattedDate = mydate.format(“dd”) – Day 28 formattedDate = mydate.format(“MM”) – Month 01 formattedDate = mydate.format(“yyyy”) – Year 2018 formattedDate = mydate.format(“EEEE”) – Day as Text Sunday //Shows whether it […]