Example usage for org.openqa.selenium Point Point

List of usage examples for org.openqa.selenium Point Point

Introduction

In this page you can find the example usage for org.openqa.selenium Point Point.

Prototype

public Point(int x, int y) 

Source Link

Usage

From source file:minium.web.config.WebDriverFactory.java

License:Apache License

public WebDriver create(WebDriverProperties webDriverProperties) {
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities(
            webDriverProperties.getDesiredCapabilities());
    DesiredCapabilities requiredCapabilities = new DesiredCapabilities(
            webDriverProperties.getRequiredCapabilities());
    WebDriver webDriver = null;/*from w w  w . j  a  v  a  2s. c o  m*/
    if (webDriverProperties.getUrl() != null) {
        RemoteWebDriver remoteDriver = new RemoteWebDriver(webDriverProperties.getUrl(), desiredCapabilities,
                requiredCapabilities);
        remoteDriver.setFileDetector(new LocalFileDetector());
        webDriver = remoteDriver;
    } else {
        String browserName = desiredCapabilities == null ? null : desiredCapabilities.getBrowserName();
        if (Strings.isNullOrEmpty(browserName))
            browserName = BrowserType.CHROME;
        webDriver = WebDriverType.typeFor(browserName).create(this, desiredCapabilities, requiredCapabilities);
    }
    WindowProperties window = webDriverProperties.getWindow();
    if (window != null) {
        DimensionProperties size = window.getSize();
        PointProperties position = window.getPosition();
        if (size != null)
            webDriver.manage().window().setSize(new Dimension(size.getWidth(), size.getHeight()));
        if (position != null)
            webDriver.manage().window().setPosition(new Point(position.getX(), position.getY()));
        if (window.isMaximized()) {
            webDriver.manage().window().maximize();
        }
    }
    return webDriver instanceof TakesScreenshot ? webDriver : new Augmenter().augment(webDriver);
}

From source file:org.apache.atlas.objectwrapper.WebDriverWrapper.java

License:Apache License

private static WebDriver appConfig(XmlTest config) {
    //      AtlasConstants.UI_URL = config.getParameter("app_url");
    String serverIP = config.getParameter("server_ip");
    String serverPort = config.getParameter("server_port");
    String browserName = config.getParameter("browserName");
    int browserHeight = Integer.parseInt(config.getParameter("browser_window_height"));
    int browserWidth = Integer.parseInt(config.getParameter("browser_window_width"));
    DesiredCapabilities capabilities = null;

    if (browserName.contains("firefox")) {
        capabilities = DesiredCapabilities.firefox();
        capabilities.setPlatform(Platform.ANY);
        webDriver = new FirefoxDriver(capabilities);
    } else if (browserName.contains("chrome") || browserName.equalsIgnoreCase("chrome")) {

        LOGGER.info("Configuring settings for Chrome");
        // Google Chrome Driver
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-web-security");
        options.addArguments("--start-maximized");

        // For use with RemoteWebDriver:
        capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        webDriver = new ChromeDriver(capabilities);
    }//w  w  w .jav  a2s.  c o  m
    AtlasConstants.UI_URL = "http://" + serverIP + ":" + serverPort;
    webDriver.manage().window().setPosition(new Point(0, 0));
    Dimension dimenssion = new Dimension(browserHeight, browserWidth);
    webDriver.manage().window().setSize(dimenssion);
    return webDriver;
}

From source file:org.apache.falcon.regression.testHelper.BaseUITestClass.java

License:Apache License

protected static void openBrowser() {

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.negotiate-auth.trusted-uris", MerlinConstants.PRISM_URL);

    driver = new FirefoxDriver(profile);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    int width = Config.getInt("browser.window.width", 0);
    int height = Config.getInt("browser.window.height", 0);

    if (width * height == 0) {
        driver.manage().window().maximize();
    } else {//  w  ww .  j  a va 2 s . c o m
        driver.manage().window().setPosition(new Point(0, 0));
        driver.manage().window().setSize(new Dimension(width, height));
    }

}

From source file:org.apache.falcon.regression.ui.pages.ProcessPage.java

License:Apache License

/**
 * Finds vertex on the graph by its name and evaluates its coordinates as 2d point.
 * @param vertex the name of vertex which point is needed
 * @return Point(x,y) object//from w w w. j  av a 2 s.c  o m
 */
