How to run test after applying filter in Xl column

For example: Dynamic Dropdown

image

I want to test dynamic dropdown, after selecting first, it leads to next dropdown which have two values.

image

rather than running tests for 4 times, i want to run only for two times. one for beverages where after selecting beverages it validates all options in second dropdown. then it goes to snacks and it validates all options in second dropdown

how it can be done?

Possibly you had better not to externalize data in external files.

It would be far easier if you write test statements with data hard-coded in your Test Case script.

its just an example, i have data of 400 plus rows and i dont want to run 400 TCs.

If you want to write data in a grid-layout, you need to create 1 data line for 1 time of test execution. So you want

Beverages Coffee Coke
Snacks Chips Cookis Cheeze Pretz

Or, if you stick to the data format , then you need to write some script to convert it into “1 data line per 1 test exection” before you pass the data to your test script. I guess, this conversion script is complicated, difficult to develop, could be buggy.

… “hard-coding” data in Groovy language would be far easier; for example

Map<String, List<String>> data = new Map<>()
data.put("Beverages", ["Coffee", "Coke"])
data.put("Snacks", ["Chips", "Cookis", "Cheeze", "Prets"])
// then use the data for testing HTML elements

Thanks for your time!

Transpose data not possible and Hard-coding would not be ideal in this situation. I am sure there might be people around us who might have dealt with scenarios using dynamic dropdowns.

I have data where 1st dropdown have 5 options, 2nd around 100 and third 400 plus…its nested.

I suppose you are going to create an state-of-the-art Excel file using dynamic dropdowns. OK. You would be able to create such xlsx file.

However, Katalon Studio does NOT understand dynamic dropdowns in Excel worksheets. Katalon Studio would not be able to consume your xlsx file with dynamic dropdowns. Katalon Studio can only understand a plain-old grid format like Comma-Separated-Values.

In the original post, you wrote

I want to test dynamic dropdown, after selecting first, it leas to next dropdown which have two values".

Have you finished writing a test case that does “check if the fist pulldown presents “Beverage or Snack”; when selected one of them, it leads to the second pulldown (Coke, Coffee, Chips, Cookies); so test script asserts that appropriate options are displayed for the 2nd pulldown”?

I think that this requirement is very complexed. I suppose it deserve sophisticated programming skill. I suppose it would require an internal data structure that represents the problem well. How will you design the data structure? If you have written a code, please show it to us. I believe that Excel would not help you much.

Its about dynamic dropdowns in WebUI NOT in excel. XL is having columns as like UI_Dropdown_Option 1, UI_Dropdown_Option 2, UI_Dropdown_Option 3 and UI_Dropdown_Option 4.

Validation required for UI_Dropdown_Option 4.
image

as far as i understand, the question is about data driven testing.
you may have to split your excel file in two different inputs and play a bit with the relationships, anyway your current scripts have to be rethinked.
see this for guidance: Combine Multiple Data Sources | Katalon Docs

I wrote a sample Test Case that touch the “Dynamic Dropdown” page, and look at the HTML elements as “pulldowns” in it.

import org.openqa.selenium.WebElement

import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI


class MyDataStructure {
	String type
	Map<String, List<String>> literals
	MyDataStructure(String type, literals) {
		this.type = type
		this.literals = literals
	}
	String getIdOne() {
		return type + "-one"
	}
	String getIdTwo() {
		return type + "-two"
	}
	Set<String> keySet() {
		return literals.keySet()
	}
	List<String> get(String key) {
		return literals.get(key)
	}
}

def textFixture = new MyDataStructure("text", ["Beverages":["Coffee","Coke"], "Snacks": ["Chips", "Cookies"]])
def jsonFixture = new MyDataStructure("json", ["Beverages":["Coffee","Coke"], "Snacks": ["Chips", "Cookies"]])
def dbFixture   = new MyDataStructure("db",   ["Beverages":["Coffee","Coke"], "Snacks": ["Chips", "Cookies"]])
	
String url = "https://css-tricks.com/examples/DynamicDropdown/"
WebUI.openBrowser("")
WebUI.navigateToUrl(url)

boolean result

result = verifyDynamicPulldown(textFixture)
result = verifyDynamicPulldown(jsonFixture)
result = verifyDynamicPulldown(dbFixture)

WebUI.closeBrowser()

Boolean verifyDynamicPulldown(MyDataStructure mds, FailureHandling flowControl = , FailureHandling.CONTINUE_ON_FAILURE) {
	// verify the first pulldown
	WebUI.verifyElementPresent(makeTestObject("//select[@id='${mds.getIdOne()}']"), 10, flowControl)
	Set<String> keysOne = mds.keySet()
	List<WebElement> optsOne =
		WebUI.findWebElements(makeTestObject("//select[@id='${mds.getIdOne()}']/option[not(@selected)]"), 10)
	optsOne.each { option ->
		assert option.getText() in keysOne
	}
	// iterate over the options of the 1st pulldown and do the following for each,
	// - choose one option of the 1st pulldown, 
        // - verify the first pulldown if the value is found in the MyDataStructure instance
        // - click the 1st pulldown, wait for response
        // - verify the second pulldown if the value is found in the MyDataStructure instance
    return true
}

