return Assertions.fail() in catch block of custom waiters method

This commit is contained in:
Seraphym-Tuhai 2023-03-14 12:20:18 +02:00
parent 16061ec4fc
commit 12041ee6e2

View File

@ -16,7 +16,6 @@
package org.thingsboard.server.msa.ui.base; package org.thingsboard.server.msa.ui.base;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
@ -34,7 +33,8 @@ import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Slf4j import static org.junit.jupiter.api.Assertions.fail;
abstract public class AbstractBasePage { abstract public class AbstractBasePage {
public static final long WAIT_TIMEOUT = TimeUnit.SECONDS.toMillis(30); public static final long WAIT_TIMEOUT = TimeUnit.SECONDS.toMillis(30);
protected WebDriver driver; protected WebDriver driver;
@ -59,8 +59,7 @@ abstract public class AbstractBasePage {
try { try {
return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator))); return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)));
} catch (WebDriverException e) { } catch (WebDriverException e) {
log.error("No visibility element: " + locator); return fail("No visibility element: " + locator);
return null;
} }
} }
@ -68,8 +67,7 @@ abstract public class AbstractBasePage {
try { try {
return wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(locator))); return wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(locator)));
} catch (WebDriverException e) { } catch (WebDriverException e) {
log.error("No presence element: " + locator); return fail("No presence element: " + locator);
return null;
} }
} }
@ -77,8 +75,7 @@ abstract public class AbstractBasePage {
try { try {
return wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))); return wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator)));
} catch (WebDriverException e) { } catch (WebDriverException e) {
log.error("No clickable element: " + locator); return fail("No clickable element: " + locator);
return null;
} }
} }
@ -87,8 +84,7 @@ abstract public class AbstractBasePage {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator))); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)));
return driver.findElements(By.xpath(locator)); return driver.findElements(By.xpath(locator));
} catch (WebDriverException e) { } catch (WebDriverException e) {
log.error("No visibility elements: " + locator); return fail("No visibility elements: " + locator);
return null;
} }
} }
@ -97,8 +93,7 @@ abstract public class AbstractBasePage {
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))); wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator)));
return driver.findElements(By.xpath(locator)); return driver.findElements(By.xpath(locator));
} catch (WebDriverException e) { } catch (WebDriverException e) {
log.error("No clickable elements: " + locator); return fail("No clickable elements: " + locator);
return null;
} }
} }
@ -106,7 +101,7 @@ abstract public class AbstractBasePage {
try { try {
wait.until(ExpectedConditions.urlContains(urlPath)); wait.until(ExpectedConditions.urlContains(urlPath));
} catch (WebDriverException e) { } catch (WebDriverException e) {
log.error("This URL path is missing"); fail("This URL path is missing");
} }
} }
@ -122,7 +117,7 @@ abstract public class AbstractBasePage {
try { try {
return wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)))); return wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator))));
} catch (WebDriverException e) { } catch (WebDriverException e) {
throw new AssertionError("Element is present"); return fail("Element is present");
} }
} }
@ -130,7 +125,7 @@ abstract public class AbstractBasePage {
try { try {
return wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(locator)))); return wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(locator))));
} catch (WebDriverException e) { } catch (WebDriverException e) {
throw new AssertionError("Elements is present"); return fail("Elements is present");
} }
} }
@ -138,7 +133,7 @@ abstract public class AbstractBasePage {
try { try {
wait.until(ExpectedConditions.numberOfWindowsToBe(tabNumber)); wait.until(ExpectedConditions.numberOfWindowsToBe(tabNumber));
} catch (WebDriverException e) { } catch (WebDriverException e) {
log.error("No tabs with this number"); fail("No tabs with this number: " + tabNumber);
} }
} }