public Point getVertexEndpoint(String vertex) {
    /** get circle of start vertex */
    LOGGER.info("Getting vertex coordinates...");
    WebElement block = driver.findElement(By.xpath(String.format(VERTEX_BLOCK_TEMPLATE, vertex)));
    String attribute = block.getAttribute("transform");
    attribute = attribute.replaceAll("[a-zA-Z]", "");
    String[] numbers = attribute.replaceAll("[()]", "").split(",");
    return new Point(Integer.parseInt(numbers[0]), Integer.parseInt(numbers[1]));
}

From source file:org.beangle.test.selenium.SeleniumTestBootstrap.java

License:Open Source License

@BeforeSuite(groups = "webdriver.start")
@Parameters({ "selenium.url", "selenium.browser", "selenium.timeout" })
public void beforeSuite(@Optional("http://localhost") String baseUrl,
        @Optional("*firefox") String browserString, @Optional("30000") String maxTimeout) throws Exception {
    seleniumDriver = null;//from   w w  w  .  j a v  a  2 s  .  c o m
    if (StringUtils.contains(browserString, "firefox")) {
        seleniumDriver = new FirefoxDriver();
    } else if (StringUtils.contains(browserString, "chrome")) {
        seleniumDriver = new ChromeDriver();
    } else if (StringUtils.contains(browserString, "ie")) {
        seleniumDriver = new InternetExplorerDriver();
    } else {
        seleniumDriver = new HtmlUnitDriver(true);
    }

    seleniumDriver.manage().deleteAllCookies();
    seleniumDriver.manage().window().setPosition(new Point(0, 0));
    // maximize browser size
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    seleniumDriver.manage().window()
            .setSize(new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight()));
    selenium = new WebDriverBackedSelenium(seleniumDriver, baseUrl);
    PAGE_LOAD_TIMEOUT = maxTimeout;
}

From source file:org.cerberus.engine.execution.impl.SeleniumServerService.java

License:Open Source License

private void setScreenSize(WebDriver driver, Integer width, Integer length) {
    driver.manage().window().setPosition(new Point(0, 0));
    driver.manage().window().setSize(new Dimension(width, length));
}

From source file:org.finra.jtaf.ewd.impl.DefaultSessionFactory.java

License:Apache License

@Override
public WebDriver createInnerDriver(Map<String, String> options, DesiredCapabilities capabilities)
        throws Exception {
    ClientProperties properties = new ClientProperties(options.get("client"));

    WebDriver wd = null;//from  ww  w.  j a  v a2 s .com
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities(capabilities);
    String browser = properties.getBrowser();

    if (properties.isUseGrid()) {
        RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(properties.getGridUrl()), capabilities);
        remoteWebDriver.setFileDetector(new LocalFileDetector());
        wd = remoteWebDriver;
    } else {
        if (browser == null || browser.equals("")) {
            throw new RuntimeException(
                    "Browser cannot be null. Please set 'browser' in client properties. Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit.");
        } else if (browser.equalsIgnoreCase("ie") || browser.equalsIgnoreCase("iexplore")
                || browser.equalsIgnoreCase("*iexplore")) {
            String webdriverIEDriver = properties.getWebDriverIEDriver();

            if (webdriverIEDriver != null) {
                System.setProperty("webdriver.ie.driver", webdriverIEDriver);
            }

            String browserVersion = properties.getBrowserVersion();

            if (browserVersion == null || browserVersion.equals("")) {
                throw new RuntimeException(
                        "When using IE as the browser, please set 'browser.version' in client properties");
            } else {
                if (browserVersion.startsWith("9")) {
                    desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                    desiredCapabilities.setCapability(
                            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                    wd = new InternetExplorerDriver(desiredCapabilities);
                } else {
                    wd = new InternetExplorerDriver(desiredCapabilities);
                }
            }
        } else if ((browser.equalsIgnoreCase("firefox") || browser.equalsIgnoreCase("*firefox"))) {
            final String ffProfileFolder = properties.getFirefoxProfileFolder();
            final String ffProfileFile = properties.getFirefoxProfileFile();
            final String path = properties.getBinaryPath();

            if (path != null) {
                FirefoxBinary fireFox = getFFBinary(path);
                FirefoxProfile ffp = null;

                if (ffProfileFolder != null) {
                    ffp = new FirefoxProfile(new File(ffProfileFolder));
                } else {
                    ffp = new FirefoxProfile();
                }

                if (ffProfileFile != null) {
                    addPreferences(ffp, ffProfileFile);
                }

                addPreferences(ffp);

                List<String> ffExtensions = properties.getFirefoxExtensions();
                if (ffExtensions != null && ffExtensions.size() > 0) {
                    addExtensionsToFirefoxProfile(ffp, ffExtensions);
                }

                wd = new FirefoxDriver(fireFox, ffp, desiredCapabilities);
            } else {
                wd = new FirefoxDriver(desiredCapabilities);
            }
        } else if (browser.equalsIgnoreCase("chrome")) {

            String webdriverChromeDriver = properties.getWebDriverChromeDriver();

            if (webdriverChromeDriver != null) {
                System.setProperty("webdriver.chrome.driver", webdriverChromeDriver);
            }

            wd = new ChromeDriver(desiredCapabilities);
        } else if (browser.equalsIgnoreCase("safari")) {
            wd = new SafariDriver(desiredCapabilities);
        } else if (browser.equalsIgnoreCase("htmlunit")) {
            wd = new HtmlUnitDriver(desiredCapabilities);
            ((HtmlUnitDriver) wd).setJavascriptEnabled(true);
        } else {
            throw new Exception("Unsupported browser type: " + browser
                    + ". Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit.");
        }

        // move browser windows to specific position. It's useful for
        // debugging...
        final int browserInitPositionX = properties.getBrowserInitPositionX();
        final int browserInitPositionY = properties.getBrowserInitPositionY();
        if (browserInitPositionX != 0 || browserInitPositionY != 0) {
            wd.manage().window().setSize(new Dimension(1280, 1024));
            wd.manage().window().setPosition(new Point(browserInitPositionX, browserInitPositionY));
        }
    }

    return wd;
}

