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:com.zaizi.automation.alfresco.F_Vanila_DocumentLibraryTest_Chrome.java

/**
* 
* @Test Delete the Document/* ww w . j a  v  a 2 s .  co  m*/
* @return
* 
* @throws Exception InterruptedException, IOException
*/

@Test
public void f_deleteDocument() throws InterruptedException, IOException {
    ExtentTest test = extent.startTest("f_deleteDocument",
            "Folder Creation and Validation as Admin in the Private Site");

    driver = TestCaseProperties.driverType("Chrome", "WINDOWS");

    //Set the upper left corner of the screen starting point
    driver.manage().window().setPosition(new Point(0, 0));

    //define screen size
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

    // define desired size
    Dimension maxWindowSize = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());

    // Maximize the browser window according to your system's current resolution(set desired size)
    driver.manage().window().setSize(maxWindowSize);

    LOGGER.info("Test case f_deleteDocument started execution");
    test.log(LogStatus.INFO, "Test case f_deleteDocument started execution");

    driver.get(TestCaseProperties.LOGIN_SCREEN_URL);

    LoginPage loginPage = new LoginPage(driver);
    LOGGER.info("Accessing the Login Page");
    test.log(LogStatus.INFO, "Accessing the Login Page");

    //Login as the Admin
    LOGGER.info("Login As Admin");
    test.log(LogStatus.INFO, "Login As Admin");
    loginPage.loginAsAdmin(className, screenShotName);
    Thread.sleep(3000);

    SearchObjects search = new SearchObjects(driver);

    //Search for the Site
    LOGGER.info("Click \"Search Finder\"");
    test.log(LogStatus.INFO, "Click \"Search Finder\"");

    LOGGER.info("Search Site \"" + siteName + "\"");
    test.log(LogStatus.INFO, "Search Site \"" + siteName + "\"");
    search.searchSite(siteName, className, screenShotName);

    //Clicks on the Site Link
    LOGGER.info("Navigate to the " + siteName);
    test.log(LogStatus.INFO, "Navigate to the " + siteName);
    Link siteLink = new Link(driver, By.xpath("//h3[@class='sitename']/a[text()='" + siteName + "']"));
    siteLink.click();

    //   Element.takescreenshot(driver, className, screenShotName);
    Thread.sleep(3000);

    //Delete Folder
    LOGGER.info("Delete the Document : " + documentName);
    test.log(LogStatus.INFO, "Delete the Document :  " + documentName);

    test.log(LogStatus.INFO, "Navigate To DocumentLibrary");
    test.log(LogStatus.INFO, "Select Document");
    test.log(LogStatus.INFO, "Click \"Selected Items\"");
    test.log(LogStatus.INFO, "Click \"Delete\" Button");
    test.log(LogStatus.INFO, "Click \"Delete Confirmation\" Button");
    test.log(LogStatus.INFO, "Login as Admin to delete Document in TrashCan");
    test.log(LogStatus.INFO, "Click \"My Profile\"");
    test.log(LogStatus.INFO, "Place DocumentName");
    test.log(LogStatus.INFO, "Click \"Search\" Button");
    test.log(LogStatus.INFO, "Check the patucular DocumentName");
    test.log(LogStatus.INFO, "Click \"Selected Item\" Button");
    test.log(LogStatus.INFO, "Click \"Delete\" Button");
    test.log(LogStatus.INFO, "Click \"OK\" Button");
    test.log(LogStatus.INFO, "Click \"OK confirmation\" Button");

    RemoveObjects delete = new RemoveObjects(driver);
    delete.deleteDocument(documentName, className, screenShotName);
    Thread.sleep(3000);
    WebDriver augmentedDriver2 = new Augmenter().augment(driver);
    File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screenshot2, new File(
            TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "100" + ".jpg"));
    test.log(LogStatus.INFO, "Snapshot below: "
            + test.addScreenCapture("./" + className + "/" + screenShotName + "100" + ".jpg"));
    System.out.println("Screenshot Taken Successfully!!!!");

    loginPage.logout();
    //--- Folder Validation   

    LOGGER.info("Accessing the Login Page Again");
    test.log(LogStatus.INFO, "Accessing the Login Page Again");

    //Login as the Admin
    LOGGER.info("Login As Admin");
    test.log(LogStatus.INFO, "Login As Admin");

    LoginPage loginPage1 = new LoginPage(driver);
    loginPage1.loginAsAdmin(className, screenShotName);

    NavigateToPage navigateTo = new NavigateToPage(driver);

    LOGGER.info("CHECK WHETHER DOCUMENT\" " + documentName + " \"IS DELETED OR NOT");
    test.log(LogStatus.INFO, "CHECK WHETHER DOCUMENT\" " + documentName + " \"IS DELETED OR NOT");
    navigateTo.goToHome();

    LOGGER.error("Click \"My Profile\" Again");
    test.log(LogStatus.INFO, "Click \"My Profile\" Again");

    navigateTo.goToUserTrashCan(className, screenShotName + "deletconfirmDOC123");

    LOGGER.info("Place DocumentUrl");
    test.log(LogStatus.INFO, "Place DocumentUrl");
    TextField textField = new TextField(driver,
            By.id("template_x002e_user-trashcan_x002e_user-trashcan_x0023_default-search-text"));
    textField.clearText();
    textField.enterText(documentName);

    LOGGER.info("Click \"Search\" Button");
    test.log(LogStatus.INFO, "Click \"Search\" Button");
    Button searchButton = new Button(driver, By.xpath("//button[text()='Search']"));
    searchButton.click();

    Thread.sleep(2000);
    WebDriver augmentedDriver3 = new Augmenter().augment(driver);
    File screenshot3 = ((TakesScreenshot) augmentedDriver3).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screenshot3, new File(
            TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "101" + ".jpg"));
    test.log(LogStatus.INFO, "Snapshot below: "
            + test.addScreenCapture("./" + className + "/" + screenShotName + "101" + ".jpg"));
    System.out.println("Screenshot Taken Successfully!!!!");

    //CheckBox checkbox=new CheckBox(driver, By.xpath("//div[@class='name'][text()='"+item+"']/ancestor::td[1]/preceding-sibling::td[2]//input"));
    //checkbox.click();

    LOGGER.info("Check the patucular docUrl");
    test.log(LogStatus.INFO, "Check the patucular docUrl");

    if (Element.isElementPresent(driver, By.xpath("//tbody[@class='yui-dt-message']//tr//td//div"))) {
        LOGGER.info(documentName + " Document IS DELETED SUCCESSFULLY");
        test.log(LogStatus.PASS, documentName + " Document IS DELETED SUCCESSFULLY");

        WebDriver augmentedDriver4 = new Augmenter().augment(driver);
        File screenshot4 = ((TakesScreenshot) augmentedDriver4).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(screenshot4, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/"
                + screenShotName + "102" + ".jpg"));
        test.log(LogStatus.INFO, "Snapshot below: "
                + test.addScreenCapture("./" + className + "/" + screenShotName + "102" + ".jpg"));
        System.out.println("Screenshot Taken Successfully!!!!");
    } else {
        Element.waitUntilElementPresent(driver,
                By.xpath("//div//div//table//tbody//tr[contains(.,'" + documentName + "')]//td//div"));

        java.util.List<WebElement> myList = driver.findElements(
                By.xpath("//div//div//table//tbody//tr[contains(.,'" + documentName + "')]//td//div"));

        for (int i = 0; i < myList.size(); i++) {

            if (myList.get(i).getText().equals(documentName)) {
                Thread.sleep(2000);
                LOGGER.info(documentName + "Document IS NOT DELETED");
                test.log(LogStatus.FAIL, documentName + " Document IS NOT DELETED");
                WebDriver augmentedDriver4 = new Augmenter().augment(driver);
                File screenshot4 = ((TakesScreenshot) augmentedDriver4).getScreenshotAs(OutputType.FILE);
                FileUtils.copyFile(screenshot4, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className
                        + "/" + screenShotName + "103" + ".jpg"));
                test.log(LogStatus.INFO, "Snapshot below: "
                        + test.addScreenCapture("./" + className + "/" + screenShotName + "103" + ".jpg"));
                System.out.println("Screenshot Taken Successfully!!!!");
            } else {
                LOGGER.info(documentName + " Document IS DELETED SUCCESSFULLY");
                test.log(LogStatus.PASS, documentName + "Document IS DELETED SUCCESSFULLY");
                WebDriver augmentedDriver4 = new Augmenter().augment(driver);
                File screenshot4 = ((TakesScreenshot) augmentedDriver4).getScreenshotAs(OutputType.FILE);
                FileUtils.copyFile(screenshot4, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className
                        + "/" + screenShotName + "104" + ".jpg"));
                test.log(LogStatus.INFO, "Snapshot below: "
                        + test.addScreenCapture("./" + className + "/" + screenShotName + "104" + ".jpg"));
                System.out.println("Screenshot Taken Successfully!!!!");
            }
        }

    }

    loginPage1.logout();
    LOGGER.info("Test case f_deleteDocument executed");
    test.log(LogStatus.INFO, "Test case f_deleteDocument executed");

    extent.endTest(test);
    extent.flush();
}

From source file:com.zaizi.automation.alfresco.F_Vanila_DocumentLibraryTest_Chrome.java

/**
 * //w w  w  . ja  va2  s .  com
 * @Test DeleteSite
 * @return
 * 
 * @throws Exception InterruptedException, IOException
 */

@Test
public void g_deleteSite() throws InterruptedException, IOException {
    LOGGER.info(TestCaseProperties.TEXT_TEST_EXECUTING, "Delete site called \" " + siteName + " \" ");

    //Extent Report Start Configuration(testCaseName,Definition of testCase)
    ExtentTest test = extent.startTest("g_deleteSite", "Delete site called \" " + siteName + " \" ");

    //Set the DriverType(BrowserName,Platform)
    driver = TestCaseProperties.driverType("Chrome", "WINDOWS");

    // Set the upper left corner of the screen starting point
    driver.manage().window().setPosition(new Point(0, 0));

    // define screen size
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

    // define desired size
    Dimension maxWindowSize = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());

    // Maximize the browser window according to your system's current
    // resolution(set desired size)
    driver.manage().window().setSize(maxWindowSize);

    //Get LoginScreen_URl from TestcaseProperties Values
    driver.get(TestCaseProperties.LOGIN_SCREEN_URL);

    LOGGER.info("Test case g_deleteSite started executing");
    test.log(LogStatus.INFO, "Test case g_deleteSite started executing");

    LOGGER.info("Accessing the Login Page");
    test.log(LogStatus.INFO, "Accessing the Login Page");

    LOGGER.info("Login as admin");
    test.log(LogStatus.INFO, "Login as admin");

    LoginPage loginPage = new LoginPage(driver);
    loginPage.loginAsAdmin(className, screenShotName);

    LOGGER.info("Check the site,if site exist Delet the user");
    test.log(LogStatus.INFO, "Check the site,if site exist Delete the user");
    test.log(LogStatus.INFO, "Search the site");
    test.log(LogStatus.INFO, "Click \"Delete\" Button,next to site\"" + siteName + "\"");
    test.log(LogStatus.INFO, "Click \"Delete\" Button,for delete confirmation");
    test.log(LogStatus.INFO, "Login as Admin to delete Site in TrashCan");
    test.log(LogStatus.INFO, "Click \"My Profile\"");
    test.log(LogStatus.INFO, "Place siteUrl");
    test.log(LogStatus.INFO, "Click \"Search\" Button");
    test.log(LogStatus.INFO, "Check the patucular siteUrl");
    test.log(LogStatus.INFO, "Click \"Selected Item\" Button");
    test.log(LogStatus.INFO, "Click \"Delete\" Button");
    test.log(LogStatus.INFO, "Click \"OK\" Button");
    test.log(LogStatus.INFO, "Click \"OK confirmation\" Button");
    RemoveObjects deleteSite = new RemoveObjects(driver);
    deleteSite.deleteSite(siteName, siteId, className, screenShotName);

    LOGGER.info("CHECK WHETHER SITE\" " + siteName + " \"IS DELETED OR NOT");
    test.log(LogStatus.INFO, "CHECK WHETHER SITE\" " + siteName + " \"IS DELETED OR NOT");

    NavigateToPage navigateTo = new NavigateToPage(driver);
    navigateTo.goToHome();

    LOGGER.error("Click \"My Profile\" Again");
    test.log(LogStatus.INFO, "Click \"My Profile\" Again");

    test.log(LogStatus.INFO, "Accessing trashcan Page");
    navigateTo.goToUserTrashCan(className, screenShotName + "deletconfirm1");

    LOGGER.info("Place siteUrl");
    test.log(LogStatus.INFO, "Place siteUrl");
    TextField textField = new TextField(driver,
            By.id("template_x002e_user-trashcan_x002e_user-trashcan_x0023_default-search-text"));
    textField.clearText();
    textField.enterText(siteId);

    LOGGER.info("Click \"Search\" Button");
    test.log(LogStatus.INFO, "Click \"Search\" Button");
    Button searchButton = new Button(driver, By.xpath("//button[text()='Search']"));
    searchButton.click();
    Thread.sleep(2000);

    WebDriver augmentedDriver1 = new Augmenter().augment(driver);
    File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screenshot1, new File(
            TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "105" + ".jpg"));
    test.log(LogStatus.INFO, "Snapshot below: "
            + test.addScreenCapture("./" + className + "/" + screenShotName + "105" + ".jpg"));
    System.out.println("Screenshot Taken Successfully!!!!");
    //Element.takescreenshot(driver, className, screenShotName+"deleteConfirmation");

    //CheckBox checkbox=new CheckBox(driver, By.xpath("//div[@class='name'][text()='"+item+"']/ancestor::td[1]/preceding-sibling::td[2]//input"));
    //checkbox.click();

    LOGGER.info("Check the patucular siteUrl");
    test.log(LogStatus.INFO, "Check the patucular siteUrl");

    if (Element.isElementPresent(driver, By.xpath("//tbody[@class='yui-dt-message']//tr//td//div"))) {
        LOGGER.info(siteName + " SITE IS DELETED SUCCESSFULLY");
        test.log(LogStatus.PASS, siteName + " SITE IS DELETED SUCCESSFULLY");
        WebDriver augmentedDriver2 = new Augmenter().augment(driver);
        File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(screenshot2, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/"
                + screenShotName + "106" + ".jpg"));
        test.log(LogStatus.INFO, "Snapshot below: "
                + test.addScreenCapture("./" + className + "/" + screenShotName + "106" + ".jpg"));
        System.out.println("Screenshot Taken Successfully!!!!");
    } else {
        Element.waitUntilElementPresent(driver,
                By.xpath("//div//div//table//tbody//tr[contains(.,'" + siteId + "')]//td//div"));

        java.util.List<WebElement> myList = driver
                .findElements(By.xpath("//div//div//table//tbody//tr[contains(.,'" + siteId + "')]//td//div"));

        for (int i = 0; i < myList.size(); i++) {

            if (myList.get(i).getText().equals(siteId)) {
                Thread.sleep(2000);
                LOGGER.info(siteName + "SITE IS NOT DELETED");
                test.log(LogStatus.FAIL, siteName + " SITE IS NOT DELETED");
                WebDriver augmentedDriver2 = new Augmenter().augment(driver);
                File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE);
                FileUtils.copyFile(screenshot2, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className
                        + "/" + screenShotName + "107" + ".jpg"));
                test.log(LogStatus.INFO, "Snapshot below: "
                        + test.addScreenCapture("./" + className + "/" + screenShotName + "107" + ".jpg"));
                System.out.println("Screenshot Taken Successfully!!!!");
            } else {
                LOGGER.info(siteName + " SITE IS DELETED SUCCESSFULLY");
                test.log(LogStatus.PASS, siteName + "SITE IS DELETED SUCCESSFULLY");
                WebDriver augmentedDriver2 = new Augmenter().augment(driver);
                File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE);
                FileUtils.copyFile(screenshot2, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className
                        + "/" + screenShotName + "108" + ".jpg"));
                test.log(LogStatus.INFO, "Snapshot below: "
                        + test.addScreenCapture("./" + className + "/" + screenShotName + "108" + ".jpg"));
                System.out.println("Screenshot Taken Successfully!!!!");
            }
        }

    }

    loginPage.logout();

    LOGGER.info("Test case g_deleteSite executed");
    test.log(LogStatus.INFO, "Test case g_deleteSite executed");

    extent.endTest(test);
    extent.flush();
}

