cancel
Showing results for 
Search instead for 
Did you mean: 

[TechCorner Challenge #14] Filtering data retrieved from a DataSource

SOLVED
Highlighted
Community Manager

[TechCorner Challenge #14] Filtering data retrieved from a DataSource

Hi ReadyAPI Community!

 

We’ve prepared an interesting task for you to solve today! Check out the participation rules and the TechCorner Leaderboard here.

 

Imagine that you are working with an app for setting up online conferences, and you need to filter data based on certain criteria. In our case - the location of an online conference participant.

 

Task: Create a script that will filter data retrieved from a DataSource

Difficulty: Star_Gold.pngStar_gray.pngStar_gray.png

 

Here’s what your script should do:

1. Take an item in a DataSourse and check if it matches the criteria.

2. If it does, run the test. If it doesn't - skip the item.

 

The Excel file to be used as a DataSource is attached below.

 

Condition: Run the test only when participants of an online user conference are located in Boston.

 

Resources: Here are some examples of working with DataSources in Groovy scripts: https://support.smartbear.com/readyapi/docs/testing/scripts/samples/data.html
The full description of the class - here you can find all the properties and methods that the class has:
https://support.smartbear.com/readyapi/apidocs/pro/DefaultPackage/WsdlDataSourceTestStep.html

 

Good luck!


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Filtering data retrieved from a DataSource

Task: Create a script that will filter data retrieved from a DataSource

 

This is a solution created for [TechCorner Challenge #14]

 

@sonya_m :

 

So, i have updated the script in order to meet the criteria, please give it a try:

 

 

def Participant_Location = context.expand( '${DataSource#Participant_Location}' )

if(Participant_Location.toLowerCase() == "boston"){
	testRunner.testCase.getTestStepByName("Register User").run(testRunner, context);
	testRunner.testCase.getTestStepByName("Buy a Ticket").run(testRunner, context);
}
else{
//	Disabling them in order them not to run
	testRunner.testCase.getTestStepByName("Register User").setDisabled(true)
	testRunner.testCase.getTestStepByName("Buy a Ticket").setDisabled(true)
}

 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

Tags (1)
7 REPLIES 7
Highlighted
Community Leader

Re: [TechCorner Challenge #14] Filtering data retrieved from a DataSource

@sonya_m :

 

Hope i have understand correctly i have created below small script as the solution, have a look :

def Participant_Location = context.expand( '${DataSource#Participant_Location}' )

if(Participant_Location.toLowerCase() == "boston"){
	testRunner.testCase.getTestStepByName("TEST__STEP__NAME").run(testRunner, context);
}
else{
//	Do Nothing
}

 

Below is the Screenshot how my Test Suite looks like:

 

HimanshuTayal_0-1599042917579.png

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Community Manager

Re: [TechCorner Challenge #14] Filtering data retrieved from a DataSource

Thank you @HimanshuTayal ! This is a nice script, working great!

 

However, one tiny change could improve it and make a perfect match for the task🙂

In your script, one particular step is run, while we expect that all test steps after the script will be run if the criteria are met!

 

Would you like to try implementing this?

 

Let me provide an image for better understanding.

 

image (5).png

 

 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Community Leader

Filtering data retrieved from a DataSource

Task: Create a script that will filter data retrieved from a DataSource

 

This is a solution created for [TechCorner Challenge #14]

 

@sonya_m :

 

So, i have updated the script in order to meet the criteria, please give it a try:

 

 

def Participant_Location = context.expand( '${DataSource#Participant_Location}' )

if(Participant_Location.toLowerCase() == "boston"){
	testRunner.testCase.getTestStepByName("Register User").run(testRunner, context);
	testRunner.testCase.getTestStepByName("Buy a Ticket").run(testRunner, context);
}
else{
//	Disabling them in order them not to run
	testRunner.testCase.getTestStepByName("Register User").setDisabled(true)
	testRunner.testCase.getTestStepByName("Buy a Ticket").setDisabled(true)
}

 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

Tags (1)
Highlighted
Community Manager

Re: [TechCorner Challenge #14] Filtering data retrieved from a DataSource

@HimanshuTayal Awesome! Thanks for making the changes!


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Community Leader

Re: [TechCorner Challenge #14] Filtering data retrieved from a DataSource

@sonya_m : M happy that it worked 😅

 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Community Manager

Re: [TechCorner Challenge #14] Filtering data retrieved from a DataSource

@HimanshuTayal 😀

Also, congrats on the new TechCorner Contributor badge🎆!


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Community Leader

Re: [TechCorner Challenge #14] Filtering data retrieved from a DataSource

@sonya_m :

 

Thank you and i was waiting for this as i was having 4 points and wanted to solve 1 more question with 1 difficulty or more and happened in this challenge this keeps me motivated and energetic to keep solving and login into community on daily basis.

 

Specially Monday/Tuesday when you post new challenge, which challenges the brain in order to solve the problem 🙂


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors