Mushfiq Absent Member.
Absent Member.
1012 views

Function for text check: Script to show error when a particular text is visible. (i.e. "Sorry, something went wrong)

HI. I would like my script to fail and throw an error when a particular test appears on the recorded site.  I know how to verify an existing text on the site but don't know how to make the script error out a text ("Sorry, something went wrong"). The script is just searching for a keyword and capturing the result. When the result page renders with a message "Sorry, something went wrong" and doesn't have the search result that is needed the script does not fail. Because it has the keyword that it is reaching and verifying that text. So I just need to know how to make the script fail when this message "Sorry, something went wrong shows up.

0 Likes
6 Replies
David Taggart Respected Contributor.
Respected Contributor.

RE: Function for text check: Script to show error when a particular text is visible. (i.e. "Sorry, something went wrong)

So you could always insert a function to verify a property exists, but set the flagmask to VERIFY_NOT_EQUAL.

For example,

BrowserVerifyProperty("//A[@textContents='Contact Us']", "textContents", "Contact Us", VERIFY_NOT_EQUAL, SEVERITY_ERROR);
0 Likes
Mushfiq Absent Member.
Absent Member.

RE: Function for text check: Script to show error when a particular text is visible. (i.e. "Sorry, something went wrong)

Thank you, David Taggart. So if I put the following line before the WebPageUrl line with the result page will that work. is the syntax correct?
BrowserVerifyProperty("//A[@textContents='Sorry, something went wrong']", "textContents", "Sorry, something went wrong", VERIFY_NOT_EQUAL, SEVERITY_ERROR);

I am currently text checking the keyword like this
WebVerifyHtml(ToEncoding(SearchKeyword), 1, WEB_FLAG_IGNORE_WHITE_SPACE | WEB_FLAG_EQUAL | WEB_FLAG_CASE_SENSITIVE, NULL, SEVERITY_ERROR, nVerifyHtmlResult2);

but if I want can I also use this format as the following to verify the text "Sorry, something went wrong" and make the script error out?
WebVerifyHtml(ToEncoding("Sorry, something went wrong"), 1, WEB_FLAG_IGNORE_WHITE_SPACE | WEB_FLAG_NOT_EQUAL | WEB_FLAG_CASE_SENSITIVE, NULL, SEVERITY_ERROR, nVerifyHtmlResult2);
0 Likes
David Taggart Respected Contributor.
Respected Contributor.

RE: Function for text check: Script to show error when a particular text is visible. (i.e. "Sorry, something went wrong)

Ah, the WebVerifyHTML function is a little different. The way that works is it looks for X instances of the text in quotes. In this case it's looking for 1 instance of "Sorry, something went wrong". What you'll want instead of WEB_FLAG_EQUAL is WEB_FLAG_SMALLER, so that you're looking for less than 1 instance of "Sorry, something went wrong".

The Web Functions Reference will have details on all available functions.

0 Likes
Mushfiq Absent Member.
Absent Member.

RE: Function for text check: Script to show error when a particular text is visible. (i.e. "Sorry, something went wrong)

It did not work sore some reason. I am getting the error message but the tool is not reporting on the text "Sorry, something went wrong".
this is what I used
WebVerifyHtml(ToEncoding("Sorry, something went wrong"), 1, WEB_FLAG_IGNORE_WHITE_SPACE | WEB_FLAG_SMALLER | WEB_FLAG_CASE_SENSITIVE, NULL,
SEVERITY_ERROR, nVerifyHtmlResult3);
0 Likes
David Taggart Respected Contributor.
Respected Contributor.

RE: Function for text check: Script to show error when a particular text is visible. (i.e. "Sorry, something went wrong)

Check your TrueLog results, see if it's finding the text.
0 Likes
Highlighted
Mushfiq Absent Member.
Absent Member.

RE: Function for text check: Script to show error when a particular text is visible. (i.e. "Sorry, something went wrong)

the text "Sorry, something went wrong" does not show in TrueLog results. It only appears sometimes when we run it as a load test with load. So I don't see the text in TrueLog. I ran it with double the load to be sure that the message can definitely show up.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.