List of usage examples for org.openqa.selenium WebDriver manage
Options manage();
From source file:com.expedia.lux.accountsettingstest.core.CreateWebDriverHelper.java
License:Open Source License
public static void setBrowserSize(WebDriver driver, Integer width, Integer height) { driver.manage().window().setPosition(new Point(0, 0)); driver.manage().window().setSize(new Dimension(width, height)); }
From source file:com.fmb.common.LogTools.java
License:Apache License
public static String screenShot(BrowserEmulator be) { // String dir = "screenshot"; // TODO String dir = "target/publish-report"; //?screenshot String time = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()); String screenShotPath = dir + File.separator + time + ".png"; WebDriver augmentedDriver = null; 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 {//from w w w . ja v a2 s. c om 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.galenframework.ide.tests.integration.ui.GalenTestBase.java
License:Apache License
@Override public WebDriver createDriver(Object[] args) { WebDriver driver = WebDriverSingleInstance.getDriver(); driver.get(getTestUrl());/* ww w . j a va2s .com*/ driver.manage().window().setSize(desktopDevice.getSize()); driver.manage().deleteAllCookies(); driver.manage().addCookie(new Cookie(MockedWebApp.MOCK_KEY_COOKIE_NAME, mockUniqueKey, "/", new Date(new Date().getTime() + ONE_YEAR))); return driver; }
From source file:com.galenframework.utils.GalenUtils.java
License:Apache License
public static void resizeDriver(WebDriver driver, String sizeText) { if (sizeText != null && !sizeText.trim().isEmpty()) { Dimension size = GalenUtils.readSize(sizeText); driver.manage().window().setSize(new org.openqa.selenium.Dimension(size.width, size.height)); }//from www . j ava2s . co m }
From source file:com.galenframework.utils.GalenUtils.java
License:Apache License
public static void autoAdjustBrowserWindowSizeToFitViewport(WebDriver driver, int width, int height) { driver.manage().window().setSize(new org.openqa.selenium.Dimension(width, height)); Dimension viewport = getViewportArea(driver); if (viewport.getWidth() < width) { int delta = (int) (width - viewport.getWidth()); driver.manage().window().setSize(new org.openqa.selenium.Dimension(width + delta, height)); }//from w w w . j ava 2 s .co m }
From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java
License:Apache License
/** * Clear browser cookies.//from w ww .ja va2 s . c o m * * @throws Exception if the test fails */ @Before public void clearCookies() throws Exception { getMockWebConnection().setDefaultResponse("<html><head></head><body></body></html>"); startWebServer(getMockWebConnection()); final WebDriver driver = getWebDriver(); driver.get(URL_HOST1); driver.manage().deleteAllCookies(); driver.get(URL_HOST2); driver.manage().deleteAllCookies(); driver.get(URL_HOST3); driver.manage().deleteAllCookies(); driver.get(URL_HOST4); driver.manage().deleteAllCookies(); stopWebServers(); }
From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java
License:Apache License
/** * @throws Exception if the test fails//from w w w . ja v a 2 s.co m */ @Test @Alerts("c1=1; c2=2; c3=3; c4=4") public void storedDomain1() throws Exception { final List<NameValuePair> responseHeader = new ArrayList<>(); responseHeader.add(new NameValuePair("Set-Cookie", "c1=1; Domain=." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c2=2; Domain=" + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c3=3; Domain=.host1." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c4=4; Domain=host1." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c5=5; Domain=." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c6=6; Domain=" + DOMAIN + ":" + PORT + "; Path=/")); responseHeader .add(new NameValuePair("Set-Cookie", "c7=7; Domain=.host1." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader .add(new NameValuePair("Set-Cookie", "c8=8; Domain=host1." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c9=9; Domain=.org; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c10=10; Domain=org; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c11=11; Domain=.htmlunit; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c12=12; Domain=htmlunit; Path=/")); getMockWebConnection().setDefaultResponse(CookieManagerTest.HTML_ALERT_COOKIE, 200, "Ok", "text/html", responseHeader); final WebDriver driver = loadPageWithAlerts2(new URL(URL_HOST1)); assertEquals("c1=1; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c1").toString()); assertEquals("c2=2; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c2").toString()); assertEquals("c3=3; path=/; domain=.host1.htmlunit.org", driver.manage().getCookieNamed("c3").toString()); assertEquals("c4=4; path=/; domain=.host1.htmlunit.org", driver.manage().getCookieNamed("c4").toString()); }
From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java
License:Apache License
/** * @throws Exception if the test fails//from ww w . j av a 2s. co m */ @Test @Alerts("c1=1; c2=2") public void storedDomain2() throws Exception { final List<NameValuePair> responseHeader = new ArrayList<>(); responseHeader.add(new NameValuePair("Set-Cookie", "c1=1; Domain=." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c2=2; Domain=" + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c3=3; Domain=.host1." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c4=4; Domain=host1." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c5=5; Domain=." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c6=6; Domain=" + DOMAIN + ":" + PORT + "; Path=/")); responseHeader .add(new NameValuePair("Set-Cookie", "c7=7; Domain=.host1." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader .add(new NameValuePair("Set-Cookie", "c8=8; Domain=host1." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c9=9; Domain=.org; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c10=10; Domain=org; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c11=11; Domain=.htmlunit; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c12=12; Domain=htmlunit; Path=/")); getMockWebConnection().setDefaultResponse(CookieManagerTest.HTML_ALERT_COOKIE, 200, "Ok", "text/html", responseHeader); final WebDriver driver = loadPageWithAlerts2(new URL(URL_HOST2)); assertEquals("c1=1; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c1").toString()); assertEquals("c2=2; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c2").toString()); }
From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java
License:Apache License
/** * @throws Exception if the test fails/*www. ja v a2 s. c o m*/ */ @Test @Alerts("c1=1; c2=2") public void storedDomain3() throws Exception { final List<NameValuePair> responseHeader = new ArrayList<>(); responseHeader.add(new NameValuePair("Set-Cookie", "c1=1; Domain=." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c2=2; Domain=" + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c3=3; Domain=.host1." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c4=4; Domain=host1." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c5=5; Domain=." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c6=6; Domain=" + DOMAIN + ":" + PORT + "; Path=/")); responseHeader .add(new NameValuePair("Set-Cookie", "c7=7; Domain=.host1." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader .add(new NameValuePair("Set-Cookie", "c8=8; Domain=host1." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c9=9; Domain=.org; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c10=10; Domain=org; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c11=11; Domain=.htmlunit; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c12=12; Domain=htmlunit; Path=/")); getMockWebConnection().setDefaultResponse(CookieManagerTest.HTML_ALERT_COOKIE, 200, "Ok", "text/html", responseHeader); final WebDriver driver = loadPageWithAlerts2(new URL(URL_HOST3)); assertEquals("c1=1; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c1").toString()); assertEquals("c2=2; path=/; domain=.htmlunit.org", driver.manage().getCookieNamed("c2").toString()); }
From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java
License:Apache License
/** * @throws Exception if the test fails/*from w ww.j a va 2 s . c o m*/ */ @Test @Alerts(DEFAULT = "c11=11; c12=12", CHROME = "c12=12") public void storedDomain4() throws Exception { final List<NameValuePair> responseHeader = new ArrayList<>(); responseHeader.add(new NameValuePair("Set-Cookie", "c1=1; Domain=." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c2=2; Domain=" + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c3=3; Domain=.host1." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c4=4; Domain=host1." + DOMAIN + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c5=5; Domain=." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c6=6; Domain=" + DOMAIN + ":" + PORT + "; Path=/")); responseHeader .add(new NameValuePair("Set-Cookie", "c7=7; Domain=.host1." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader .add(new NameValuePair("Set-Cookie", "c8=8; Domain=host1." + DOMAIN + ":" + PORT + "; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c9=9; Domain=.org; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c10=10; Domain=org; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c11=11; Domain=.htmlunit; Path=/")); responseHeader.add(new NameValuePair("Set-Cookie", "c12=12; Domain=htmlunit; Path=/")); getMockWebConnection().setDefaultResponse(CookieManagerTest.HTML_ALERT_COOKIE, 200, "Ok", "text/html", responseHeader); final WebDriver driver = loadPageWithAlerts2(new URL(URL_HOST4)); assertEquals("c12=12; path=/; domain=htmlunit", driver.manage().getCookieNamed("c12").toString()); if (driver.manage().getCookieNamed("c11") != null) { assertEquals("c11=11; path=/; domain=htmlunit", driver.manage().getCookieNamed("c11").toString()); } }