From source file:de.ppi.selenium.browser.DefaultWebDriverFactory.java

License:Apache License

@Override
public WebDriver createWebDriver(Map<String, String> options, DesiredCapabilities capabilities)
        throws IOException {
    ClientProperties properties = new ClientProperties(options.get(CLIENT_PROPERTIES_KEY));

    WebDriver wd = null;/* ww w. j a  va2 s  . co m*/
    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.getFfBinaryPath();
            final FirefoxProfile ffp;
            if (ffProfileFolder != null) {
                ffp = new FirefoxProfile(new File(ffProfileFolder));
            } else {
                ffp = new FirefoxProfile();
            }

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

            addPreferences(ffp, properties);

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

            if (path != null) {
                FirefoxBinary fireFox = getFFBinary(path);
                wd = new FirefoxDriver(fireFox, ffp, desiredCapabilities);
            } else {
                wd = new FirefoxDriver(new FirefoxBinary(), ffp, desiredCapabilities);

            }
        } else if (browser.equalsIgnoreCase("chrome")) {

            final String webdriverChromeDriver = properties.getWebDriverChromeDriver();

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

            final ChromeOptions chromeOptions = new ChromeOptions();
            final String chromeBinaryPath = properties.getChromeBinaryPath();
            if (chromeBinaryPath != null) {
                chromeOptions.setBinary(chromeBinaryPath);
            }

            if (properties.getAcceptedLanguages() != null) {

                final Map<String, Object> prefs = new HashMap<String, Object>();
                prefs.put("intl.accept_languages", properties.getAcceptedLanguages());
                chromeOptions.setExperimentalOption("prefs", prefs);
            }
            desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

            wd = new ChromeDriver(desiredCapabilities);

        } else if (browser.equalsIgnoreCase("safari")) {
            wd = new SafariDriver(desiredCapabilities);
        } else if (browser.equalsIgnoreCase("htmlunit")) {
            final BrowserVersion browserVersion = BrowserVersion.FIREFOX_45;
            if (properties.getAcceptedLanguages() != null) {
                browserVersion.setBrowserLanguage(properties.getAcceptedLanguages().split(",")[0]);
            }
            wd = new HtmlUnitDriver(browserVersion);
            ((HtmlUnitDriver) wd).setJavascriptEnabled(true);
        } else if (browser.equalsIgnoreCase("phantomjs")) {
            final String webdriverPhantomJSDriver = properties.getWebDriverPhantomJSDriver();
            if (properties.getAcceptedLanguages() != null) {
                desiredCapabilities.setCapability("phantomjs.page.customHeaders.Accept-Language",
                        properties.getAcceptedLanguages());
            }

            if (webdriverPhantomJSDriver != null) {
                desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                        webdriverPhantomJSDriver);
                wd = new PhantomJSDriver(desiredCapabilities);
            } else {
                wd = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(),
                        desiredCapabilities);
            }
        } else {
            throw new IllegalArgumentException("Unsupported browser type: " + browser
                    + ". Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit, phantomjs.");
        }

        // 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));
        }
        wd.manage().timeouts().implicitlyWait(properties.getAppearWaitTime(), TimeUnit.MILLISECONDS);
    }

    return wd;
}

