blob: a90205d269d4f6dca7ffc75231bc28583f48e904 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package com.mavlushechka.a1qa.elements;
import com.mavlushechka.a1qa.driverUtils.ActionUtils;
import com.mavlushechka.a1qa.driverUtils.WebDriverUtils;
import com.mavlushechka.a1qa.driverUtils.WebDriverWaitFactory;
import com.mavlushechka.a1qa.utils.LoggerUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import java.util.List;
public abstract class BaseElement {
private final By locator;
private final String name;
public BaseElement(By locator, String name) {
this.locator = locator;
this.name = name;
}
public void click() {
WebElement webElement = findElement();
scrollTo();
LoggerUtils.info("Clicking on the \"" + name + "\" element.");
webElement.click();
}
public String getText() {
WebElement webElement = findElement();
LoggerUtils.info("Getting text of the \"" + name + "\" element.");
return webElement.getText();
}
public boolean isEnabled() {
WebElement webElement = findElement();
LoggerUtils.info("Getting state of the \"" + name + "\" element.");
return webElement.isEnabled();
}
public boolean isVisible() {
LoggerUtils.info("Getting visibility of the \"" + name + "\" element.");
return WebDriverWaitFactory.createWebDriverWait().until(ExpectedConditions.visibilityOfElementLocated(locator)).isDisplayed();
}
public boolean isInvisible() {
LoggerUtils.info("Getting invisibility of the \"" + name + "\" element.");
return WebDriverWaitFactory.createWebDriverWait().until(ExpectedConditions.invisibilityOfElementLocated(locator));
}
public boolean isAny() {
List<WebElement> webElements = findElements();
LoggerUtils.info("Getting any \"" + name + "\" elements.");
return webElements.size() > 0;
}
public String getName() {
return name;
}
public Dimension getDimension() {
WebElement webElement = findElement();
LoggerUtils.info("Getting dimension of the \"" + name + "\" element.");
return webElement.getSize();
}
public String getAttributeValue(String attribute) {
WebElement webElement = findElement();
LoggerUtils.info("Getting \"" + attribute + "\" attribute of the \"" + name + "\" element.");
return webElement.getAttribute(attribute);
}
protected WebElement findElement() {
isVisible();
LoggerUtils.info("Finding the \"" + name + "\" element.");
return WebDriverUtils.findElement(locator);
}
protected List<WebElement> findElements() {
LoggerUtils.info("Finding the \"" + name + "\" elements.");
return WebDriverUtils.findElements(locator);
}
protected void scrollTo() {
WebElement webElement = findElement();
LoggerUtils.info("Scrolling to the \"" + name + "\" element.");
ActionUtils.scrollTo(webElement);
}
}
|