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

import com.mavlushechka.a1qa.driverUtils.ActionUtils;
import com.mavlushechka.a1qa.utils.DoubleUtils;
import com.mavlushechka.a1qa.utils.LoggerUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;

public class Slider extends BaseElement {

    public Slider(By locator, String name) {
        super(locator, name);
    }

    public void slideTo(int percentage) {
        WebElement slider = findElement();
        Point currentPoint = new Point((int) Math.round(DoubleUtils.getPercentageOf(slider.getSize().getWidth(), getValue())-getDimension().width/2.0), 0);
        Point expectedPoint = new Point((int) Math.round(DoubleUtils.getPercentageOf(slider.getSize().getWidth(), percentage)-getDimension().width/2.0), 0);

        LoggerUtils.info("Sliding on the \"" + getName() + "\" element.");
        ActionUtils.dragAndDrop(slider, currentPoint, expectedPoint);
    }

    public int getValue() {
        return Integer.parseInt(findElement().getAttribute("value"));
    }

}