List of usage examples for org.openqa.selenium Point Point
public Point(int x, int y)
From source file:com.mgmtp.jfunk.web.util.Rectangle.java
License:Apache License
/** * Returns the point that specifies the center of the rectangle. * * @return center of the rectangle./* w w w . j a v a 2 s . co m*/ */ public Point center() { return new Point(left + width / 2, top + height / 2); }
From source file:com.molo.dagger.LogTools.java
License:Apache License
public static String screenShot(BrowserEmulator be) { String dir = "screenshot"; // TODO String time = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()); String screenShotPath = dir + File.separator + time + ".png"; WebDriver augmentedDriver = null;//from w w w. ja va 2s.co m if (GlobalSettings.browserCoreType == 1 || GlobalSettings.browserCoreType == 3) { augmentedDriver = be.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(be.getBrowserCore()); } else { return "Incorrect browser type"; } try { File sourceFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(sourceFile, new File(screenShotPath)); } catch (Exception e) { e.printStackTrace(); return "Failed to screenshot"; } // Convert '\' into '/' for web image browsing. return screenShotPath.replace("\\", "/"); }
From source file:com.mycompany.browserManipulationUtilities.ScreenShotUtility.java
protected static Point getViewPortTopLeftCorner(WebDriver browser) { JavascriptExecutor jseBrowser = (JavascriptExecutor) browser; Integer xOffset = ((Long) jseBrowser.executeScript("return window.pageXOffset", "")).intValue(); Integer yOffset = ((Long) jseBrowser.executeScript("return window.pageYOffset", "")).intValue(); Point topLeft = new Point(xOffset, yOffset); return topLeft; }
From source file:com.mycompany.layoutTests.HorizontalLayoutTesterTest.java
/** * Test of calculateHorizontalSpacingBetweenTwoElements method, of class HorizontalLayoutTester. *//* ww w . j a va 2 s.co m*/ @Test public void testCalculateHorizontalSpacingBetweenTwoElements_overlapCase() { System.out.println("calculateHorizontalSpacingBetweenTwoElements"); Point webElem1Orig = new Point(10, 10); Dimension webElem1Dim = new Dimension(30, 30); Point webElem2Orig = new Point(10, 100); Dimension webElem2Dim = new Dimension(30, 30); WebElement webElement1 = Mockito.mock(WebElement.class); Mockito.when(webElement1.getLocation()).thenReturn(webElem1Orig); Mockito.when(webElement1.getSize()).thenReturn(webElem1Dim); WebElement webElement2 = Mockito.mock(WebElement.class); Mockito.when(webElement2.getLocation()).thenReturn(webElem2Orig); Mockito.when(webElement2.getSize()).thenReturn(webElem2Dim); Integer expResult = -30; Integer result = HorizontalLayoutTester.calculateHorizontalSpacingBetweenTwoElements(webElement1, webElement2); assertEquals(expResult, result); }
From source file:com.mycompany.layoutTests.HorizontalLayoutTesterTest.java
@Test public void testCalculateHorizontalSpacingBetweenTwoElements_nonOverlapCase() { System.out.println("calculateHorizontalSpacingBetweenTwoElements"); Point webElem1Orig = new Point(10, 10); Dimension webElem1Dim = new Dimension(30, 30); Point webElem2Orig = new Point(100, 100); Dimension webElem2Dim = new Dimension(30, 30); WebElement webElement1 = Mockito.mock(WebElement.class); Mockito.when(webElement1.getLocation()).thenReturn(webElem1Orig); Mockito.when(webElement1.getSize()).thenReturn(webElem1Dim); WebElement webElement2 = Mockito.mock(WebElement.class); Mockito.when(webElement2.getLocation()).thenReturn(webElem2Orig); Mockito.when(webElement2.getSize()).thenReturn(webElem2Dim); Integer expResult = 60;/*ww w.j av a 2 s . c o m*/ Integer result = HorizontalLayoutTester.calculateHorizontalSpacingBetweenTwoElements(webElement1, webElement2); assertEquals(expResult, result); }
From source file:com.mycompany.layoutTests.VerticalLayoutTesterTest.java
/** * Test of testVerticalSpacingBetweenTwoElements method, of class VerticalLayoutTester. */// w w w . ja v a 2 s . c o m @Test public void testTestVerticalSpacingBetweenTwoElements() { System.out.println("testVerticalSpacingBetweenTwoElements"); Point webElem1Orig = new Point(10, 10); Dimension webElem1Dim = new Dimension(30, 30); Point webElem2Orig = new Point(10, 100); Dimension webElem2Dim = new Dimension(30, 30); WebElement webElement1 = Mockito.mock(WebElement.class); Mockito.when(webElement1.getLocation()).thenReturn(webElem1Orig); Mockito.when(webElement1.getSize()).thenReturn(webElem1Dim); WebElement webElement2 = Mockito.mock(WebElement.class); Mockito.when(webElement2.getLocation()).thenReturn(webElem2Orig); Mockito.when(webElement2.getSize()).thenReturn(webElem2Dim); int minVerticalPixelSpacing = 50; int maxVerticalPixelSpacing = 70; boolean expResult = true; boolean result = VerticalLayoutTester.testVerticalSpacingBetweenTwoElements(webElement1, webElement2, minVerticalPixelSpacing, maxVerticalPixelSpacing); assertEquals(expResult, result); }
From source file:com.mycompany.layoutTests.VerticalLayoutTesterTest.java
/** * Test of calculateVerticalSpacingBetweenElements method, of class VerticalLayoutTester. *//*from ww w . j a va 2s . com*/ @Test public void testCalculateVerticalSpacingBetweenElements() { System.out.println("calculateVerticalSpacingBetweenElements"); Point webElem1Orig = new Point(10, 10); Dimension webElem1Dim = new Dimension(30, 30); Point webElem2Orig = new Point(10, 100); Dimension webElem2Dim = new Dimension(30, 30); WebElement webElement1 = Mockito.mock(WebElement.class); Mockito.when(webElement1.getLocation()).thenReturn(webElem1Orig); Mockito.when(webElement1.getSize()).thenReturn(webElem1Dim); WebElement webElement2 = Mockito.mock(WebElement.class); Mockito.when(webElement2.getLocation()).thenReturn(webElem2Orig); Mockito.when(webElement2.getSize()).thenReturn(webElem2Dim); int expResult = 60; int result = VerticalLayoutTester.calculateVerticalSpacingBetweenElements(webElement1, webElement2); assertEquals(expResult, result); }
From source file:com.opera.core.systems.OperaMouse.java
License:Apache License
public void mouseMove(Coordinates where, long xOffset, long yOffset) { Point p = getPoint(where, "mouse move"); // We can't compare against Integer.MAX_VALUE and throw because this method isn't defined as // able to throw an Exception. Weird things will just happen here... int xO = (int) xOffset; int yO = (int) yOffset; lastMousePosition = new Point(p.x + xO, p.y + yO); parent.exec.mouseAction(p.x + xO, p.y + yO); }
From source file:com.opera.core.systems.OperaWebElement.java
License:Apache License
/** * Click top left, can be modified to click in the middle *//* ww w . ja va 2 s.c o m*/ public Point getLocation() { assertElementNotStale(); String coordinates = debugger.callFunctionOnObject( "var coords = " + OperaAtoms.GET_LOCATION + "(locator); return coords.x + ',' + coords.y;", objectId); // TODO: The goog.dom.getDocumentScrollElement_() function the Google closure library doesn't // return the document for SVG documents. This is used by the above atom. In this case the // coordinates string will be empty, so we use this fallback to get the coordinates. Hopefully // a fix will be forthcoming in the closure library. if (coordinates.isEmpty()) { logger.warning("Falling back to non-atom positioning code in getLocation"); coordinates = debugger.callFunctionOnObject( "var coords = locator.getBoundingClientRect();" + "return (coords.left-window.pageXOffset)+','+(coords.top-window.pageYOffset)", objectId); } String[] location = coordinates.split(","); return new Point(Integer.valueOf(location[0]), Integer.valueOf(location[1])); }
From source file:com.pentaho.selenium.BaseTest.java
License:Apache License
@BeforeSuite public void setUpClass() { this.log.info("Master setup"); // Initialize BASEURL baseUrl = "http://localhost:8080/pentaho/"; downloadDir = System.getProperty("user.home") + "\\SeleniumDonwloadDir"; pentahoReleaseVersion = System.getProperty("pentaho.release.version"); pentahoBaServerServiceName = System.getProperty("pentaho.bi.server.service.name"); pentahoBaServerUrl = System.getProperty("pentaho.bi.server.url"); pentahoBaServerHostname = System.getProperty("pentaho.bi.server.hostname"); pentahoBaServerPort = System.getProperty("pentaho.bi.server.port"); this.log.info("pentaho.release.version::" + pentahoReleaseVersion); new File(downloadDir).mkdir(); System.setProperty("webdriver.log.file", "/dev/stdout"); //System.setProperty( "webdriver.firefox.logfile", "/dev/stdout" ); // Setting log preferences LoggingPreferences logs = new LoggingPreferences(); logs.enable(LogType.BROWSER, Level.WARNING); /*logs.enable( LogType.SERVER, Level.WARNING ); logs.enable( LogType.DRIVER, Level.WARNING ); logs.enable( LogType.PROFILER, Level.WARNING ); logs.enable( LogType.CLIENT, Level.WARNING ); logs.enable( LogType.PERFORMANCE, Level.WARNING );*/ /*/*from w w w .java 2s .c o m*/ * INTERNET EXPLORER DRIVER */ // Initialize DRIVER FirefoxProfile ffProfile = new FirefoxProfile(); //ffProfile.setEnableNativeEvents( true ); ffProfile.setPreference("general.useragent.locale", "en-US"); ffProfile.setPreference("intl.accept_languages", "en-US, en"); ffProfile.setPreference("browser.download.folderList", 2); // 0 - Desktop, 1- Download dir, 2 - specify dir ffProfile.setPreference("browser.helperApps.alwaysAsk.force", false); ffProfile.setPreference("browser.download.manager.showWhenStarting", false); ffProfile.setPreference("browser.download.dir", downloadDir); ffProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "table/excel;application/vnd.ms-excel;application/msexcel;application/x-msexcel;application/x-ms-excel;application/x-excel;application/x-dos_ms_excel;application/xls;application/x-xls;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;text/csv;application/rtf"); // Setting properties for webdriver DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.LOGGING_PREFS, logs); capabilities.setCapability(FirefoxDriver.PROFILE, ffProfile); BaseTest.driver = new FirefoxDriver(capabilities); /* * INTERNET EXPLORER DRIVER */ /* * System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer_Win32_2.44.0\\IEDriverServer.exe"); * System.setProperty("webdriver.ie.driver.host", "10.120.42.25"); * System.setProperty("webdriver.ie.driver.loglevel", "FATAL"); System.setProperty("webdriver.ie.driver.loglevel", * downloadDir + "\\seleniumlogs.txt"); * * // We could use any driver for our tests... DesiredCapabilities capabilities = new DesiredCapabilities(); * capabilities.setBrowserName("internet explorer"); capabilities.setVersion("8"); * capabilities.setPlatform(Platform.WINDOWS); capabilities.setCapability("platform", "WINDOWS"); * capabilities.setJavascriptEnabled(true); //capabilities.setCapability(InternetExplorerDriver.HOST, * "10.120.40.243"); * * capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); * capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); * * // Get a handle to the driver. This will throw an exception // if a matching driver cannot be located driver = * new RemoteWebDriver(new URL("http://10.120.42.25:4444/wd/hub"), capabilities); //driver = new * InternetExplorerDriver(); */ BaseTest.driver.manage().window().setPosition(new Point(0, 0)); BaseTest.driver.manage().window().setSize(new Dimension(1360, 764)); BaseTest.driver.manage().timeouts().pageLoadTimeout(180, TimeUnit.SECONDS); BaseTest.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); BaseTest.driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS); // Initialize WAIT wait = new FluentWait<WebDriver>(BaseTest.driver).withTimeout(30, TimeUnit.SECONDS).pollingEvery(5, TimeUnit.SECONDS); }