Jacobvu84 / serenity-screenplay-junit-webdriver

Quản lý giáo trình cho khoá học
0 stars 2 forks source link

Swipe #29

Open Jacobvu84 opened 5 years ago

Jacobvu84 commented 5 years ago
package com.asksqa.interactions;

import static net.serenitybdd.screenplay.Tasks.instrumented;

import net.serenitybdd.core.pages.WebElementFacade;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.targets.Target;

public class Swipe {

    public enum Direction {
        DOWN, UP, LEFT, RIGHT;

        @Override
        public String toString() {
            return super.toString().toLowerCase();
        }
    }

    public static Performable with(Direction direction) {
        switch (direction) {
            case RIGHT:
                return instrumented(SwipeRight.class);
            case LEFT:
                return instrumented(SwipeLeft.class);
            case UP:
                return instrumented(SwipeUp.class);
            case DOWN:
                return instrumented(SwipeDown.class);
            default:
                throw new UnsupportedOperationException("Unsupported the direction " + direction);
        }
    }
}
Jacobvu84 commented 5 years ago

down

package com.asksqa.interactions;

import java.time.Duration;

import org.openqa.selenium.Dimension;

import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Interaction;
import net.thucydides.core.annotations.Step;

public class SwipeDown extends AppiumObject implements Interaction {

    @Override
    @Step("{0} swipes down screen")
    public <T extends Actor> void performAs(T actor) {

        Dimension size = getScreenSize(actor);

        int startY = (int) (size.getHeight() * 0.50);
        int endY = (int) (size.getHeight() * 0.20);
        int startX = size.getWidth() / 2;

        withAction(actor).press(PointOption.point(startX, startY))
                .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2)))
                .moveTo(PointOption.point(startX, endY))
                .release().perform();

    }

}
Jacobvu84 commented 5 years ago

left

        int startY = (int) (size.getHeight() / 2.0);
        int startX = (int) (size.getWidth() * 0.90);
        int endX = (int) (size.getWidth() * 0.05);

        withAction(actor).longPress(PointOption.point(startX, startY))
                .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2)))
                .moveTo(PointOption.point(endX, startY))
                .release().perform();
Jacobvu84 commented 5 years ago

right

        int startY = (int) (size.getHeight() / 2.0);
        int startX = (int) (size.getWidth() * 0.05);
        int endX = (int) (size.getWidth() * 0.90);

        withAction(actor)
                .longPress(PointOption.point(startX, startY))
                .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2)))
                .moveTo(PointOption.point(endX, startY))
                .release().perform();
Jacobvu84 commented 5 years ago

up

        int startY = (int) (size.getHeight() * 0.50);
        int endY = (int) (size.getHeight() * 0.20);
        int startX = size.getWidth() / 2;

        withAction(actor).press(PointOption.point(startX, endY))
                .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2)))
                .moveTo(PointOption.point(startX, startY))
                .release().perform();