summaryrefslogtreecommitdiff
path: root/src/main/java/com/mavlushechka/a1qa/elements/BaseElement.java
blob: edcf1e777ed034f5350cfe4341ea2a0efb647045 (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
package com.mavlushechka.a1qa.elements;

import com.mavlushechka.a1qa.driverUtils.WebDriverUtils;
import com.mavlushechka.a1qa.utils.LoggerUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;

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 webElement.isDisplayed();
    }

    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);
    }

}