Parse html entities for special characters methods

I don’t think I shared this before. However if you are like me and grab values from the DB to compare you might run into character strings that need to be parsed. For example ‘(’ appears as ’ ('. In order to change this I have been using jsoup. Now I’m sure you could change this to a keyword but I prefer methods that I import.

Here is my one for doing the DB value parsed:

package miscMethods

import org.jsoup.Jsoup

/*
 * Author: B_L
 * Last Modified: 01/29/2019
 * Last Modified By: B_L
 * Purpose: parse db names
 * 
 */

public class DBValues {

	public static DBData getPrimeSalesUserCust() {
		DBData userData = findTestData('yourDBHere');
		return userData;
	}

	public static DBData getCustomerName(DBData userData) {
		String customerName = Jsoup.parse((userData.getValue(4, 1)).toString()).text();
		return customerName;
	}
}

another way to apply it to parse any string you pass:

package miscMethods

import org.jsoup.Jsoup


public class ParseString {

	public static DBData parseString(String stringToParse) {
		String parsedString = Jsoup.parse(stringToParse.toString()).text();
		return parsedString;
	}
}

just remember if you do it this way you’ll need to import at the top of your test case, unless you want to convert this to a keyword.

import miscMethods.ParseString 

String yourStringToParseHere = ParseString.parseString(yourStringToParseHere )
2 Likes