From source file:org.gradle.needle.selenium.CaptureScreenshot.java

License:Apache License

public static String screenShot(BrowserFactory bf) {
    String dir = "screenshot"; // TODO
    String time = new SimpleDateFormat("yyyyMMdd-HH:mm:ss").format(new Date());
    String screenShotPath = dir + File.separator + time + ".png";
    WebDriver augmentedDriver = null;//w w w  .java2  s. c o  m
    if (GlobalSettings.browserCoreType == 1 || GlobalSettings.browserCoreType == 3) {
        augmentedDriver = bf.getBrowserCore();
        augmentedDriver.manage().window().setPosition(new Point(0, 0));
        augmentedDriver.manage().window().setSize(new Dimension(9999, 9999));
    } else if (GlobalSettings.browserCoreType == 2) {
        augmentedDriver = new Augmenter().augment(bf.getBrowserCore());
    } else {
        return "";
    }

    try {
        File sourceFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(sourceFile, new File(screenShotPath));

    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }

    return screenShotPath.replace("\\", "/");
}

From source file:org.kurento.room.test.RoomTest.java

License:Open Source License

protected List<WebDriver> createBrowsers(int numUsers)
        throws InterruptedException, ExecutionException, TimeoutException {

    final List<WebDriver> browsers = Collections.synchronizedList(new ArrayList<WebDriver>());

    parallelBrowserInit(numUsers, 0, browsers);

    if (browsers.size() < numUsers) {
        int required = numUsers - browsers.size();
        log.warn("Not enough browsers were created, will retry to " + "recreate the missing ones: {}",
                required);/* www  . j av a 2  s  .  c o m*/
        parallelBrowserInit(required, browsers.size(), browsers);
    }

    if (browsers.size() < numUsers)
        fail("Unable to create the required number of browsers: " + numUsers);

    int row = 0;
    int col = 0;
    for (WebDriver browser : browsers) {

        browser.manage().window().setSize(new Dimension(BROWSER_WIDTH, BROWSER_HEIGHT));
        browser.manage().window().setPosition(
                new Point(col * BROWSER_WIDTH + LEFT_BAR_WIDTH, row * BROWSER_HEIGHT + TOP_BAR_WIDTH));
        col++;
        if (col * BROWSER_WIDTH + LEFT_BAR_WIDTH > MAX_WIDTH) {
            col = 0;
            row++;
        }
    }

    browsersClosed = false;
    return browsers;
}

From source file:org.oneandone.qxwebdriver.ui.mobile.core.WidgetImpl.java

License:LGPL

protected static Point getCenter(WebElement element) {
    Dimension size = element.getSize();
    int halfWidth = size.getWidth() / 2;
    int halfHeight = size.getHeight() / 2;

    Point loc = element.getLocation();
    int posX = loc.getX() + halfWidth;
    int posY = loc.getY() + halfHeight;

    Point point = new Point(posX, posY);
    return point;
}