Is it possible to use a variable or test data within a Test Object?
For instance, I want to create an event in our events management system that pulls the title “Event 1” from test data (or a variable). Then, in second test case, I want to find the Event to edit it by locating and clicking the link element on that page whose label matches that same variable/test data.
@Dean Hicks said:
Is it possible to use a variable or test data within a Test Object?
For instance, I want to create an event in our events management system that pulls the title “Event 1” from test data (or a variable). Then, in second test case, I want to find the Event to edit it by locating and clicking the link element on that page whose label matches that same variable/test data.
Thanks in advance!
You can use object property wherein your “title” contains value “Event 1”
It is a good question, as we also would be interested in knowing how to solve it. In our case we have unique transactions that need to be verified, to be more precise their content is to be verified.
Create a new transaction
Store the transaction ‘Date/Time’ as a variable
Open the list of transactions
Find the last transaction by using the unique ‘Date/Time’ variable stored earlier
Open the exact transaction
Verify the content
This case is quite complicated, and you can use groovy scripts to make this happen.
Assign variable’s value to the test object , which is link element in your example. This test object should have one unique property such as “text()” to demonstrate event’s label
After an event is created, change “text()” property’s value to be new value and use it in your test step.
Example:
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase import static com.kms.katalon.core.testdata.TestDataFactory.findTestData import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords 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 as TestCaseFactory import com.kms.katalon.core.testdata.TestData as TestData import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository import com.kms.katalon.core.testobject.TestObject as TestObject import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords import internal.GlobalVariable as GlobalVariable import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
// Create test object’s variable
lnk_EditEvent = findTestObject(‘Page_EventManagement/btn_SearchEvent’)
// Change test object’s property and set its active to use this property for finding object
lnk_EditEvent.findProperty(‘text()’).setValue(createdEventName)
lnk_EditEvent.findProperty(‘text()’).setActive(true)
// Click on the changed link element
WebUI.click(lnk_EditEvent)
@Dean Hicks said:
Is it possible to use a variable or test data within a Test Object?
For instance, I want to create an event in our events management system that pulls the title “Event 1” from test data (or a variable). Then, in second test case, I want to find the Event to edit it by locating and clicking the link element on that page whose label matches that same variable/test data.
Thanks in advance!
I am still new to Katalon, but from what I have seen this would not be possible, once a test is completed and a second test is run it would have to have fresh values or pre-stored variables. I do not know of a way to edit test data from running a test…
With that being said if you mean in a single test case to grab it and then use it for a dynamic value. yes you could do that.
I would do something like this:
eventOne = WebUI.getText(findTestObject(‘objectEvent’))
obviously you would want to modify the property modification based upon what you need. What this will do is create a new variable, based upon an object you predefined and add in the data pulled from event.
notice I have a " with a follow ’ this is closing off the first part and adding in the value from eventOne then follows with "] to close it off.
Hi,
Can any one please provide me the piece of code for the below scenario.
- There are multiple Roles available e.g. Admin, Manger, Engineer etc, I want to identify this roles as soon as user gets logged in and based on Rights module appears for the respective logged in user. Now I want to check all the modules available and clickable after logged in with any user based on the role.
e.g. Admin User ( can access Sys Admin and Sys admin contains module A,B and C) and Rest of the Modules like Setup, Configuration etc.
Engineer User (Can’t see the Sys Admin Module, hence will not be able to click or open this) and Rest of the modules like Setup, Configuration etc. available
Manager User (Can’t access the Sys Admin and Setup Module, hence will not be able to click or open this) and Rest of the modules like Report, Configuration etc available.
Can any one please help me with the piece of code for the same. I am struggling with this have tried many things but still not got the proper solution. JFI I have created the Keyword for this and making user login and then trying to fetch and save the Role in variable so that I can use it for the module role access…
Thank you so much. This is working… Great!!!
Can we able to pass the test data in xpath like
changecountry = WebUI.modifyObjectProperty(findTestObject(‘GetCountryies/country_name’), ‘xpath’, ‘equals’, '//*[@data-city=‘findTestData(‘countriesListing’).getValue(1, 2)’,true)
I think it should be something like:
changecountry = WebUI.modifyObjectProperty(findTestObject(‘GetCountryies/country_name’), ‘xpath’, ‘equals’, ‘//*[@city=’+findTestData(‘countriesListing’).getValue(1, 2)+’,true)
we are almost there.
changecountry = WebUI.modifyObjectProperty(findTestObject(‘GetCountryies/country_name’), ‘xpath’, ‘equals’, ‘//*[@data-city=’+findTestData(‘countriesListing’).getValue(1, 4)+’]’,true)
Xpath shows
Finding web element with id: ‘Object Repository/GetCountryies/country_name’ located by ‘By.xpath: //*[@data-city=Hong Kong]’ in ‘30’ second(s)
Sorry this doesn’t seems to work
changecountry = WebUI.modifyObjectProperty(findTestObject(‘GetCountryies/country_name’), ‘xpath’, ‘equals’, ‘//*[@data-city=’"+findTestData(‘countriesListing’).getValue(1, 2)+"’],true)