Example usage for org.openqa.selenium.remote DriverCommand GET

List of usage examples for org.openqa.selenium.remote DriverCommand GET

Introduction

In this page you can find the example usage for org.openqa.selenium.remote DriverCommand GET.

Prototype

String GET

To view the source code for org.openqa.selenium.remote DriverCommand GET.

Click Source Link

Usage

From source file:com.smash.revolance.ui.materials.mock.webdriver.browser.MockedBrowserController.java

License:Open Source License

@Override
public synchronized void notify(JSonWireEvent event) {
    String name = (String) event.getProp("command.name");
    String path = (String) event.getProp("command.path");
    String elementId = (String) event.getProp("command.elementId");
    String htmlAttribute = (String) event.getProp("command.elementHtmlAttribute");
    String cssAttribute = (String) event.getProp("command.elementCssAttribute");

    System.out.println("Receiving command: " + name + " with path: " + path);

    Map<String, Object> commandPayload = (Map<String, Object>) event.getProp("command.payload");

    // Just the value part in the payload
    Map<String, Object> resultPayload = new HashMap<String, Object>();

    if (isCommand(event, DriverCommand.NEW_SESSION)) {
        browser = new MockedBrowser();

        resultPayload.put("browserName", this.getClass().getSimpleName());
        resultPayload.put("browserPlatform", OS.isFamilyUnix() ? "LINUX" : "WINDOWS");
        resultPayload.put("browserVersion", "0.0.1-SNAPSHOT");
    }/*from  www  . j  a v a 2  s  .  com*/
    if (isCommand(event, DriverCommand.SET_WINDOW_SIZE)) {
        browser.setSize((Integer) commandPayload.get("width"), (Integer) commandPayload.get("height"));
    }
    if (isCommand(event, DriverCommand.GET_WINDOW_SIZE)) {
        Dimension dim = browser.getDimension();
        resultPayload.put("width", dim.getWidth());
        resultPayload.put("height", dim.getHeight());
    }
    if (isCommand(event, DriverCommand.SET_WINDOW_POSITION)) {
        browser.setLocation((Integer) commandPayload.get("x"), (Integer) commandPayload.get("y"));
    }
    if (isCommand(event, DriverCommand.GET_WINDOW_POSITION)) {
        Point location = browser.getLocation();
        resultPayload.put("x", location.getX());
        resultPayload.put("y", location.getY());
    }
    if (isCommand(event, DriverCommand.GET_CURRENT_URL)) {
        resultPayload.put("url", browser.getUrl());
    }
    if (isCommand(event, DriverCommand.GET)) {
        try {
            browser.goToUrl((String) commandPayload.get("url"));
        } catch (Exception e) {
            System.err.println(e);
        }
    }
    if (isCommand(event, DriverCommand.EXECUTE_SCRIPT)) {
        resultPayload.put("value", browser.executeJavaScript((String) commandPayload.get("script"),
                (Object[]) commandPayload.get("args")));
    }
    if (isCommand(event, DriverCommand.GET_ALERT_TEXT)) {
        resultPayload.put("alertStatusCode", ErrorCodes.NO_ALERT_PRESENT);
        resultPayload.put("alertMessage", "No alert is present");
    }
    if (isCommand(event, DriverCommand.GET_TITLE)) {
        resultPayload.put("title", browser.getTitle());
    }
    if (isCommand(event, DriverCommand.SCREENSHOT)) {
        resultPayload.put("screenshot", browser.takeScreenshot());
    }
    if (isCommand(event, DriverCommand.FIND_ELEMENTS)) {
        List<String> elements = browser.findElements((String) commandPayload.get("value"));
        resultPayload.put("elementList", buildElementList(elements));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_LOCATION)) {
        Point location = browser.getElementLocation(elementId);

        resultPayload.put("elementX", String.valueOf(location.getX()));
        resultPayload.put("elementY", String.valueOf(location.getY()));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_SIZE)) {
        Dimension dim = browser.getElementSize(elementId);

        resultPayload.put("elementW", String.valueOf(dim.getWidth()));
        resultPayload.put("elementH", String.valueOf(dim.getHeight()));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_TAG_NAME)) {
        resultPayload.put("elementTagName", browser.getElementTag(elementId));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_TEXT)) {
        resultPayload.put("elementText", browser.getElementText(elementId));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_ATTRIBUTE)) {
        resultPayload.put("elementHtmlAttributeValue",
                browser.getElementHtmlAttribute(elementId, htmlAttribute));
    }
    if (isCommand(event, DriverCommand.IS_ELEMENT_DISPLAYED)) {
        resultPayload.put("isElementDisplayed", browser.isElementDisplayed(elementId));
    }
    if (isCommand(event, DriverCommand.GET_ELEMENT_VALUE_OF_CSS_PROPERTY)) {
        resultPayload.put("elementCssAttributeValue", browser.getElementCssAttribute(elementId, cssAttribute));
    }
    event.setProp("command.value", resultPayload);
    notifyAll();
}

From source file:com.smash.revolance.ui.materials.mock.webdriver.handler.JSonWireController.java

License:Open Source License

@POST
@Path("/session/{sessionId}/url")
@Produces(MediaType.APPLICATION_JSON)/*from  w  w w .ja v  a  2s .  co m*/
@Consumes(MediaType.APPLICATION_JSON)
public Response setCurrentUrl(@PathParam("sessionId") String sessionId, String payload) {
    Command cmd = new Command(sessionId, DriverCommand.GET, "POST", payload);
    CommandResult cmdResult = new CommandExecutor(cmd, getPath()).execute();
    return new CommandResponse(cmdResult).buildResponse();
}