blob: 8a7408d6445a3d77924d65d34ff1611c65a2fd9d (
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
|
package com.mavlushechka.a1qa.elements;
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;
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 = find();
LoggerUtils.info("Clicking on the \"" + name + "\" element.");
webElement.click();
}
public String getText() {
WebElement webElement = find();
LoggerUtils.info("Getting text of the \"" + name + "\" element.");
return webElement.getText();
}
public boolean isEnabled() {
WebElement webElement = find();
LoggerUtils.info("Getting state of the \"" + name + "\" element.");
return webElement.isEnabled();
}
public boolean isVisible() {
WebElement webElement = find();
LoggerUtils.info("Getting visibility of the \"" + name + "\" element.");
return WebDriverWaitFactory.createWebDriverWait().until(ExpectedConditions.visibilityOf(webElement)).isDisplayed();
}
public boolean isInvisible() {
WebElement webElement = find();
LoggerUtils.info("Getting invisibility of the \"" + name + "\" element.");
return WebDriverWaitFactory.createWebDriverWait().until(ExpectedConditions.invisibilityOf(webElement));
}
public String getName() {
return name;
}
public Dimension getDimension() {
WebElement webElement = find();
LoggerUtils.info("Getting dimension of the \"" + name + "\" element.");
return webElement.getSize();
}
public String getAttributeValue(String attribute) {
WebElement webElement = find();
LoggerUtils.info("Getting \"" + attribute + "\" attribute of the \"" + name + "\" element.");
return webElement.getAttribute(attribute);
}
protected WebElement find() {
LoggerUtils.info("Finding the \"" + name + "\" element.");
return WebDriverUtils.findElement(locator);
}
}
|