Random numbers are Concatenated–Katalon Studio

How we can deal with text fields for example UserName, SSN, Phone, EmployeeID, Email Address which requires unique values for each user in automation script? 

Steps
1. Record the script 
2. Create the string variable for error message 
3. Compare 
4. Create Random variable int 
5. Concatenate random int with email address which is unique 
6. Save the record

import staticcom.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint

import staticcom.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import staticcom.kms.katalon.core.testdata.TestDataFactory.findTestData

import staticcom.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

import com.kms.katalon.core.checkpoint.CheckpointFactory asCheckpointFactory

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords asMobileBuiltInKeywords

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords asMobile

import com.kms.katalon.core.model.FailureHandling as FailureHandling

import com.kms.katalon.core.testcase.TestCase as TestCase

import com.kms.katalon.core.testcase.TestCaseFactory asTestCaseFactory

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testdata.TestDataFactory asTestDataFactory

import com.kms.katalon.core.testobject.ObjectRepository asObjectRepository

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords asWSBuiltInKeywords

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords asWS

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords asWebUiBuiltInKeywords

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords asWebUI

import internal.GlobalVariable as GlobalVariable

import org.openqa.selenium.Keys as Keys

WebUI.openBrowser(‘https://www.daraz.pk/’)

WebUI.navigateToUrl(‘https://www.daraz.pk/customer/account/create/’)

WebUI.selectOptionByValue(findTestObject(‘Page_Create new customer account/select_SelectMaleFemale’), ‘female’, true)

WebUI.setText(findTestObject(‘Page_Create new customer account/input_RegistrationFormfirst_na’), ‘John’)

WebUI.setText(findTestObject(‘Page_Create new customer account/input_RegistrationFormlast_nam’), ‘Do’)

WebUI.setText(findTestObject(‘Page_Create new customer account/input_RegistrationFormemail’), ‘John@test.com’)

WebUI.setText(findTestObject(‘Page_Create new customer account/input_RegistrationFormpassword’), ‘test12345’)

WebUI.click(findTestObject(‘Page_Create new customer account/button_Submit’))

String MG= WebUI.verifyTextPresent(“Invalid email address”, false)

if (MG.equals(“true”)) {

   int RN;

 RN= (int)(Math.random()*500)

WebUI.setText(findTestObject(‘Page_Create new customer account/input_RegistrationFormemail’), ‘John’+RN+’@test.com’)

WebUI.sendKeys(findTestObject(‘Page_Create new customer account/button_Submit’), Keys.chord(Keys.ENTER))

}

else

WebUI.comment(“User Registration Successful”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: