Adding date and time when registering a new user

Hi All,
I hope you can help me, i am very new to Katalon and not so good with Javascript. The challenge i am facing is that, when a user is registering on a website, the username should include the date and time so that i can have different usernames when running the Register test case multiple times. I am currently manually changing the username on the script, which defeat the purpose of automation. How can i achieve this?

Thanks,

Hello, use timestamp for this purpose.

long ts = System.currentTimeMillis() / 1000LString username = 'MyUsername_' + ts

1 Like

Hi Marek,
Thank you for you response. where do i put in the code? this is currently how my script looks like? where would i insert the code above?

WebUI.openBrowser(’’)

WebUI.maximizeWindow()

WebUI.navigateToUrl(‘http://uat.katalon.co.za/Account/SignIn’)

WebUI.click(findTestObject(‘Light Registration/Page_Welcome to katalon/a_Register’))

WebUI.setText(findTestObject(‘Light Registration/Page_Registration/input_Username’), ‘MaryMofokeng009’)

Thank you

Your code should look like this:

WebUI.openBrowser('')WebUI.maximizeWindow()WebUI.navigateToUrl('http://uat.katalon.co.za/Account/SignIn')WebUI.click(findTestObject('Light Registration/Page_Welcome to katalon/a_Register'))long ts = System.currentTimeMillis() / 1000LString username = 'MaryMofokeng_' + tsWebUI.setText(findTestObject('Light Registration/Page_Registration/input_Username'), username)

1 Like

Thank you so much Marek. It is working.

Good afternoon:

I have a similar issue to the one above. In my test case, I need to register a new user, must be email. However, I don’t want to register the same user each time because the system will indicate user is already registered. Here is the script:

Mobile.startApplication(‘C:\\Users\\dcherry\\Desktop\\CodeTwo-debug.apk’, true)

MobileBuiltInKeywords.tap(findTestObject(‘OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/btn_Reg’), 0)

MobileBuiltInKeywords.tap(findTestObject(‘OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regemail’), 0)

MobileBuiltInKeywords.setText(findTestObject(‘OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regemail’), ‘katalon1@testdnc.com’,

0)

MobileBuiltInKeywords.tap(findTestObject(‘OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regPassword’), 0)

MobileBuiltInKeywords.setText(findTestObject(‘OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regPassword’), ‘password1@’,

0)

MobileBuiltInKeywords.tap(findTestObject(‘OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regConfirm Password’),

0)

MobileBuiltInKeywords.setText(findTestObject(‘OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regConfirm Password’),

'password1@', 0)

MobileBuiltInKeywords.tap(findTestObject(‘OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/REGISTER’), 0)

MobileBuiltInKeywords.closeApplication()

Hi Darlene,

you can use the very same approach as I mentioned above. See following script:

Mobile.startApplication('C:\\Users\\dcherry\\Desktop\\CodeTwo-debug.apk', true)MobileBuiltInKeywords.tap(findTestObject('OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/btn_Reg'), 0)MobileBuiltInKeywords.tap(findTestObject('OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regemail'), 0)long ts = System.currentTimeMillis() / 1000LString email = 'randomEmail_' + ts + '@yourdomain.com'MobileBuiltInKeywords.setText(findTestObject('OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regemail'), email,     0)MobileBuiltInKeywords.tap(findTestObject('OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regPassword'), 0)MobileBuiltInKeywords.setText(findTestObject('OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regPassword'), 'password1@',     0)MobileBuiltInKeywords.tap(findTestObject('OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regConfirm Password'),     0)MobileBuiltInKeywords.setText(findTestObject('OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/regConfirm Password'),     'password1@', 0)MobileBuiltInKeywords.tap(findTestObject('OnSolve/CodeRED Mobile/Android/CRMA/Sign In Page/Register/REGISTER'), 0)MobileBuiltInKeywords.closeApplication()

2 Likes

Thank you so much Marek…this is a lifesaver!!

Hello Marek,

Thank you for providing support to the other Katalon users! I’ve been trying to implement your method into my solution but have had no luck.

I need to insert something such as time to a user creation entry to differentiate over other previously created users.
Current line for input:
WebUI.setText(findTestObject(‘Page_XXXXX Admin/input_Role Name_name’), ‘qaautomation’)

Attempting to use your solution:

long ts = System.currentTimeMillis() / 1000LString username = 'qaautomation_' + tsWebUI.setText(findTestObject('Page_XXXXX Admin/input_Role Name_name'), username)When using this katalon throws error on the line starting with long ts as an unrecognized exception.Do I need to add some sort of import? Thanks again for trying to give a solution to those who are more novice to Katalon. 

Hi Dakota,

can you share the exception you get? I don’t see any issue in this code, no import is required for long type, it is default import in Java.

Thanks for the quick response Marek,

Below is the exception from the log

Test Cases/EA Create FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Unable to set text (Root cause: java.lang.IllegalArgumentException: Object is null)

at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:65)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:27)

at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword.setText(SetTextKeyword.groovy:65)

at com.kms.katalon.core.webui.keyword.builtin.SetTextKeyword.execute(SetTextKeyword.groovy:37)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.setText(WebUiBuiltInKeywords.groovy:950)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$setText$1.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)

at Script1537301255105.run(Script1537301255105.groovy:34)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)

at TempTestCase1537302436379.run(TempTestCase1537302436379.groovy:22)

at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)

at groovy.lang.GroovyShell.run(GroovyShell.java:518)

at groovy.lang.GroovyShell.run(GroovyShell.java:507)

at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)

at groovy.ui.GroovyMain.run(GroovyMain.java:384)

at groovy.ui.GroovyMain.process(GroovyMain.java:370)

at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)

at groovy.ui.GroovyMain.main(GroovyMain.java:109)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)

at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)

)

It looks like a problem with your test object. Is the path correct? Which selector type do you use?

I created a brand new script and for what ever reason the logic provided is now working. Thank you Marek for your support. If I do figure how the problem was fixed on my end, I will share on this post.