hw4: finalize selenoid and ansible workflow with citrus tests
This commit is contained in:
@@ -4,6 +4,7 @@ import com.google.inject.Inject;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.ElementClickInterceptedException;
|
||||
import org.openqa.selenium.JavascriptExecutor;
|
||||
import org.openqa.selenium.NoSuchElementException;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
@@ -20,7 +21,8 @@ public class MainPage {
|
||||
|
||||
private final WebDriver driver;
|
||||
|
||||
private final By menuLearning = By.cssSelector("span[title='Обучение']");
|
||||
private final By menuLearningByTitle = By.cssSelector("span[title='Обучение']");
|
||||
private final By menuLearningByText = By.xpath("//span[normalize-space()='Обучение']");
|
||||
private final By categories = By.cssSelector("a[href*='/categories/']");
|
||||
|
||||
@Inject
|
||||
@@ -36,17 +38,18 @@ public class MainPage {
|
||||
public String clickRandomCategory() {
|
||||
PageUtils.removeBottomBanner(driver);
|
||||
|
||||
final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
|
||||
final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
|
||||
|
||||
final WebElement menu = wait.until(drv -> drv.findElement(menuLearning));
|
||||
menu.click();
|
||||
|
||||
final List<WebElement> els = wait.until(drv -> {
|
||||
final List<WebElement> found = drv.findElements(categories).stream()
|
||||
.filter(WebElement::isDisplayed)
|
||||
.toList();
|
||||
return found.isEmpty() ? null : found;
|
||||
});
|
||||
List<WebElement> els = findVisibleCategories(wait);
|
||||
if (els.isEmpty()) {
|
||||
clickLearningMenu(wait);
|
||||
els = wait.until(drv -> {
|
||||
final List<WebElement> found = drv.findElements(categories).stream()
|
||||
.filter(WebElement::isDisplayed)
|
||||
.toList();
|
||||
return found.isEmpty() ? null : found;
|
||||
});
|
||||
}
|
||||
|
||||
final WebElement chosen = els.get(ThreadLocalRandom.current().nextInt(els.size()));
|
||||
final String href = chosen.getAttribute("href");
|
||||
@@ -68,4 +71,29 @@ public class MainPage {
|
||||
|
||||
return href;
|
||||
}
|
||||
|
||||
private List<WebElement> findVisibleCategories(WebDriverWait wait) {
|
||||
return wait.until(drv -> drv.findElements(categories).stream()
|
||||
.filter(WebElement::isDisplayed)
|
||||
.toList());
|
||||
}
|
||||
|
||||
private void clickLearningMenu(WebDriverWait wait) {
|
||||
WebElement menu = null;
|
||||
try {
|
||||
menu = wait.until(drv -> drv.findElement(menuLearningByTitle));
|
||||
} catch (NoSuchElementException ignored) {
|
||||
} catch (org.openqa.selenium.TimeoutException ignored) {
|
||||
}
|
||||
|
||||
if (menu == null) {
|
||||
menu = wait.until(drv -> drv.findElement(menuLearningByText));
|
||||
}
|
||||
|
||||
try {
|
||||
menu.click();
|
||||
} catch (ElementClickInterceptedException ignored) {
|
||||
((JavascriptExecutor) driver).executeScript("arguments[0].click();", menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user