Page 1 of 1

Isolating a specific notification

Posted: 06 Jan 2015 22:26
by MURTUMA
I'm trying to isolate a specific notification from a single app. The only thing I can use is a percentage value in notification_text variable. In this case I want that notification to stop from continuing the flow while other notifications would go forward.

I handle the logic but not the scripting: contains(notification_text, this is the part where I'm lost.);

That should return either true or false which will be checked in expression condition. That part I handle too but not the above one.

To make it clear, I need to find value x%, where x is something between 0 and 100. There's no space between numerics and %.

I've read all the help files regarding regular expressions and scripting in general but they're not as noob friendly as I'd need, so I'm stuck.

Thanks!

Re: Isolating a specific notification

Posted: 07 Jan 2015 20:11
by Martin
I would use regular expressions in this case.

The function matches(text, regexp) tests if a text matches the specified pattern so a script like this should work in a test flow.

Code: Select all

notification_text = "test 85% xyz";
and then a condition Expression with script:

Code: Select all

matches(notification_text, ".*\\d+%.*");
.* matches any number of leading characters then \\d+ for one or multiple digits, followed by a percent sign and then any number of trailing characters.
It's probably cleaner to use a reluctant quantifier ? for the first .* so that it does not match the 8 of 85%.

Code: Select all

matches(notification_text, ".*?\\d+%.*");
You could also extract the percent value with a script like this:

Code: Select all

notification_text = "test 85% xyz";
groups = newList();
matches(notification_text, ".*?(\\d+%).*", groups);
value = getElement(groups, 1);
Regards,
Martin

Re: Isolating a specific notification

Posted: 07 Jan 2015 21:39
by MURTUMA
I couldn't get it working.

The notification_text variable can contain something like "qwerty.png 45%", without quotes. When I check that value in text editor through debug dialog it shows following:

qwerty.png
45%

Notice the two lines, if that makes any difference.

The notification itself looks like this:

qwerty.png
45%

The header is bold, percent value is not. Also, the notification returns a value for content_title variable which in this case is "qwerty.png" but otherwise does not seem to use or show it anywhere.

For a remainder, I'm still stuck on my old SGS+ Gingerbread. Just saying so you'll get better idea how notifications work, if that matters.

Anyway, thanks for the answer, although, the case is still open. And would you happen to know anything better place, where I could learn more about the similar scripting language AM uses?

Re: Isolating a specific notification

Posted: 07 Jan 2015 21:51
by Martin
I did not consider that the text contains multiple lines.
You could either replace the newlines in the string with spaces or you could turn on DOTALL mode in the regular expression so that a dot also matches newlines:
matches(notification_text, "(?s).*?(\\d+%).*", groups);

Re: Isolating a specific notification

Posted: 07 Jan 2015 22:36
by MURTUMA
Yeah, I didn't neither notice the newline at first, as the debug dialog only shows the value in one line. But now it works. Thanks for your help, again!