I have no coding experience, nor Regular expression experience, ( or testautomation in general) but am willing to learn. So I’m quite a noob.
I searched the web for what is seems at first glance a simple problem. I can continue writing tests, but I want to be the test robust and can handle changing testdata.
I have an Object with a Text property “Daisy-boeken (25)” (ignore the quotes)
I want to check if the number is greater than 25.
I did some research but didn’t find a way via a regular expression to verify a match. I found some answers with simple expressions but they do not cover all the situations.
Like: Daisy-boeken \([2-9][6-9]\)
The number Daisy-boeken (30) will not match the regex, which it should.
Can someone point me out here how to improve the Regex?
Second question: Can this be solved programmaticaly in Groovy, without using regular expressions?
Any answer will be greatly appreciated, as it will improve my insights in Katalon,Groovy and Regex.
This particular problem is not one I’d use regex for, but still…
Try
2[5-9]|[3-9]\d+|[1-9]\d{2,}
I’d much prefer to extract the text and use Groovy but you don’t make clear exactly what HTML elements you’re dealing with – what (where) is your “text property”?
I’d much prefer to extract the text and use Groovy but you don’t make clear exactly what HTML elements you’re dealing with – what (where) is your “text property”?
Thanks for your anwser Russ,
I’ll attach a png the properties from the of the obecjt taken with object spy. I hope it will suffice.
I see. You’re dealing with Test Objects, not HTML elements. Seriously, I wouldn’t start there – it’s a bit like a guy in London who wants to fly into Paris airport by sailing across the Atlantic Ocean to New York and boarding a flight to France at JFK. Why go that way?
And if you really want to take that route, is there something wrong with Kazurayum’s code? It looks very comprehensive…
kazurayam
i want to search using “pro” in search bar, which gives me auto suggestion list irrespective of case (say “Idea Product”, “Products”),how do i verify if my search text is present in Suggestion list??
Right now i’m converting suggestion list results into smaller case & matchnig those stuff using selenium code…
I too am very new to everything. I have a test that calls a method to verify a file has been downloaded. Here is the method.
@Keyword
public boolean isFileDownloaded(String downloadPath, String fileName) {
//When using this, ensure your test case includes the following two lines
//String home = System.getProperty('user.home')
//String userDownloads = new File(home + '/Downloads/')
//use the variable userDownloads above as the downloadPath in this function call
File dir = new File(downloadPath);
File[] dirContents = dir.listFiles();
if (dirContents.length > 1) {
for (int i = 0; i < dirContents.length; i++) {
if (dirContents[i].getName().equals(fileName)) {
// File has been found, it can now be deleted
dirContents[i].delete();
KeywordUtil.markPassed("File has been successfully verified and deleted");
return true;
}
}
KeywordUtil.markFailedAndStop("File not found");
return false;
}
KeywordUtil.markFailedAndStop("No files to verify");
return false;
In my test, when I call the method I state the value of the variable fileName. However, that file name has a number in it that increases every time the file is downloaded ie: File_12345_Type.csv. I dont need to check the exact number to verify the file was downloaded, so I was hoping to use a regex to state the value. However, I would assume that you need to tell Katalon somehow that you are using a regex like in some commands. Any help with this would be appreciated =)
If anyone needs the answer, I edited the method this way @Keyword
public boolean isFileDownloadedRegEx(String downloadPath, String RegEx) {
//When using this, ensure your test case includes the following two lines
//String home = System.getProperty(‘user.home’)
//String userDownloads = new File(home + ‘/Downloads/’)
//use the variable userDownloads above as the downloadPath in this function call
Pattern regexPat = Pattern.compile(RegEx)
File dir = new File(downloadPath);
File[] dirContents = dir.listFiles();
if (dirContents.length > 1) {
for (int i = 0; i < dirContents.length; i++) {
Matcher mat = regexPat.matcher(dirContents[i].getName())
if (mat.find()) {
// File has been found, it can now be deleted
dirContents[i].delete();
KeywordUtil.markPassed(“File has been successfully verified and deleted”);
return true;
}
}
KeywordUtil.markFailedAndStop(“File not found”);
return false;
}
KeywordUtil.markFailedAndStop(“No files to verify”);
return false;