get text to verify another testcase

a dhiyaul asikin
1 min readJan 24, 2020

--

Hello, I will share how get text in testcase1 can use to another testcase. example :

TestCase1 :

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

// parameters def URL = “https://www.google.com/search?q=katalon" def testObject = new TestObject().addProperty(“xpath”, ConditionType.EQUALS, “//div[@id=’resultStats’]”)

// create directory to locate a temporary file Path
projectDir = Paths.get(RunConfiguration.getProjectDir())
Path tmpDir = projectDir.resolve(‘tmp’)
if (!Files.exists(tmpDir)) {
Files.createDirectory(tmpDir)
}
// Prepare File object
File dataFile = tmpDir.resolve(‘data.txt’).toFile()

// open a web page
WebUI.openBrowser(‘’)
WebUI.navigateToUrl(URL)
WebUI.verifyElementPresent(testObject, 10)

// retrieve a text labeled “result stats” from the Google Search Result page String value = WebUI.getText(testObject).trim()

// save the text into a file under <project dir>/tmp directory
dataFile.text = value

WebUI.closeBrowser()’

TestCase2 :

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

// parameters
def URL = “https://www.google.com/search?q=katalon"
def testObject = new TestObject().addProperty(“xpath”, ConditionType.EQUALS, “//div[@id=’resultStats’]”)

// create directory to locate a temporary file
Path projectDir = Paths.get(RunConfiguration.getProjectDir())
Path tmpDir = projectDir.resolve(‘tmp’)
if (!Files.exists(tmpDir)) {
Files.createDirectory(tmpDir)
}

// read the file to retrieve the data prepared by TestScript1
File dataFile = tmpDir.resolve(‘data.txt’).toFile()
String previousValue = dataFile.text.trim()

// open a web page
WebUI.openBrowser(‘’) WebUI.navigateToUrl(URL) WebUI.verifyElementPresent(testObject, 10)

// verify if the same value as the data is displayed in the web page //WebUI.verifyTextPresent(value, false)
// this line often fails with no meaningful diagnostics

def currentValue = WebUI.getText(testObject).trim()
assert currentValue == previousValue
WebUI.closeBrowser()

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

a dhiyaul asikin
a dhiyaul asikin

No responses yet

Write a response