Jacobvu84 / serenity-screenplay-junit-webdriver

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

Tap Factory #31

Open Jacobvu84 opened 5 years ago

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

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

import java.io.File;

import io.appium.java_client.touch.offset.PointOption;
import net.serenitybdd.screenplay.Interaction;
import net.serenitybdd.screenplay.targets.Target;

public class Tap {
    public static TapOnPoint on(PointOption point) {
        return instrumented(TapOnPoint.class, point);
    }

    public static TapOnImage on(File image) {
        return instrumented(TapOnImage.class, image);
    }

    public static Interaction outSide(Target target) {
        return instrumented(TapOutSide.class, target);
    }
}
Jacobvu84 commented 5 years ago
package com.asksqa.interactions;

import io.appium.java_client.touch.offset.PointOption;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Interaction;

public class TapOnPoint extends AppiumObject implements Interaction{

    private PointOption point;

    public TapOnPoint(PointOption point) {
        this.point = point;
    }

    @Override
    public <T extends Actor> void performAs(T actor) {
        withAction(actor).tap(point).perform();
    }
}

E.g: Tap.on(PointOption.point(200, 200))

Jacobvu84 commented 5 years ago

Tap outsides element


package com.asksqa.interactions;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Interaction;
import net.serenitybdd.screenplay.targets.Target;
import net.thucydides.core.annotations.Step;

import io.appium.java_client.touch.offset.PointOption;

public class TapOutSide extends AndroidObject implements Interaction {

    private static final Logger LOGGER = LoggerFactory.getLogger(TapOutSide.class);

    private Target target;

    public TapOutSide(Target target) {
        this.target = target;
    }

    @Override
    @Step("{0} taps outside the pop-up screen")
    public <T extends Actor> void performAs(T actor) {

        int x = target.resolveFor(actor).getRect().x;
        int y = target.resolveFor(actor).getRect().y;
        int h = target.resolveFor(actor).getRect().height;
        int w = target.resolveFor(actor).getRect().width;
        LOGGER.info("Tap at: (" + x +"," + y + ")");

        withAction(actor).tap(PointOption.point(x + w + 60, y + h + 100)).perform();
    }

    public static Interaction on(Target target) {
        return instrumented(TapOutSide.class, target);
    }

}

E.g Tap.outSide(POP_UP_CONTAINER)