Hello everyone, hope that this topic get helpful responses because I am frustrated by this
Let me demonstrate the flow of the test:
Create a document and name them with this format: (“Testing Note” + random number)
So I’m using this method: //Generate random numbers
int randomNumber = new Random().nextInt(10000) + 1
WebUI.setText(findTestObject(‘Document/Doc Name - textbox’), randomText)
//Save into GlobalVariable
GlobalVariable.GeneratedText = randomText
Result: It did create a document that followed the format that I expected.
2. Move to the “Search Document” screen and find the document just created
The tricky part is this screen has no searchbox, it contains a table that include all created documents.
Question: I need to find the latest document that I created because during experiment, I’ve created way too many documents with the format: (“Testing Note” + random numbers)
Is there anyway I can do it ?
FYI: I dont know how to code, the script above is from ChatGPT and I just fix it to suitable for execution on the app if you can provide me a script, please describe it specifically so I can know what does it do, thanks
You have a Global Variable created. Once you have created the new record you could look for the text appearing on screen (where the text to search for is your global variable):
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
TestObject makeTestObject(String id, String xpath) {
TestObject tObj = new TestObject(id)
tObj.addProperty("xpath", ConditionType.EQUALS, xpath)
return tObj
}
String topic = "How to find created document in a web page that has no search box"
WebUI.openBrowser('https://forum.katalon.com/')
TestObject anchorOfTheTopic = makeTestObject("trOfTheTopic",
"//a[contains(text() , '${topic}')]")
WebUI.verifyElementPresent(anchorOfTheTopic, 10)
String dataTopicId = WebUI.getAttribute(anchorOfTheTopic, 'data-topic-id')
println "The data-topic-id of the topic '${topic}' is ${dataTopicId}"
WebUI.closeBrowser()
When I execute this script, I saw the following message in the console:
The data-topic-id of the topic 'How to find created document in a web page that has no search box' is 168894
I guess, this code does something like you want to do.
There may be the ability to sort the list of documents in time order, such that your document would be the first. So, click on the Date/Time heading to sort it and then check the first row matches your Global Variable’s value. If you can investigate the HTML (hit the F12 key, then choose “Open Dev-Tools”), maybe there is an attribute that indicates which way the Date/Time heading is sorted that you should check first.