Need help on how to automate a given business scenario

Hi Experts,
I know this’ more of an automation question, rather than a Katalon specific question
Need an advice reg. how to automate this scenario
I have a weird business reqmt. that goes something like this →

  1. Create an Employee in the system by entering Firstname, Lastname, DOB, DOJ, Benefit plans, etc.
  2. Click on Submit
  3. Employee is created successfully
  4. Now the thing is, for e.g., if I had entered first name = Anand, and Last name = Kumar during employee creation, then system will not allow me to create another new employee with the same first and last name
  5. However, it allows me to create another new employee with first name = ANAND1, and last name = KUMAR1, etc., like that, but not with ANAND & KUMAR
    And again, if an employee is created with first & last name = ANAND1 and KUMAR1, then again it will not allow me to create with ANAND1 and KUMAR1 as the first & Last names respectively

How to overcome this situation?
I know every time I have to update the datasheet [which means that a manual intervention is required], or else, I need to request the DevOps engineer to void the employee creation from the back-end

Is there any other way to overcome this?

Kindly let me know
Many Thanks

4 Likes

May I ask @kazurayam, @dineshh and @grylion54 for your expertise here :grinning_face:

1 Like

Yes, it is.

Read the following classic essay by Kent Beck written 30 years ago.

Test Infected: Programmers Love Writing Tests

Just read it through. You do not have to type and run the sample codes in Java; although I would love to.

Let me quote a phrase from this essay:

Now that we have implemented two test cases we notice some code duplication for setting-up the tests. It would be nice to reuse some of this test set-up code. In other words, we would like to have a common fixture for running the tests. With JUnit you can do so by storing the fixture’s objects in instance variables of your TestCase class and initialize them by overridding the setUp method. The symmetric operation to setUp is tearDown which you can override to clean up the test fixture at the end of a test. Each test runs in its own fixture and JUnit calls setUp and tearDown for each test so that there can be no side effects among test runs.

Here you should learn several terms commonly used in the software testing: “fixture”, “set-up” and “tearDown”. — This essay was the origin of these terms, you know?

You need to implement “set-up” and “tearDown” to manage the “fixture” so that your tests can run repeatedly successful. You want to initialize the target system as “set-Up”; or you want to clean-up the target system as “tearDown”. You need to implement these yourself. No AI would help you.

How to?

Katalon Studio provides the following framework. I believe, Katalon learned JUnit when they designed the product originally.

Test Fixture and Test Listners

You can utilize “Test Listener” to implement the processing for “set-up” and “tearDown” to manage the test “fixtures” effectively.

3 Likes

I don’t know your target system. It’s only you who knows it. So overcome it yourself.

3 Likes

There are multiple ways , one is below , you can create a local variable or global variable.

let say you create a global variable as firstname , lastname

then in your test case , you can use the below

================================================

String charSet = ‘abcdefghijklmno’
int length = 5

GlobalVariable.firstname= (‘firstname’ + RandomStringUtils.random(length, charSet.toCharArray()))

GlobalVariable.lastname= (‘lastname’ + RandomStringUtils.random(length, charSet.toCharArray()))

============================================================

then in ur test case , you can do something like below

WebUI.setText(findTestObject(‘somepath/somepath1/somepath2’), GlobalVariable.firstname)

WebUI.setText(findTestObject(‘somepath/somepath1/somepath2’), GlobalVariable.lastname)

this is one of the many ways , everytime you will get a different fisrtname and last name

is this what you needed @anandkumar.venkatara

3 Likes

You can create an Employee programatically. Then, can you remove the newly added Employee programatically as well?

In the set-up or tearDown, your test should check if the Employee is there in the system. And if there it is, your test should remove it. By doing such cleanup, your test will be able to repeat creating the Employee next time.

If your target system does not allow you to remove the added Employee, then you should talk to the developer and ask them to change the target system so that it lets you remove the Employee programatically in order to bring the target system back to the initial state.

4 Likes

programatically you can handle your use case . if you need to use same name again, create a clean up script which deletes the records created earlier.

3 Likes

It doesn’t sound like an automation question, it sounds like a testing question. Before you automate something you need to understand the logic or the requirements and it sounds like initial testing hasn’t taken place. If you want to automate a test then it would help to have access to the database, otherwise you will struggle to understand the state of the system eg is this my first John Smith in the system or actually the fifth. In reality, could this simply be a unit test rather than a UI-based test script? Your dev will hopefully have already covered this and you may be duplicating effort

3 Likes

Thnx everyone for your valueable suggestions

For now, Im use the solution provided by Monty_Bagati, going to use random variables and see

Best Regards

3 Likes

@anandkumar.venkatara : There are many use cases where in we can create duplicate entities like the one you have explained. In such cases, you can either use the approach @Monty_Bagati has explained (if the fields accept only alphabetic characters) or append the current date time stamp with milliseconds to the fields while creating the entities which cannot be duplicated.

This kind of constraint pops up a lot, and it’s definitely annoying when tests depend on “unique forever” data. Most teams I’ve seen get around it by auto-generating names with timestamps or random suffixes at runtime so the script stays hands-off.

2 Likes