From source file:imagedownload.Downloader.java

public void download() {
    System.out.println((new Date()).toString());

    WebDriver driver = new ChromeDriver();
    WebDriver.Window win = driver.manage().window();
    // get the full screen size (exculde desktop toolbar)
    win.maximize();/*  w w  w  . j a  va  2  s  . co m*/
    int screenHeight = win.getSize().getHeight();
    int screenWidth = win.getSize().getWidth();
    System.out.println("Screen: " + screenHeight + "*" + screenWidth);
    // set browser size and position it to bottom right
    win.setSize(new Dimension(browserWidth, browserHeight));
    System.out.println("Browser: " + win.getSize().getHeight() + "*" + win.getSize().getWidth());
    win.setPosition(new Point(screenWidth - browserWidth, screenHeight - browserHeight));
    // position the browser outside of windows
    if (hide) {
        win.setPosition(new Point(screenWidth, screenHeight));
    }

    String page = firstPage;
    boolean hasNextPage = true;
    int pageCnt = 0;
    while (hasNextPage && pageCnt < pageLimit) {
        pageCnt++;
        if (visitedPages.get(page) != null) {
            System.out.println("Looped back. Quit download.");
            break;
        }
        visitedPages.put(page, page);
        driver.get(page);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        hasNextPage = false;
        if (pagination) {
            // if no xpath configured, default search all <a> hyperlinks
            if (xpath == null || xpath.trim().equals("")) {
                xpath = determineNextPage(driver);
            }
            if (xpath != null && !xpath.trim().equals("")) {
                page = "";
                System.out.println("Xpath: " + xpath);
                List<WebElement> checkList = driver.findElements(By.xpath(xpath));
                for (WebElement elm : checkList) {
                    String text = elm.getAttribute("innerHTML");
                    for (String t : next) {
                        if (text.equals(t)) {
                            hasNextPage = true;
                            page = elm.getAttribute("href");
                            break;
                        }
                    }
                }
                System.out.println("Next page: " + hasNextPage + ", " + page);
            }
        }

        List<WebElement> imgList = driver.findElements(By.tagName("img"));
        List<String> filteredList = new ArrayList<String>();
        for (WebElement img : imgList) {
            if (img.getAttribute("src") == null) {
                continue;
            }
            if (duplicateFilter) {
                if (savedImages.get(img.getAttribute("src")) != null) {
                    continue;
                }
            }
            if (minSizeFilter) {
                if (img.getSize().getHeight() < minHeight || img.getSize().getWidth() < minWidth) {
                    continue;
                }
            }
            filteredList.add(img.getAttribute("src").trim());
        }

        int cnt = 0;
        InputStream imgIn = null;
        OutputStream imgOut = null;
        for (String location : filteredList) {
            cnt++;
            try {
                String[] urlArr = location.split("\\/");
                String[] nameArr = urlArr[urlArr.length - 1].split("\\.");
                String ext = nameArr[nameArr.length - 1];
                String filePath = config.getProperty("output.folder") + config.getProperty("output.namePrefix")
                        + "_" + pageCnt + "_" + cnt + "." + ext;
                System.out.println("File location: " + location);
                System.out.println("File name: " + urlArr[urlArr.length - 1]);
                System.out.println("File ext: " + nameArr[nameArr.length - 1]);
                System.out.println("Output: " + filePath);

                driver.get(location);
                driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
                WebElement image = driver.findElement(By.tagName("img"));
                System.out.println("Image element: " + image.getAttribute("src"));

                AutoSave.save(driver, image, filePath);
                savedImages.put(location, location);
            } finally {
                try {
                    if (imgIn != null) {
                        imgIn.close();
                    }
                    if (imgOut != null) {
                        imgOut.close();
                    }
                } catch (IOException ex) {
                    Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    driver.quit();
    System.out.println((new Date()).toString());
}

From source file:io.appium.java_client.AppiumDriver.java

License:Apache License

/**
 * Convenience method for "zooming in" on an element on the screen.
 * "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other.
 * NOTE://from   w w  w.j  av a2  s .com
 * This convenience method slides touches away from the element, if this would happen to place one of them
 * off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api
 * instead of this method.
 *
 * @param el The element to pinch
 */
public void zoom(WebElement el) {
    MultiTouchAction multiTouch = new MultiTouchAction(this);

    Dimension dimensions = el.getSize();
    Point upperLeft = el.getLocation();
    Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2,
            upperLeft.getY() + dimensions.getHeight() / 2);
    int yOffset = center.getY() - upperLeft.getY();

    TouchAction action0 = new TouchAction(this).press(el).moveTo(el, center.getX(), center.getY() - yOffset)
            .release();
    TouchAction action1 = new TouchAction(this).press(el).moveTo(el, center.getX(), center.getY() + yOffset)
            .release();

    multiTouch.add(action0).add(action1);

    multiTouch.perform();
}

From source file:io.appium.java_client.imagecomparison.ComparisonResult.java

License:Apache License

/**
 * Transforms a map into {@link Point} object.
 *
 * @param map the source map./*from  w ww.  j  ava 2  s  . c o m*/
 * @return {@link Point} object
 */
public static Point mapToPoint(Map<String, Object> map) {
    return new Point(toSeleniumCoordinate(map.get("x")), toSeleniumCoordinate(map.get("y")));
}

From source file:io.openvidu.test.OpenViduClientBrowserTest.java

License:Apache License

@Override
public void setupBrowserTest() throws InterruptedException {
    super.setupBrowserTest();

    execExceptions.clear();//from  w ww .j  a v  a  2 s .  c o  m

    if (testScenario != null && testScenario.getBrowserMap() != null
            && testScenario.getBrowserMap().size() > 0) {
        int row = 0;
        int col = 0;
        for (final String browserKey : testScenario.getBrowserMap().keySet()) {
            Browser browser = getPage(browserKey).getBrowser();
            browser.getWebDriver().manage().window()
                    .setSize(new Dimension(WEB_TEST_BROWSER_WIDTH, WEB_TEST_BROWSER_HEIGHT));
            browser.getWebDriver().manage().window()
                    .setPosition(new Point(col * WEB_TEST_BROWSER_WIDTH + WEB_TEST_LEFT_BAR_WIDTH,
                            row * WEB_TEST_BROWSER_HEIGHT + WEB_TEST_TOP_BAR_WIDTH));
            col++;
            if (col * WEB_TEST_BROWSER_WIDTH + WEB_TEST_LEFT_BAR_WIDTH > WEB_TEST_MAX_WIDTH) {
                col = 0;
                row++;
            }
        }
    }
}

From source file:io.selendroid.client.waiter.WaitingConditions.java

License:Apache License

public static Callable<Point> elementLocationToBe(final WebElement element, final Point expectedLocation) {
    return new Callable<Point>() {
        private Point currentLocation = new Point(0, 0);

        public Point call() throws Exception {
            currentLocation = element.getLocation();
            if (currentLocation.equals(expectedLocation)) {
                return expectedLocation;
            }//from  w ww  .j  a  v a2  s.  com

            return null;
        }

        @Override
        public String toString() {
            return "location to be: " + expectedLocation + " is: " + currentLocation;
        }
    };
}

From source file:io.selendroid.driver.SelendroidUnknownCommandHandlingTest.java

License:Apache License

@Test(expected = UnsupportedCommandException.class)
public void testShouldNotSetPosition() {
    Point targetPosition = new Point(1, 2);
    driver().manage().window().setPosition(targetPosition);
}

From source file:jp.co.nssol.h5.test.selenium.testcase.StressTest.java

License:Apache License

@Test
public void scrollTest() throws InterruptedException {
    getDriver().manage().window().setPosition(new Point(0, 1000));
    // TODO ??/*from  w  w  w.j  av a 2 s.  com*/
}