TestObject makeTestObject(String xpath) {
	TestObject tObj = new TestObject(xpath)
	tObj.addProperty("xpath", ConditionType.EQUALS, xpath)
	return tObj
}

This sample is incomplete still. It checks the 1st pulldown, but does not check the 2nd pulldown — to be implemented.

I tried to make my code as concise as possible. The core portion is the following lines:

...
def textFixture = new MyDataStructure("text", ["Beverages":["Coffee","Coke"], "Snacks": ["Chips", "Cookies"]])
...
result = verifyDynamicPulldown(textFixture)
...

Is this code too much complicated?

---- Yes, it is complexed. But the Dynamic Dropdown page deserves this level of complexity. I needed Groovy language constructs for modularization: class, function, Map<String, List<String>> to make the code as concise as possible. I could not find a way to solve this problem in Katalon’s “Manual mode” where I can only use a linear sequence of calls to Keywords.

The literal: ["Beverages":["Coffee","Coke"], "Snacks": ["Chips", "Cookies"]] is important for my sample code. It is an object literal in Groovy, similar to JSON.

If you want to externalize the data, then you would want to create a JSON file, and your test reads the JSON file for itself. Katalon’s “Data Driven testing” approach does not help dealing with JSON files.

Hi

any luck with 2nd dropdown? even with my code i can run only 1st

I supported verifying all 3 sets of two pulldowns in the Dynamic Dropdown page.

import org.openqa.selenium.WebElement

import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.util.KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

class Expected {
	String type
	Map<String, List<String>> literals
	Expected(String type, literals) {
		this.type = type
		this.literals = literals
	}
	String getIdOne() {
		return type + "-one"
	}
	String getIdTwo() {
		return type + "-two"
	}
	Set<String> keySet() {
		return literals.keySet()
	}
	List<String> get(String key) {
		return literals.get(key)
	}
}

def expected4text = new Expected("text", ["Beverages":["Coffee","Coke"], "Snacks": ["Chips", "Cookies"]])
def expected4json = new Expected("json", ["Beverages":["Coffee","Coke"], "Snacks": ["Chips", "Cookies"]])
def expected4db = new Expected("db",   ["Beverages":["Coffee","Coke"], "Snacks": ["Chips", "Cookies"]])
	
String url = "https://css-tricks.com/examples/DynamicDropdown/"
WebUI.openBrowser("")
WebUI.setViewPortSize(800, 600)
WebUI.navigateToUrl(url)

try {
	verifyDynamicPulldowns(expected4text, FailureHandling.CONTINUE_ON_FAILURE)
	verifyDynamicPulldowns(expected4json, FailureHandling.CONTINUE_ON_FAILURE)
	verifyDynamicPulldowns(expected4db, FailureHandling.CONTINUE_ON_FAILURE)
} finally {
	WebUI.delay(3)
	WebUI.closeBrowser()
}

void verifyDynamicPulldowns(Expected expected, FailureHandling flowControl) {
	WebUI.verifyElementPresent(makeTestObject("//select[@id='${expected.getIdOne()}']"), 10, flowControl)
	List<WebElement> actualOptsOne = 
		WebUI.findWebElements(makeTestObject("//select[@id='${expected.getIdOne()}']/option[not(@selected)]"), 10)
	// verify the first pulldown against what is expected	
	actualOptsOne.eachWithIndex { option1, index1 ->
		String key = option1.getText()
		if (key in expected.keySet()) {
			// choose an <option> of the first pull down by label
			WebUI.selectOptionByLabel(makeTestObject("//select[@id='${expected.getIdOne()}']"), key, false)
			// find the values displayed in the 2nd pulldown
			List<WebElement> actualOptsTwo = 
				WebUI.findWebElements(makeTestObject("//select[@id='${expected.getIdTwo()}']/option"), 10)
			// verify the values displayed in the 2nd pulldown against what is expected
			actualOptsTwo.eachWithIndex { option2, index2 ->
				if (option2.getText() in expected.get(key)) {
					;
				} else {
					KeywordUtil.markFailedAndStop("<select id='${expected.getIdTwo()}'> has a <option>${option2.getText()}<option>, which is unexpected")
				}
			}
		} else {
			KeywordUtil.markFailedAndStop("<select id='${expected.getIdOne()}'> has a <option>${key}</option>, which is unexpected")
		}
	}
}

TestObject makeTestObject(String xpath) {
	TestObject tObj = new TestObject(xpath)
	tObj.addProperty("xpath", ConditionType.EQUALS, xpath)
	return tObj
}


See the video.

Please note in the video the test case “TC1” failed.

It failed because that the target web site Dynamic Dropdown has a problem. The 3rd “Pulls from MySQL database” is mal-functioning.

My test case “TC1” happened to point out that problem. I would see it is a success.