I am running a test suite with TC1, TC2, and TC3. All three require an OTP code. The OTP code for each test case, i stored in a GlobalVariable.
The flow is as follows: I run the test suite, and when TC1 sends the OTP code to the email, I copy the code and paste it into the GlobalVariable, and it works successfully even while the test suite is running. However, for TC2 and TC3, I do the same, but it fails—when entering the OTP, Katalon does not use the latest code.
Is there a solution for this?
How do you obtain a new OTP value?
Does TC1 request some external system to give you a new OTP?
TC1 should be able to wait and receive the newly obtained OTP and write the value into a GlobalVariable, shouldn’t it?
You haven’t explained the reason why you involve “email” in this processing. People do not understand it without your description.
currently i work with mobile environment, so its basically a test for forgot password features, so it needs the OTP before continue to the next step. the OTP itself is sent to user’s email.
TC1 should be able to write the neyly obtained OTP value into the GlobalVariable, shouldn’t it?
- yes, but i need to know how to get the otp dynamically so i dont have to copy paste while the test running (its work if the TC is run 1 by 1, but it didn’t for Test Suite)
You want your test case to access email to retrieve information. This is a frequently asked question.
Please make search this forum with keyword “Handling Gmail” or “how to get email content” etc.
Unfortunately it is a difficult question to solve (many blocking factors there), but you should be able to eventually. Just try.
Does anyone have practical experience of implementing this case? Could someone show a working sample code? I must confess, no, I don’t.
To add to the comment above - if you have three test cases that each try to get a OTP, you could instead get the code from TC1 and write to a global variable that could then be used in TC2 and TC3 (assuming you run the test suite sequentially, not in parallel).
I’m not up to date with the latest GMail integration but a forum search will definitely show results.
Remember that GMail supports ‘plus addressing’ - which means you can send a OTP to a dynamic email address that uses the same inbox. Ie mrtest+1@gmail.com, mrtest+2@gmail.com etc… will all go to mrtest@gmail.com inbox.
let say, i am able to get the otp from the email, do you know how to update the globalvariable?
def otpCode = Mobile.getText(findTestObject(‘Mahasiswa Lupa Password/YopMail/otp_code’), 0)
println(otpCode)
// Update global variable otpLupaPassword
GlobalVariable.otpLupaPassword = otpCode
// Print to verify if it’s correctly updated
println('OTP Lupa Password updated: ’ + GlobalVariable.otpLupaPassword)
Mobile.closeApplication()
i already tried this, but in the tc2 the “GlobalVariable.otpLupaPassword” is not updated
@keenanhashim
Did you check the execution log? The following lines must have printed something. What did you see?
println(otpCode)
...
println('OTP Lupa Password updated: ’ + GlobalVariable.otpLupaPassword)
Do you have the entry otpLupaPassword
defined in a Execution Profile, e.g, “default” ?
Do you have a statement in your script ? :
import internal.GlobalVariable
You have
Mobile.getText(findTestObject(‘Mahasiswa Lupa Password/YopMail/otp_code’), 0)
Here you specfied 0 as the second argument, which is “timeout” in seconds. I doubt if 0 is appropriate. Why not you give 10 instead of 0?
Do you have a Test Suite which binds the tc1 and tc2 together?
I guess that you do not have a Test Suite. Rather you do as follows:
- You executed the tc1 — it finished fine.
- And after that, you executed the tc2.
- You found the GlobalVariable appeared blank in the tc2.
- So you raised this topic.
Am I right?
Please be informed: a GlobalVariable exists only on runtime memory in a Test Case scope or a Test Suite scope. Any changes into a GlobalVariable will NOT be persisted into disk at all.
If you have a Test Suite that binds tc1 and tc2, then the tc2 would be able to see the GlobalVariable updated by the preceding tc1 via the runtime memory allocated for a Test Suite.
If you execute the tc1 and tc2 isolated without binding them in a Test Suite, a GlobalVariable is visible only in the scope of each individual Test Cases. Tc2 can NOT see the GlobalVariable in the tc1, as tc1 has already finished and disappeared.
- Did you check the execution log? The following lines must have printed something. What did you see?
its copying the otp that i got from tc1,
- Do you have the entry
otpLupaPassword
defined in a Execution Profile, e.g, “default” ?
yes, i defined it but the value is empty string
<GlobalVariableEntity>
<description></description>
<initValue>''</initValue>
<name>otpLupaPassword</name>
</GlobalVariableEntity>
- Do you have a statement in your script ?
i already imported the global variable
- Here you specfied 0 as the second argument, which is “timeout” in seconds. I doubt if 0 is appropriate. Why not you give 10 instead of 0?
lemme try first
- Do you have a Test Suite which binds the tc1 and tc2 together?
nope, lemme try it first and gets an update for you
- Am I right?
yapp
@keenanhashim,
I noticed that you do not know the Markdown syntax of Discourse, the engine of this forum. You didn’t write any markdown so that your original post looked hard to understand.
Therefore, please forgive me, I edited your post above so that it becomes more readable.
-
I differentiated my questions and your replies
-
I employed the “code formatting syntax” to make program sources and logs readable.
yap, im sorry for the inconvenience for my post
the problem was solved, i should put the 2 TC in a test suite