All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.jarch.test.page.BasePage Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package br.com.jarch.test.page;

import br.com.jarch.core.util.BundleUtils;
import br.com.jarch.test.TestUtils;
import br.com.jarch.util.*;
import br.com.jarch.core.type.FieldType;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.List;

public abstract class BasePage {
	private static final String MAIN_MENU = "Main Menu";
	private static final String FINAL_MENU = "Final Menu";
	private static final String LIST_JSF = "list.jsf";
	private static final String DATA_JSF = "data.jsf";
	protected int timeSecondsWaitMessage = 30;
	protected int timeSecondsWaitAjax = 10;
	protected int timeSecondsWaitPage = 30;
	protected int timeSecondsWaitDocumentReady = 5;
	protected int timeSecondsWaitLookup = 30;
	protected int timeSecondsWaitComponentReady = 5;
	protected int timeWaitMilliSeconds = 150;
	protected int timeWaitMilliSecondsScroll = 500;
	protected int timeSecondsOpenDialog = 5;
	protected int timeSecondsCloseDialog = 1;
	protected int timeSecondsOpenDivDataDetail = 3;
	protected int timeSecondsCloseDivDataDetail = 3;
	protected int timeSecondsWaitMessageSuccess = 60;
	private WebDriver driver;

	public BasePage(WebDriver driver) {
		this.driver = driver;
//		Locale.setDefault(new Locale("pt", "BR"));
		PageFactory.initElements(driver, this);
	}

	protected String getFolderXhtml() {
		return CharacterUtils.removeCharEspecial(getFinalMenu()).replace(" ", "").toLowerCase();
	}

	protected String getMainMenu() {
		return MAIN_MENU;
	}

	protected String getFinalMenu() {
		return FINAL_MENU;
	}

	protected String getPageList() {
		return LIST_JSF;
	}

	protected String getPageData() {
		return DATA_JSF;
	}

	public WebElement findElement(By by) {
		waitElementReady(by);
		return driver.findElement(by);
	}

	public List findElements(By by) {
		return driver.findElements(by);
	}

	public void clear(By by) {
		clear(findElement(by));
	}

	public void clear(WebElement element) {
		waitElementReady(element);
		element.clear();
		waitForDefault();
	}

	public void clickClearSendKeys(By by, CharSequence... keys) {
		clickClearSendKeys(findElement(by), keys);
	}

	public void clickClearSendKeys(WebElement element, CharSequence... keys) {
		click(element);
		clear(element);
		sendKeys(element, keys);
	}

	public void sendKeys(By by, CharSequence... keys) {
		sendKeys(findElement(by), keys);
	}

	public void sendKeys(WebElement element, CharSequence... keys) {
		waitElementReady(element);
		element.sendKeys(keys);
		waitForDefault();
	}

	public boolean isElementReady(By by, int seconds) {
		try {
			WebElement webElement = driver.findElement(by);
			waitElementReady(webElement, seconds);
			return true;
		} catch (Exception ex) {
			return false;
		}
	}

	public boolean isElementDisplayed(By by) {
		try {
			WebElement webElement = driver.findElement(by);
			return webElement.isDisplayed();
		} catch (Exception ex) {
			return false;
		}
	}

	public void waitElementReady(WebElement element) {
		waitElementReady(element, timeSecondsWaitComponentReady);
	}

	public void waitElementReady(By by) {
		isElementReady(by, timeSecondsWaitComponentReady);
	}

	public void waitElementReady(WebElement element, int seconds) {
		new FluentWait<>(driver)
				.withTimeout(Duration.ofSeconds(seconds))
				.pollingEvery(Duration.ofSeconds(1))
				.ignoring(Exception.class)
				.until(d -> ExpectedConditions.visibilityOf(element));

		new FluentWait<>(driver)
				.withTimeout(Duration.ofSeconds(seconds))
				.pollingEvery(Duration.ofSeconds(1))
				.ignoring(Exception.class)
				.until(d -> element.isDisplayed());
	}

	public void click(By by) {
		WebElement webElement = findElement(by);
		click(webElement);
	}

	public void click(WebElement element) {
		waitElementReady(element);
		try {
			element.click();
		} catch (Exception ex) {
			if (isTryAgain(ex)) {
				scrollTo(element);
				click2(element);
			} else {
				throw ex;
			}
		}

		waitForDefault();
	}

	private static boolean isTryAgain(Exception ex) {
		return ex.getMessage() != null
				&& (ex.getMessage().contains("is not clickable at point")
				|| ex.getMessage().contains("Unable to locate element")
				|| ex.getMessage().contains("Other element would receive the click")
				|| ex.getMessage().contains("element is not attached to the page document"));
	}

	private void click2(WebElement element) {
		try {
			element.click();
			waitForDefault();
		} catch (Exception ex) {
			if (isTryAgain(ex)) {
				scrollBottomPage();
				click3(element);
			} else {
				throw ex;
			}
		}
	}

	private void click3(WebElement element) {
		element.click();
		waitForDefault();
	}

	public void submit(By by) {
		waitElementReady(by);
		findElement(by).submit();
	}

	public void waitForPage(String page) {
		waitForPage(page, timeSecondsWaitPage);
	}

	public void waitForPage(String page1, String page2) {
		waitForPage(page1, page2, timeSecondsWaitPage);
	}

	public void waitForPage(String page, int seconds) {
		LogUtils.generate("Aguardando pagina " + page);

		new FluentWait<>(driver)
				.withTimeout(Duration.ofSeconds(seconds))
				.pollingEvery(Duration.ofSeconds(1))
				.ignoring(Exception.class)
				.until(e -> e.getCurrentUrl().contains(page));
	}

	public void waitForPage(String page1, String page2, int seconds) {
		LogUtils.generate("Aguardando pagina " + page1 + " ou " + page2);

		new FluentWait<>(driver)
				.withTimeout(Duration.ofSeconds(seconds))
				.pollingEvery(Duration.ofSeconds(1))
				.ignoring(Exception.class)
				.until(e -> e.getCurrentUrl().contains(page1)
						|| e.getCurrentUrl().contains(page2));
	}

	public void waitForMessage(String message) {
		waitForMessage(message, timeSecondsWaitMessage);
	}

	public void waitForMessage(String message, int seconds) {
		LogUtils.generate("Aguardando mensagem " + message);

		new FluentWait<>(driver)
				.withTimeout(Duration.ofSeconds(seconds))
				.pollingEvery(Duration.ofSeconds(1))
				.ignoring(Exception.class)
				.until(d -> d.getPageSource().contains(message));
	}

	public void waitForDontMessage(String message) {
		waitForDontMessage(message, timeSecondsWaitMessage);
	}

	public void waitForDontMessage(String message, int seconds) {
		LogUtils.generate("Aguardando nao existir a mensagem " + message);

		new FluentWait<>(driver)
				.withTimeout(Duration.ofSeconds(seconds))
				.pollingEvery(Duration.ofSeconds(1))
				.ignoring(Exception.class)
				.until(e -> !e.getPageSource().contains(message));
	}

	protected boolean isAlertPresent() {
		try {
			driver.switchTo().alert();
			return true;
		} catch (NoAlertPresentException e) {
			return false;
		}
	}

	protected String closeAlertAndGetItsText(boolean acceptNextAlert) {
		Alert alert = driver.switchTo().alert();
		String alertText = alert.getText();

		if (acceptNextAlert)
			alert.accept();
		else
			alert.dismiss();

		return alertText;
	}

	protected void waitDocumentReady() {
		new WebDriverWait(driver, Duration.ofSeconds(timeSecondsWaitDocumentReady))
				.until(wd -> {
					LogUtils.generate("Aguardando !!!");
					return ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("completeTask");
				});
	}

	public void login(String url, String login, String senha) {
		TestUtils.login(driver, url, login, senha);
	}

	public void logout() {
		click(By.cssSelector("#navbartop >ul >li > .botaoSairMenu"));
		click(By.cssSelector(".swal-button--danger"));
	}

	public void wellcome() {
		click(By.cssSelector("#navbartop > ul > li > a"));
	}

	public void waitForMessageSuccess() {
		waitForMessage("Procedimento realizado com sucesso", timeSecondsWaitMessageSuccess);
		waitElementReady(By.cssSelector(".swal-button--confirm"));
		clickButtonOkMessageProcess();
	}

	public void waitForMessageProcess() {
		TestUtils.waitForMessageProcess(driver, timeSecondsWaitMessage);
	}

	public void waitForAjaxProcess() {
		TestUtils.waitForAjaxProcess(driver, timeSecondsWaitAjax);
	}

	public void waitForDefault() {
		SleepUtils.pauseMilliSeconds(timeWaitMilliSeconds);
	}

	public void waitForPageList() {
		waitForPage(getPageList());
	}

	public void waitForPageData() {
		waitForPage(getPageData());
	}

	public void waitForPageListOrData() {
		waitForPage(getPageList(), getPageData());
	}

	public void acessMainMenu(String mainMenu) {
		By byCssSelector = By.cssSelector("#side-menu > li.active > a");

		if (isElementReady(byCssSelector, 3)) { // se tiver aberto fecha...
			scrollTo(byCssSelector);
			click(byCssSelector);
		}

		By byMainMenu = By.xpath("//span[text()='" + mainMenu + "']");
		scrollTo(byMainMenu);
		click(byMainMenu);
	}

	public void acessFinalMenu(String mainMenu) {
		if (mainMenu == null || mainMenu.isEmpty()) {
			return;
		}

		scrollTo(By.linkText(mainMenu));
		click(By.linkText(mainMenu));
	}

	public void scrollTopPage() {
		((JavascriptExecutor) driver).executeScript("window.scrollTo(0, 0)");
	}

	public void scrollBottomPage() {
		((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
		waitForScroll();
	}

	public void scrollTo(By by) {
		scrollTo(findElement(by));
		waitForScroll();
	}

	public void scrollTo(WebElement webElement) {
		TestUtils.scrollTo(driver, webElement);
		waitForScroll();
	}

	public void close() {
		driver.close();
	}

	public void quit() {
		driver.quit();
	}

	public boolean isExistsButtonInsert() {
		return isCurrentPageList() && isExists(By.cssSelector(".divlistdatatable__button-insert"));
	}

	public void clickListActionInsert() {
		click(By.cssSelector(".divlistdatatable__button-insert"));
		waitForPageData();
	}

	public boolean isExistsButtonClone() {
		if (!isCurrentPageList()) {
			return false;
		}

		try {
			click(By.cssSelector(".divlistdatatable__menubutton-action > button"));
			return isExists(By.cssSelector("div[style*='display: block'] > ul > li > .divlistdatatable__menuitem-clone"));
		} catch (Exception ex) {
			return false;
		}
	}

	public void clickListActionClone() {
		click(By.cssSelector(".divlistdatatable__menubutton-action > button"));
		click(By.cssSelector("div[style*='display: block'] > ul > li > .divlistdatatable__menuitem-clone"));
		waitForPageData();
	}

	public boolean isExistsButtonChange() {
		if (!isCurrentPageList()) {
			return false;
		}

		try {
			click(By.cssSelector(".divlistdatatable__menubutton-action > button"));
			return isExists(By.cssSelector("div[style*='display: block'] > ul > li > .divlistdatatable__menuitem-change"));
		} catch (Exception ex) {
			return false;
		}
	}

	public void clickListActionChange() {
		click(By.cssSelector(".divlistdatatable__menubutton-action > button"));
		click(By.cssSelector("div[style*='display: block'] > ul > li > .divlistdatatable__menuitem-change"));
		waitForPageData();
	}

	public void clickListActionDynamicPosition(int position) {
		click(By.cssSelector(".divlistdatatable__menubutton-action > button"));
		click(By.cssSelector("div[style*='display: block'] > ul > li:nth-child(" + position + ") > .divlistdatatable__menuitem-dynamic"));
		waitForPageData();
	}

	public boolean isExistsButtonConsult() {
		if (!isCurrentPageList()) {
			return false;
		}

		try {
			click(By.cssSelector(".divlistdatatable__menubutton-action > button"));
			return isExists(By.cssSelector("div[style*='display: block'] > ul > li > .divlistdatatable__menuitem-consult"));
		} catch (Exception ex) {
			return false;
		}
	}

	public void clickListActionConsult() {
		click(By.cssSelector(".divlistdatatable__menubutton-action > button"));
		click(By.cssSelector("div[style*='display: block'] > ul > li > .divlistdatatable__menuitem-consult"));
		waitForPageData();
	}

	public boolean isExistsButtonDelete() {
		if (!isCurrentPageList()) {
			return false;
		}

		try {
			click(By.cssSelector(".divlistdatatable__menubutton-action > button"));
			return isExists(By.cssSelector("div[style*='display: block'] > ul > li > .divlistdatatable__menuitem-delete"));
		} catch (Exception ex) {
			return false;
		}
	}

	public void clickListActionDelete() {
		By by = By.cssSelector(".divlistdatatable__menubutton-action > button");
		click(by);
		click(By.cssSelector("div[style*='display: block'] > ul > li > .divlistdatatable__menuitem-delete"));
		waitForPageData();
	}

	public void scrollToMasterSave() {
//        scrollTo(By.className("paneldatamaster__button-save"));
		TestUtils.scrollToButtonsDivDataMaster(driver, findElement(By.cssSelector(".paneldatamaster__button-save")));
	}

	public void clickMasterSave() {
		click(By.className("paneldatamaster__button-save"));
	}

	public void clickMasterSaveDontEndTask() {
		click(By.className("paneldatamaster__button-dontendtask"));
	}

	public void clickMasterSaveEndTask() {
		click(By.className("paneldatamaster__button-endtask"));
	}

	public void clickMasterConfirm() {
		click(By.cssSelector(".ui-confirm-dialog .paneldatamaster__button-confirm"));
	}

	public void scrollToMasterDelete() {
//        scrollTo(By.className("paneldatamaster__button-delete"));
		TestUtils.scrollToButtonsDivDataMaster(driver, findElement(By.cssSelector(".paneldatamaster__button-delete")));
	}

	public void clickMasterDelete() {
		click(By.className("paneldatamaster__button-delete"));
	}

	public void clickMasterConfirmDelete() {
		clickMasterConfirmDelete("");
	}

	public void clickMasterConfirmDelete(String message) {
		if (message == null
				|| message.isEmpty()) {
			message = "Deseja Realmente Excluir o Registro ?";
		}

		waitForAjaxProcess();

		waitForMessage(message);

		click(By.cssSelector(".ui-confirm-dialog .paneldatamaster__button-confirm"));
	}

	public void scrollToMasterReturn() {
//        scrollTo(By.className("paneldatamaster__button-return"));
		TestUtils.scrollToButtonsDivDataMaster(driver, findElement(By.cssSelector(".paneldatamaster__button-return")));
	}

	public void clickMasterReturn() {
		click(By.className("paneldatamaster__button-return"));
	}

	public void clickMasterDynamic() {
		click(By.className("paneldatamaster__button-dynamic"));
	}

	public void clickMasterDynamicEndTask() {
		click(By.className("paneldatamaster__button-dynamic-endtask"));
	}

	public void clickMasterDynamicDontEndTask() {
		click(By.className("paneldatamaster__button-dynamic-dontendtask"));
	}

	public void clickListSearch() {
		click(By.className("filtersearch__button-search"));
		waitForMessageProcess();
	}

	public void clickListSearch(String id) {
//                click(By.className("filtersearch__button-search"));
		click(By.cssSelector("div[id*='" + id + "'] .filtersearch__button-search"));
		waitForMessageProcess();
	}

	public void clickListTaskSearch(int tab) {
		click(By.cssSelector("div[id = 'tab-" + tab + "'] .filtersearch__button-search"));
		waitForMessageProcess();
	}

	public void clickFilterSelectionClean() {
		click(By.className("filtersearch__button-clean"));
	}

	public void clickFilterSelectionClean(String id) {
		click(By.cssSelector("div[id*='" + id + "'] .filtersearch__button-clean"));
	}

	public void clickFilterSelectionSearch() {
		clickListSearch();
	}

	public void clickFilterSelectionSearch(String id) {
		clickListSearch(id);
	}

	public void clickFilterSelectionSendSelects() {
		click(By.cssSelector(".dialogselect__save"));
	}

	protected boolean isCurrentPageList() {
		return driver.getCurrentUrl().contains(getPageList());
	}

	protected boolean isCurrentPageData() {
		return driver.getCurrentUrl().contains(getPageList());
	}

	public void goPageList() {
		goPageListFromUrl();

		if (isPageNotFound()) {
			goPageListFromMenu();
		}
	}

	public boolean isPageNotFound() {
		return driver.getPageSource().contains(BundleUtils.messageBundle("message.paginaNaoEncontrado"));
	}

	public void goPageListFromMenu() {
		if (!isCurrentPageList() || isPageNotFound()) {
			acessMainMenu(getMainMenu());
			acessFinalMenu(getFinalMenu());
			waitForPageList();
		}
	}

	public void goPageListFromUrl() {
		goPageListFromUrl(true);
	}

	public void goPageListFromUrl(boolean validPageList) {
		if (!isCurrentPageList()) {
			String currentUrl = driver.getCurrentUrl();
			currentUrl = currentUrl.substring(0, currentUrl.indexOf("/paginas/") + 9);
			currentUrl = currentUrl.concat(getFolderXhtml());
			currentUrl = currentUrl.concat("/");
			currentUrl = currentUrl.concat(getPageList());
			driver.get(currentUrl);
			if (validPageList) {
				waitForPageList();
			}
		}
	}

	public void goPageListFromUrlAndWaitListOrData() {
		if (!isCurrentPageList()) {
			String currentUrl = driver.getCurrentUrl();
			currentUrl = currentUrl.substring(0, currentUrl.indexOf("/paginas/") + 9);
			currentUrl = currentUrl.concat(getFolderXhtml());
			currentUrl = currentUrl.concat("/");
			currentUrl = currentUrl.concat(getPageList());
			driver.get(currentUrl);
			waitForPageListOrData();
		}
	}

	public void clickMasterCancel() {
		click(By.className("paneldatamaster__button-cancel"));
	}

	public void fillLookup(String lookupId, String value) {
		By code = By.cssSelector("input[id *= '" + lookupId + ":codeLookup']");
		fillLookup(code, value);
		waitForAjaxProcess();
	}

	public void fillLookup(By codeLookup, String value) {
		fillLookup(findElement(codeLookup), value);
	}

	public void fillLookup(WebElement webElement, String value) {
		new FluentWait<>(driver)
				.withTimeout(Duration.ofSeconds(timeSecondsWaitLookup))
				.pollingEvery(Duration.ofSeconds(1))
				.ignoring(Exception.class)
				.until(d -> ExpectedConditions.elementToBeClickable(webElement));

		clickClearSendKeys(webElement, value);
		tab(webElement);
		waitForAjaxProcess();

	}

	public void pauseSeconds(int seconds) {
		SleepUtils.pauseSeconds(seconds);
	}

	public WebDriver getDriver() {
		return driver;
	}

	public void clickDetailDivDataDetailTabSave() {
		click(By.className("paneldatadetailtab__button-save"));
		waitForAjaxProcess();
		waitForCloseDivDetail();
	}

	public void waitForOpenDivDetail() {
		pauseSeconds(timeSecondsOpenDivDataDetail);
	}

	public void waitForCloseDivDetail() {
		pauseSeconds(timeSecondsCloseDivDataDetail);
	}

	public void waitForScroll() {
		SleepUtils.pauseMilliSeconds(timeWaitMilliSecondsScroll);
	}

	public void waitForOpenDialog() {
		pauseSeconds(timeSecondsOpenDialog);
	}

	public void waitForCloseDialog() {
		pauseSeconds(timeSecondsCloseDialog);
		waitForAjaxProcess();
	}

	public void filterComboTask(int tab, String nameTask) {
//		nameTask = nameTask.replace("\n", "");
		click(By.cssSelector("label[id *= 'selectOneMenuTaskFilter" + tab + "_label']"));
		click(By.cssSelector("div[style *= 'display: block'] > div > ul > li[data-label = '" + nameTask + "']"));
		waitForDefault();
	}

	public void clickDetail(String titleTab) {
		click(By.xpath("//a[text() = '" + titleTab + "']"));
		waitForPageData();
	}

	public void clickDetail(Integer index) {
		click(By.cssSelector("li[data-index = '" + index + "']"));
		waitForPageData();
	}

	public void clickDetailActionInsert(String href) {
		click(By.xpath("//a[contains(@href, '" + href + "')]/span/input"));
		waitForPageData();
	}

	public void clickDetailActionClone(int detailNumber) {
		click(By.xpath("//button[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_button')]"));
		click(By.cssSelector("div[id $= 'dataTableDetail:" + (detailNumber - 1) + ":mb_menu'] .tabbody__menuitem-clone"));
		waitForPageData();
	}

	public void clickDetailActionChange(int detailNumber) {
		click(By.xpath("//button[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_button')]"));
		click(By.cssSelector("div[id $= 'dataTableDetail:" + (detailNumber - 1) + ":mb_menu'] .tabbody__menuitem-change"));
		waitForPageData();
	}

	public void clickDetailActionConsult(int detailNumber) {
		click(By.xpath("//button[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_button')]"));
		click(By.cssSelector("div[id $= 'dataTableDetail:" + (detailNumber - 1) + ":mb_menu'] .tabbody__menuitem-consult"));
		waitForPageData();
	}

	public void clickDetailActionDelete(int detailNumber) {
		click(By.xpath("//button[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_button')]"));
		click(By.cssSelector("div[id $= 'dataTableDetail:" + (detailNumber - 1) + ":mb_menu'] .tabbody__menuitem-delete"));
		waitForPageData();
	}

	public void clickDetailSave() {
		click(By.xpath("//a[contains(@class, 'tabbody__button-save')]"));
		waitForAjaxProcess();
	}

	public void clickDetailCancel() {
		click(By.xpath("//a[contains(@class, 'tabbody__button-cancel')]"));
	}

	public void clickDetailReturn() {
		click(By.xpath("//a[contains(@class, 'tabbody__button-return')]"));
	}

	public void clickDetailDelete() {
		click(By.xpath("//button[contains(@class, 'tabbody__button-delete')]"));
		waitForPageData();
	}

	public void clickDetailConfirmDelete() {
		click(By.cssSelector("div[id $= 'dialogConfirmacaoExclusaoDetalhe'] .btn-success "));
		waitForPageData();
	}

	public void clickDivDataDetailTab(int detailNumber) {
		click(By.xpath("//div[@class='tabs']/ul[1]/li[" + detailNumber + "]/a[1]"));
		waitForAjaxProcess();
	}

	public void clickDivDataDetailTabActionInsert(int detailNumber) {
		click(By.xpath("//div[@class='tabs']/ul[1]/li[" + detailNumber + "]/a[1]//input[2]"));
		waitForOpenDivDetail();
	}

	public void clickDivDataDetailTabDetailActionClone(int detailNumber) {
		click(By.xpath("//button[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_button')]"));
		click(By.xpath("//div[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_menu')]/ul[1]/li[1]/a[1]"));
		waitForOpenDivDetail();
	}

	public void clickDivDataDetailTabDetailActionChange(int detailNumber) {
		click(By.xpath("//button[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_button')]"));
		click(By.xpath("//div[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_menu')]/ul[1]/li[2]/a[1]"));
		waitForOpenDivDetail();
	}

	public void clickDivDataDetailTabDetailActionConsult(int detailNumber) {
		click(By.xpath("//button[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_button')]"));
		click(By.xpath("//div[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_menu')]/ul[1]/li[3]/a[1]"));
		waitForOpenDivDetail();
	}

	public void clickDivDataDetailTabDetailActionDelete(int detailNumber) {
		click(By.xpath("//button[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_button')]"));
		click(By.xpath("//div[contains(@id, 'dataTableDetail:" + (detailNumber - 1) + ":mb_menu')]/ul[1]/li[4]/a[1]"));
		waitForOpenDivDetail();
	}


	public void clickDivDataDetailTabDetailSave(int detailNumber) {
		String index = CharacterUtils.alignTextRigth("" + detailNumber, 2, "0");
		click(By.xpath("//div[contains(@id, 'divTabDet" + index + "Data')]/div[1]/div[1]/div[1]/span[1]/a[contains(@class, 'paneldatadetailtab__button-save')]"));
		waitForCloseDivDetail();
	}


	public void clickDivDataDetailTabDetailReturn(int detailNumber) {
		String index = CharacterUtils.alignTextRigth("" + detailNumber, 2, "0");
		click(By.xpath("//div[contains(@id, 'divTabDet" + index + "panelDetail')]/div[1]/div[1]/span[1]/button[contains(@class, 'paneldatadetailtab__button-delete')]"));
		waitForCloseDivDetail();
	}

	public void clickDivDataDetailTabDetailDelete(int detailNumber) {
		String index = CharacterUtils.alignTextRigth("" + detailNumber, 2, "0");
		click(By.xpath("//div[contains(@id, 'divTabDet" + index + "panelDetail')]/div[1]/div[1]/span[1]/button[contains(@class, 'paneldatadetailtab__button-delete')]"));
	}

	public void clickDivDataDetailTabDetailConfirmDelete() {
		click(By.xpath("//div[contains(@id, 'dialogConfirmacaoExclusaoDetalhe')]/div[1]/div[2]/div[1]/table[1]/tbody[1]/tr[1]/td[2]/a[1]"));
		waitForCloseDivDetail();
	}

	public void clickSelect(String idComponent, String partialDescription) {
		click(By.cssSelector("div.ui-selectonemenu > label[id *= '" + idComponent + "']"));
		pauseSeconds(1);
		WebElement webElement = findElement(By.cssSelector("div[style *= 'display: block'] > div > ul > li[data-label *= '" + partialDescription + "']"));
		click(webElement);
		pauseSeconds(1);
	}

	public void clickSelect(WebElement element, String partialDescription) {
		click(element);
		pauseSeconds(1);
		WebElement webElement = findElement(By.cssSelector("div[style *= 'display: block'] > div > ul > li[data-label *= '" + partialDescription + "']"));
		click(webElement);
		pauseSeconds(1);
	}

	public void clickSelect(By selector, String partialDescription) {
		click(selector);
		pauseSeconds(1);
		WebElement webElement = findElement(By.cssSelector("div[style *= 'display: block'] > div > ul > li[data-label *= '" + partialDescription + "']"));
		click(webElement);
		pauseSeconds(1);
	}

	public void clickSelect(String idComponent, int item) {
		WebElement webElement = findElement(By.xpath("//div[contains(@id, '" + idComponent + "')]"));
		clickSelect(webElement, item);
	}

	public void clickSelect(By by, int item) {
		WebElement webElement = findElement(by);
		clickSelect(webElement, item);
	}

	public void clickSelect(WebElement webElement, int item) {
		click(webElement);

		Actions actions = new Actions(driver);
		actions.moveToElement(webElement);
		waitForAjaxProcess();

		for (int i = 0; i < 100; i++) {
			actions.sendKeys(Keys.ARROW_UP);
		}

		for (int i = 0; i < item; i++) {
			actions.sendKeys(Keys.ARROW_DOWN);
		}

		waitForAjaxProcess();
		actions.sendKeys(Keys.ENTER);
		waitForAjaxProcess();
		actions.perform();
		waitForAjaxProcess();
	}

	public void clickSelectAliasW(String idComponent, int item) {
		click(By.cssSelector("label[id*='" + idComponent + ":idSelectOneMenu_label']"));
		click(By.cssSelector("li[id*='" + idComponent + ":idSelectOneMenu_" + item + "']"));
	}

	public void clickButtonOkMessageProcess() {
		click(By.cssSelector(".swal-button--confirm"));
	}

	public void goPageListAndFilter(By byFilter, String valueFilter) {
		goPageList();
		goPageListAndFilter(findElement(byFilter), valueFilter);
	}

	public void goPageListAndFilter(WebElement elementFilter, String valueFilter) {
		goPageList();

		if (!elementFilter.getAttribute("value").equals(valueFilter)) {
			clickClearSendKeys(elementFilter, valueFilter);
			clickListSearch();
		}
	}

	public void goDeleteDataInsertAndDataChange(WebElement webElementFilterSearch, FieldType fieldType) {
		goDeleteDataInsertAndDataChange(webElementFilterSearch, fieldType, false);
	}

	public void goDeleteDataInsertAndDataChange(WebElement webElementFilterSearch, String keyInsert, String keyChange) {
		goDeleteDataInsertAndDataChange(webElementFilterSearch, keyInsert, keyChange, false);
	}

	public void goDeleteDataInsertAndDataChange(WebElement webElementFilterSearch, FieldType fieldType, boolean scrollButtonDelete) {
		goDeleteDataInsertAndDataChange(webElementFilterSearch, fieldType.getValueInsertTest(), fieldType.getValueChangeTest(), scrollButtonDelete);
	}

	public void goDeleteDataInsertAndDataChange(WebElement webElementFilterSearch, String keyInsert, String keyChange, boolean scrollButtonDelete) {
		goPageListAndFilter(webElementFilterSearch, keyInsert);
		clickListActionDelete();

		if (scrollButtonDelete) {
			scrollToMasterDelete();
		}

		clickMasterDelete();
		clickMasterConfirmDelete();

		waitForMessageSuccess();
		goPageListAndFilter(webElementFilterSearch, keyChange);
		clickListActionDelete();

		if (scrollButtonDelete) {
			scrollToMasterDelete();
		}

		clickMasterDelete();
		clickMasterConfirmDelete();
		waitForMessageSuccess();
	}

	public boolean isExists(By by) {
		return !driver.findElements(by).isEmpty();
	}

	public void tab(WebElement webElement) {
		click(webElement);
		webElement.sendKeys(Keys.TAB);
//		Actions actions = new Actions(driver);
//		actions.moveToElement(webElement);
//		actions.sendKeys(Keys.TAB);
//		actions.perform();
	}

	public void clickExecuteTask(int tab) {
		waitForMessageProcess();
		click(By.cssSelector("#tab-" + tab + " .listtask__button-execute"));
		waitForMessageProcess();
	}

	public void enter() {
		Actions actions = new Actions(driver);
		actions.sendKeys(Keys.ENTER);
	}

	public void fileUploadDocxFake(By by) {
		fileUploadFake(findElement(by), ".docx");
	}

	public void fileUploadPdfFake(WebElement webElement) {
		fileUploadFake(webElement, ".pdf");
		waitForAjaxProcess();
	}

	public void fileUploadPdfFake(By by) {
		fileUploadFake(findElement(by), ".pdf");
		waitForAjaxProcess();
	}

	public void fileUploadFake(WebElement inputUploadElement, String extension) {
		try {
			File arquivoTemp = File.createTempFile("WORDFAKE", extension);
			FileUtils.save(arquivoTemp, "DOCUMENTO FAKE COM EXTENSAO WORD");
			inputUploadElement.sendKeys(arquivoTemp.getAbsolutePath());
			arquivoTemp.deleteOnExit();
			SleepUtils.pauseSeconds(1);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void clickLookupWithFirstSearchFieldInputAndSelectItemResult(String lookup, String value, int item){
		clickOpenLookup(lookup);
		clickLookupFirstSearchFieldInputClearSendKeys(lookup, value);
		clickLookupSearch(lookup);
		clickLookupSelectItem(lookup, item);
	}

	public void clickOpenLookup(String lookup){
		click(By.cssSelector("a[id*='" + lookup +":commandLinkSearch']"));
		waitForAjaxProcess();
	}

	public void clickLookupFirstSearchFieldInputClearSendKeys(String lookup, String value){
		clickClearSendKeys(By.cssSelector("div[id*='" + lookup + "'] table[id*='" + lookup + "'] td.filtersearch__panelgrid-value input.filtersearch__inputtext"), value);
//		clickClearSendKeys(By.cssSelector("div[id*='" + lookup + "'] table[id*='" + lookup + "'] td.filtersearch__panelgrid-value *[class*='filtersearch__']"), value);
		waitForAjaxProcess();
	}

	public void clickLookupSearch(String lookup){
		click(By.cssSelector("div[id*='" + lookup +"'] a.filtersearch__button-search"));
		waitForAjaxProcess();
	}

	public void clickLookupSelectItem(String lookup, int item){
		click(By.cssSelector("div[id*='" + lookup +"'] a[id*='" + item + ":commandLinkSelecionalineTableLookupExtension']"));
		waitForAjaxProcess();
	}

	public void clickDialogSelectSelectAll(String lookup){
		click(By.cssSelector("div[id*='" + lookup +"'] div.dialogselect-datatable th.ui-selection-column div.ui-chkbox"));
		waitForAjaxProcess();
	}

	public void clickDialogSelectSelectItem(String lookup, int item){
		click(By.cssSelector("div[id*='" + lookup +"'] div.dialogselect-datatable tr[data-ri='" + item + "'] td.ui-column-unselectable div.ui-chkbox"));
		waitForAjaxProcess();
	}

	public void clickDialogSelectConfirm(String lookup){
		click(By.cssSelector("div[id*='" + lookup +"'] button[id*='" + lookup + ":btnEnviarSelecionados']"));
		waitForAjaxProcess();
	}

	public void clickDialogSelectWithFirstSearchFieldInputAndSelectFirstItemResult(String lookup, String value, int item){
		clickLookupFirstSearchFieldInputClearSendKeys(lookup, value);
		clickLookupSearch(lookup);
		clickDialogSelectSelectItem(lookup, item);
		clickDialogSelectConfirm(lookup);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy