<commit_before>package au.com.agic.apptesting.utils.impl;

import au.com.agic.apptesting.exception.InvalidInputException;
import au.com.agic.apptesting.utils.FeatureState;
import au.com.agic.apptesting.utils.GetBy;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;

import static com.google.common.base.Preconditions.checkState;

/**
 * Implementation of the GetBy service
 */
public class GetByImpl implements GetBy {
	@Override
	public By getBy(
			final String selector,
			final boolean valueAlias,
			final String value,
			final FeatureState featureState) {

		final String fixedValue = valueAlias ? featureState.getDataSet().get(value) : value;

		checkState(StringUtils.isNotBlank(fixedValue), "Selector or alias is blank");

		if (ID.equals(selector)) {
			return By.id(fixedValue);
		}

		if (XPATH.equals(selector)) {
			return By.xpath(fixedValue);
		}

		if (CLASS.equals(selector)) {
			return By.cssSelector("." + fixedValue);
		}

		if (NAME.equals(selector)) {
			return By.name(fixedValue);
		}

		if (VALUE.equals(selector)) {
			final String escaped = fixedValue.replaceAll("'", "\'");
			return By.cssSelector("[value='" + escaped + "']");
		}

		if (CSS_SELECTOR.equals(selector)) {
			return By.cssSelector(fixedValue);
		}

		if (TEXT.equals(selector)) {
			final String escaped = fixedValue.replaceAll("'", "''");
			return By.xpath("//*[text()='" + escaped + "')");
		}

		throw new InvalidInputException("Unexpected selector");
	}
}<commit_msg>Fixed up a selection based on text content<commit_after>package au.com.agic.apptesting.utils.impl;

import au.com.agic.apptesting.exception.InvalidInputException;
import au.com.agic.apptesting.utils.FeatureState;
import au.com.agic.apptesting.utils.GetBy;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;

import static com.google.common.base.Preconditions.checkState;

/**
 * Implementation of the GetBy service
 */
public class GetByImpl implements GetBy {
	@Override
	public By getBy(
			final String selector,
			final boolean valueAlias,
			final String value,
			final FeatureState featureState) {

		final String fixedValue = valueAlias ? featureState.getDataSet().get(value) : value;

		checkState(StringUtils.isNotBlank(fixedValue), "Selector or alias is blank");

		if (ID.equals(selector)) {
			return By.id(fixedValue);
		}

		if (XPATH.equals(selector)) {
			return By.xpath(fixedValue);
		}

		if (CLASS.equals(selector)) {
			return By.cssSelector("." + fixedValue);
		}

		if (NAME.equals(selector)) {
			return By.name(fixedValue);
		}

		if (VALUE.equals(selector)) {
			final String escaped = fixedValue.replaceAll("'", "\'");
			return By.cssSelector("[value='" + escaped + "']");
		}

		if (CSS_SELECTOR.equals(selector)) {
			return By.cssSelector(fixedValue);
		}

		if (TEXT.equals(selector)) {
			final String escaped = fixedValue.replaceAll("'", "''");
			return By.xpath("//*[text()='" + escaped + "']");
		}

		throw new InvalidInputException("Unexpected selector");
	}
}
{'fraction_non_alphanumeric': 0.14290439960304333, 'fraction_numerical': 0.0006615944426066821, 'mean_word_length': 4.361702127659575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '373518', 'n_tokens_mistral': 1076, 'n_tokens_neox': 948, 'n_words': 199}