Javascript to Automate PIN login code

I’m a bit of a novice at this so please bear with me :).
I have written scripts in KR that auto populate application forms for use by trainees as practice scenarios in assessment. However, one stumbling block I’ve hit is the Login process before the application form can be started. A user account has to be created with a Username, Password and 6 digit PIN. At Login, three random digits from this PIN are requested. I haven’t been able to figure out how to write an extension script that can use If commands to automatically select the required PIN digits.

The fields on the login screen are named pinbox1, pinbox2 and pinbox3 with the label on each pinboxlabel1…2…3, with the label values being 1st, 2nd, 3rd, 4th, 5th, 6th. PIN code used is usually generic like 010101 as there are security validation around using the same number, or sequential numbers.

Can anyone help me with the javascript and how to add this to my KR scripts please?

Hi there,

Could you provide us with a sample of your test script so we could try testing it and see what’s going on?

Have you given up on this :question:

I’d take the lack of response in that time to be either given up, solved it themselves, or moved on to something else.

1 Like

Hi Guys, I’m really sorry, I never saw the responses to my thread. Unfortunately I never got this to work, so had to do a lot of manual work instead. My javascript script looks something like this(sample of Pin1 field). Does the Javascript make sense and how can it be incorporated into the KR script? Thanks

function Pin1() {
if(Pin1Label == ‘1st’){
Pin1 = 2;
else if(Pin1Label == ‘2nd’){
Pin1 = 0;
else if(Pin1Label == ‘3rd’){
Pin1 = 2;
else if(Pin1Label == ‘4th’){
Pin1 = 2;
else if(Pin1Label == ‘5th’){
Pin1 = 2;
Pin1 = 4;

Nothing about this makes any sense.

First off, you’re using Katalon Studio, which uses Groovy, not JavaScript…but you’re tryna use JavaScript.

Second, you have written Katalon Recorder script, but now wish to write some code to automate some stuff… This should be telltale sign to refactor your test cases into code in Katalon Studio.

Third, your JavaScript code has this function called Pin1, in which sets a variable called Pin1. That won’t work.

Lmk if you need someone to write this code for you. I’d be happy to, for some money!

I’m using Katalon Recorder, not Studio, which as far as I’m aware can use javascript. The reason I’m trying to use external code is because the commands within katalon recorder were not giving me the desired results to automate the Pin login process. As I mention in my first post, I’m new to this, so that’s why I was looking for help. Beginning your reply with “Nothing about this makes any sense” is insulting and condescending. I’m not in a position to learn how to use Katalon Studio, which is far more complicated than Recorder. In my javascript, I’m not trying to create a variable, it was meant as an indication that I wish to type a certain number into the Pin1 box depending if it asks for the 1st, 2nd, 3rd digit.

My understanding is that this website is a community for helping people, not for selling your coding skills.

Wow. Just wow.

What is with people these days, that can’t even handle criticism, let alone be bothered to read the f****** manual?!

You sure no app under test, show no HTML code to scrape, show no script.

You disappear for more than a year .

You come back, but post some absolute nonsense JavaScript. Somehow you don’t get that, if you have to write code to fill the gap caused by a no-code solution (Katalon Recorder), you should probably switch to something that’s more code…

Then when told that you should switch to Katalon Studio, and given a documentation on how to do so, you don’t even read it. Instead you focus on big bad Mike Warren and him being mean.

You even hide behind being new…

To add insult to injury, you’re on here asking for JavaScript code, but when I offer it as a service (we’re not ChatGPT lol), you take offense.

Honestly, I think you’re beyond help on this. Best of luck to you.

Tagging @Elly_Tran and for your advice to this question.

Hi folks, :wave:

I would like to remind you that while we encourage you to discuss and learn from each other, hostility of any kind is strongly discouraged and will be removed if repeated.

We know that text-based asynchronous communication in an online forum setting can sometimes be hard due to the lack of nonverbal cues that help to convey emotion, or that what is said could be misinterpreted in the wrong way, hence, we ask that you follow our Community Guideline to help us build a safe space for healthy discussions together.

If you are new to our community, please remember to read through our Getting Started Guide as well as this topic to know how to format your question(s) to receive the best support from other members and our team. You could even tag our @team into your topic if your question(s) has gone unanswered.

Thanks :+1:


I understand people being frustrated from failing to even search for existing subjects, not reading shared documents when shared, etc… But yeah, I don’t understand mwarren04011990’s hostility in this case, especially when christopher.odwyer82’s responses seemed reasonable to me.

@christopher.odwyer82 There’s no need for you to use JavaScript to execute what you’ve shared here, you can actually use if / else / elseif / endif directly within Katalon Recorder, likewise with setting variables.

So, Katalon Recorder can both handle conditional operations, and setting values (via the store / storeEval commands, but should be initiated before being called via ‘store’).

If you need to repeatedly call this check, if you can incorporate it into a while / endwhile loop, then it should ‘cycle’ through all iterations, if there are multiple.

If it requires a list data source, that’s where JavaScript can come in handy (e.g. initiate var with a list, call value via index number, uses a Katalon Recorder variable (e.g. ${Count}) to parse the current instance number), but so can just using CSV files (there’s guides for how to do this too).

This way you’re also minimising your need to capture and parse values back into Katalon Recorder from a JavaScript source too, where possible.


Thanks Guy for the advice. I had tried using the built in If/Elseif statements before but never succeeded with making it work, so that’s why I switched to try using Javascript instead. But after your advice, I decided to give it another go and finally managed to make it work. I think where I was going wrong before was I was using ${X} in the If statements, and this was always throwing an ‘unexpected token’ error. The solution was so simple in the end, I’m kicking myself how I didn’t get it before. My script looks like this now:

open |
storeText | id=PinLabel1 | x
storeText | id=PinLabel2 | y
storeText | id=PinLabel3 | z
setText | id=username | ${username}
setText | id=password | ${password}
If | x == ‘1st’ |
setText | id=Pin1box | 0
ElseIf | x == ‘2nd’ |
setText | id=Pin1box | 0
ElseIf | x == ‘3rd’ |
setText | id=Pin1box | 0
ElseIf | x == ‘4th’ |
setText | id=Pin1box | 1
ElseIf | x == ‘5th’ |
setText | id=Pin1box | 1
ElseIf | x == ‘6th’ |
setText | id=Pin1box | 1

and so on for the other two Pin fields.

Thanks for all your help with this guys, I really appreciate it.