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:
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!
Solved! Go to Solution.
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" 🙂 ↓↓↓↓↓
@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:
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
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.
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" 🙂 ↓↓↓↓↓
@HimanshuTayal Awesome! Thanks for making the changes!
@sonya_m : M happy that it worked 😅
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
Also, congrats on the new TechCorner Contributor badge🎆!
@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" 🙂 ↓↓↓↓↓
Subject | Author | Latest Post |
---|---|---|