All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.siwenyan.si.SiCommandExecutorSetWindowSize Maven / Gradle / Ivy

There is a newer version: 1.25.1.0
Show newest version
package com.github.siwenyan.si;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriverException;

class SiCommandExecutorSetWindowSize extends SiCommandExecutor implements ISiCommandExecutorFlagUi {

    @Override
    public void execute(SiCommand command, SiContext siContext) throws SiVerifyException, SiWebDriverException {
        String sSize = command.getSiModelCommand().getTarget();
        String[] p = sSize.split("x", 2);
        int width = Integer.parseInt(p[0]);
        int height = Integer.parseInt(p[1]);

        try {
            siContext.asWebDriver().manage().window().setSize(new Dimension(width, height));
        } catch (WebDriverException e) {
            String message = e.getMessage();
            if (message.startsWith("setWindowRect")) {
                siContext.getReporter().reportMessage("Using javascript...");
                siContext.asJavascriptExecutor().executeScript("window.resizeTo(" + width + ", " + height + ")");
            } else {
                throw e;
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy