package cz.moneta.test.dsl.ib;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ib.authentication.LoginPage;
import cz.moneta.test.harness.endpoints.ib.IbEndpoint;
import cz.moneta.test.harness.support.web.Builders;

public class Ib {

    private final Harness harness;
    private IbEndpoint ibEndpoint;

    public Ib(Harness harness) {
        this.harness = harness;
    }

    public LoginPage openLoginPage() {
        ibEndpoint = harness.getEndpoint(IbEndpoint.class);
        ibEndpoint.openApplication();

        // Login page is frame based, frames are added by javascript. Yeah, life is a hassle, I know
        ibEndpoint.switchToFrame("//frameset/frame[2]");

        return Builders.newWebFlowBuilder(LoginPage.class, ibEndpoint, harness);
    }

    public void closeApplication() {
        harness.closeEndpoint(harness.getEndpoint(IbEndpoint.class));
    }
}
