<commit_before>package com.autonomy.abc.selenium.page;

import com.autonomy.abc.selenium.menubar.NavBarTabId;
import com.autonomy.abc.selenium.menubar.SideNavBar;
import com.autonomy.abc.selenium.menubar.TopNavBar;
import com.autonomy.abc.selenium.util.AbstractMainPagePlaceholder;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.List;

public class KeywordsPage extends KeywordsBase implements AppPage {

	public KeywordsPage(final SideNavBar sideNavBar, final WebElement $el) {
		super($el, sideNavBar.getDriver());
	}

	@Override
	public void navigateToPage() {
		getDriver().get("promotions");
	}

	public WebElement createNewKeywordsButton() {
		return findElement(By.xpath(".//a[contains(text(), 'Create new keywords')]"));
	}

	public void deleteAllSynonyms() throws InterruptedException {
		loadOrFadeWait();
		filterView("Synonyms");

		for (final String language : getLanguageList()) {
			selectLanguage(language);
			final int numberOfSynonymGroups = findElements(By.cssSelector(".keywords-list li:first-child .remove-search-synonym")).size();

			if (numberOfSynonymGroups >= 2) {
				for (int i = 0; i <= numberOfSynonymGroups; i++) {
					if (findElements(By.cssSelector(".keywords-list li:first-child .remove-search-synonym")).size() > 2) {
						findElement(By.cssSelector(".keywords-list li:first-child .remove-search-synonym")).click();
						Thread.sleep(3000);
					} else {
						if (findElements(By.cssSelector(".keywords-list li:first-child .remove-search-synonym")).size() == 2) {
							findElement(By.cssSelector(".keywords-list li:first-child .remove-search-synonym")).click();
						}

						loadOrFadeWait();
						break;
					}
				}
			}
		}
	}

	public int countSynonymLists(final String language) {
		final List<String> synonymLists = new ArrayList<>();

		for (final WebElement synonymGroup : findElement(By.cssSelector(".keywords-list")).findElements(By.xpath(".//li[contains(@data-language, '" + language.toLowerCase() + "')]/../../ul[contains(@class, 'synonyms-list')]"))) {
			if (!synonymGroup.getText().equals("")) {
				synonymLists.add(synonymGroup.getText());
			}
		}

		return synonymLists.size() - getBlacklistedTerms().size();
	}

	public WebElement leadSynonym(final String synonym) {
		return findElement(By.xpath(".//div[contains(@class, 'keywords-list')]/ul/li/ul[contains(@class, 'synonyms-list')]/li[1][@data-keyword='" + synonym + "']"));
	}

	private int getNumberOfLanguages() {<commit_msg>[abc] Rename of selector on keywords page [rev:none]<commit_after>package com.autonomy.abc.selenium.page;

import com.autonomy.abc.selenium.menubar.NavBarTabId;
import com.autonomy.abc.selenium.menubar.SideNavBar;
import com.autonomy.abc.selenium.menubar.TopNavBar;
import com.autonomy.abc.selenium.util.AbstractMainPagePlaceholder;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.List;

public class KeywordsPage extends KeywordsBase implements AppPage {

	public KeywordsPage(final SideNavBar sideNavBar, final WebElement $el) {
		super($el, sideNavBar.getDriver());
	}

	@Override
	public void navigateToPage() {
		getDriver().get("promotions");
	}

	public WebElement createNewKeywordsButton() {
		return findElement(By.xpath(".//a[contains(text(), 'Create new keywords')]"));
	}

	public void deleteAllSynonyms() throws InterruptedException {
		loadOrFadeWait();
		filterView("Synonyms");

		for (final String language : getLanguageList()) {
			selectLanguage(language);
			final int numberOfSynonymGroups = findElements(By.cssSelector(".keywords-list li:first-child .remove-synonym")).size();

			if (numberOfSynonymGroups >= 2) {
				for (int i = 0; i <= numberOfSynonymGroups; i++) {
					if (findElements(By.cssSelector(".keywords-list li:first-child .remove-synonym")).size() > 2) {
						findElement(By.cssSelector(".keywords-list li:first-child .remove-synonym")).click();
						Thread.sleep(3000);
					} else {
						if (findElements(By.cssSelector(".keywords-list li:first-child .remove-synonym")).size() == 2) {
							findElement(By.cssSelector(".keywords-list li:first-child .remove-synonym")).click();
						}

						loadOrFadeWait();
						break;
					}
				}
			}
		}
	}

	public int countSynonymLists(final String language) {
		final List<String> synonymLists = new ArrayList<>();

		for (final WebElement synonymGroup : findElement(By.cssSelector(".keywords-list")).findElements(By.xpath(".//li[contains(@data-language, '" + language.toLowerCase() + "')]/../../ul[contains(@class, 'synonyms-list')]"))) {
			if (!synonymGroup.getText().equals("")) {
				synonymLists.add(synonymGroup.getText());
			}
		}

		return synonymLists.size() - getBlacklistedTerms().size();
	}

	public WebElement leadSynonym(final String synonym) {
		return findElement(By.xpath(".//div[contains(@class, 'keywords-list')]/ul/li/ul[contains(@class, 'synonyms-list')]/li[1][@data-keyword='" + synonym + "']"));
	}

	private int getNumberOfLanguages() {
{'fraction_non_alphanumeric': 0.15723761217323448, 'fraction_numerical': 0.00351150994927819, 'mean_word_length': 4.793220338983051, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '2768014', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1614, 'n_words': 277}