<commit_before>package base.grid;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;

public abstract class BaseCell {

	private String selector;
	private WebDriver driver = null;
	private int row;
	private int column;
	private WebElement element;
	
	protected int getRow() {
		return row;
	}

	protected int getColumn() {
		return column;
	}

	public BaseCell(String selector, int row, int column) {
		this.selector = selector;
		this.row = row;
		this.column = column;
	}
	
	public BaseCell(String selector, String actionSelector, int row, int column) {
		this.selector = selector + actionSelector;
		this.row = row;
		this.column = column;
	}

	protected WebElement getElement() {
		try {
			esperaSpinLoad();
			element = null;
			element = driver.findElement(By.cssSelector(getFormatedSelector()));
			focusElement();
		} catch (NoSuchElementException e) {
		}
		return element;
	}
	
	private String getFormatedSelector(){
		String cellSelector = String.format(selector, row, column);
		return cellSelector;
	}

	private void focusElement() {
		JavascriptExecutor script = (JavascriptExecutor) driver;
		String focusScript = "$(\"%s\").focus()";
		script.executeScript(String.format(focusScript, getFormatedSelector()));
	}
	
	public String getText() {
		WebElement element = getElement();
		if (element == null)
			return null;
		return getElement().getText();
	}
	
	public void click() {
			By bySelector = By.cssSelector(getFormatedSelector());
			new FluentWait<WebDriver>(driver)
					.withTimeout(5, TimeUnit.SECONDS)
					.pollingEvery(100, TimeUnit.MILLISECONDS)
					.ignoring(NoSuchElementException.class)
					.until(ExpectedConditions.elementToBeClickable(bySelector))
					.sendKeys(Keys.ENTER);
			esperaSpinLoad();
	}

	protected void esperaSpinLoad() {
		esperaFecharElemento("[class='body-loader active']", 120);
	}

	private void esperaFecharElemento(String Css, int timeout) {
		new FluentWait<WebDriver>(driver).withTimeout(100, TimeUnit.SECONDS).pollingEvery(100, TimeUnit.MILLISECONDS)<commit_msg>Added comments to where waits and the webdriver have to be added.<commit_after>package base.grid;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;

public abstract class BaseCell {

	private String selector;
	// Add your WebDriver here
	private WebDriver driver = null;
	private int row;
	private int column;
	private WebElement element;
	
	protected int getRow() {
		return row;
	}

	protected int getColumn() {
		return column;
	}

	public BaseCell(String selector, int row, int column) {
		this.selector = selector;
		this.row = row;
		this.column = column;
	}
	
	public BaseCell(String selector, String actionSelector, int row, int column) {
		this.selector = selector + actionSelector;
		this.row = row;
		this.column = column;
	}

	protected WebElement getElement() {
		try {
			waitScreenLoader();
			element = null;
			element = driver.findElement(By.cssSelector(getFormatedSelector()));
			focusElement();
		} catch (NoSuchElementException e) {
		}
		return element;
	}
	
	private String getFormatedSelector(){
		String cellSelector = String.format(selector, row, column);
		return cellSelector;
	}

	private void focusElement() {
		JavascriptExecutor script = (JavascriptExecutor) driver;
		String focusScript = "$(\"%s\").focus()";
		script.executeScript(String.format(focusScript, getFormatedSelector()));
	}
	
	public String getText() {
		WebElement element = getElement();
		if (element == null)
			return null;
		return getElement().getText();
	}
	
	public void click() {
			By bySelector = By.cssSelector(getFormatedSelector());
			new FluentWait<WebDriver>(driver)
					.withTimeout(5, TimeUnit.SECONDS)
					.pollingEvery(100, TimeUnit.MILLISECONDS)
					.ignoring(NoSuchElementException.class)
					.until(ExpectedConditions.elementToBeClickable(bySelector))
					.click();
			waitScreenLoader();
	}

	protected void waitScreenLoader() {
		//If there is a screen loader, add its CssPath here.
		// With this, no action will be taken until the loader has closed
		String loaderCssPath = "";
		waitElementClose(loaderCssPath, 120);
	}

	private void waitElementClose(String Css, int timeout) {
		new FluentWait<WebDriver>(driver).withTimeout(100, TimeUnit.SECONDS).pollingEvery(100, TimeUnit.MILLISECONDS)
{'fraction_non_alphanumeric': 0.1082463679148762, 'fraction_numerical': 0.005320237364436259, 'mean_word_length': 4.7036172695449245, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5379910', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1490, 'n_words': 357}