Hi.
I am attempting to use regular expression with the Find/Replace feature for the first time.
I have Katalon Studio test scripts which contain many multiple instances of text such as the following.
Thread.sleep(300)
Thread.sleep(1000)
Thread.sleep(2800)
etc…
Instead of changing them manually, I thought of using the regular expression in the Find/Replace feature. Thanks to a response in this post, I obtained the following regular expression.
Thread\s*\.\s*sleep\s*\(\s*\d+\s*\)
I ran the following script in Katalon, and it works perfectly to replace the given string.
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 static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
public class Main {
public static void main() {
String x = "Some Thread.sleep(1000) text";
x = x.replaceAll("Thread\\R?\\s*\\.\\s*sleep\\s*\\(\\s*\\d+\\s*\\)", "wait.Wait(driver, 1)");
System.out.println(x);
}
}
Main.main()
However, when I input the above regular expression verbatum into the “Find” field of the Find/Replace feature, and then select Options=Regular expressions, it finds nothing in the text, even though it has many instances of Thread.sleep.
What am I doing wrong? I have search other RefExp katalon posts, but don’t see a solution.
Ilya