List of usage examples for org.openqa.selenium Cookie toString
@Override
public String toString()
From source file:com.partnet.automation.selenium.AbstractConfigurableDriverProvider.java
License:Apache License
/** * Screenshooter for HTMLUnit. It saves the html source to disk following the * same pattern as the screenshot path. The HTMLUnit session is transfered to * PhantomJs, which takes the screenshot, and is destroyed. The original * driver is not destroyed/*from w w w . java2s . c o m*/ * * Note: Javascript events, current page changes, etc.. are not saved and are * not captured in the screenshots taken. * * @param path * - where to save the file. This assumes a png file will be * generated * @param baseUrl * - used to transfer the cookies to the phantomjs driver properly. * * @see #getPhantomJsWebDriver() */ public void saveScreenshotForHtmlUnit(String path, String baseUrl) { final WebDriver driver = this.get(); if (!(driver instanceof HtmlUnitDriver)) { LOG.warn("Wrong driver called screenshooter for HTMLUnit driver, default to regular screenshooter"); this.saveScreenshotAs(path); return; } PhantomJSDriver phantomJs = (PhantomJSDriver) getPhantomJsWebDriver(); try { phantomJs.get(baseUrl); String url = driver.getCurrentUrl(); LOG.debug("Url: {}", url); for (Cookie cookie : driver.manage().getCookies()) { LOG.debug("Cookie: {}", cookie.toString()); phantomJs.manage().addCookie(cookie); } phantomJs.get(url); // set current thread to phantomjs, and take screenshot in the default way this.set(phantomJs); LOG.debug("HTML Screenshot taken: {}", this.saveScreenshotAs(path)); } finally { // set back original driver for this thread this.set(driver); phantomJs.close(); phantomJs.quit(); } }
From source file:com.thoughtworks.selenium.webdriven.commands.GetCookie.java
License:Apache License
@Override protected String handleSeleneseCommand(WebDriver driver, String ignored, String alsoIgnored) { StringBuilder builder = new StringBuilder(); for (Cookie c : driver.manage().getCookies()) { builder.append(c.toString()); builder.append("; "); }/* ww w . ja v a2 s .c o m*/ return builder.toString(); }
From source file:org.wso2.carbon.appmanager.integration.ui.Util.APPMPublisherRestClient.java
License:Open Source License
/** * logs in to the publisher//from w w w . ja v a2s . c o m * * @param userName * @param password * @return * @throws Exception */ public String login(String userName, String password) throws Exception { WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username"))); // find element username WebElement usernameEle = driver.findElement(By.id("username")); // fill user name usernameEle.sendKeys(userName); // find element password wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password"))); WebElement passwordEle = driver.findElement(By.id("password")); // fill element passwordEle.sendKeys(password); // find submit button and click on it. wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("btn-primary"))); driver.findElement(By.className("btn-primary")).click(); // get the current String redirectedUrl = driver.getCurrentUrl(); // parsing url URL aURL = new URL(redirectedUrl); Set<org.openqa.selenium.Cookie> allCookies = driver.manage().getCookies(); for (org.openqa.selenium.Cookie loadedCookie : allCookies) { // get /publisher cookie if (loadedCookie.getPath().equals("/publisher/")) { this.setSession(loadedCookie.toString()); } } String urlPath = aURL.getPath(); //driver.quit(); if ((urlPath.equals("/publisher/assets/webapp/"))) { return "logged in"; } else { return "not logged in"; } }
From source file:org.wso2.carbon.appmanager.tests.util.APPMPublisherRestClient.java
License:Open Source License
/** * logs in to the user store// www.java2 s .com * * @param userName * @param password * @return * @throws Exception */ public String login(String userName, String password) throws Exception { // find element username WebElement usernameEle = driver.findElement(By.id("username")); // fill user name usernameEle.sendKeys("admin"); // find element password WebElement passwordEle = driver.findElement(By.id("password")); // fill element passwordEle.sendKeys("admin"); // find submit button and click on it. driver.findElement(By.className("btn-primary")).click(); // get the current String redirectedUrl = driver.getCurrentUrl(); // parsing url URL aURL = new URL(redirectedUrl); Set<org.openqa.selenium.Cookie> allCookies = driver.manage().getCookies(); for (org.openqa.selenium.Cookie loadedCookie : allCookies) { // get /publisher cookie if (loadedCookie.getPath().equals("/publisher/")) { this.setSession(loadedCookie.toString()); // System.out.println(loadedCookie.toString()); } } String urlPath = aURL.getPath(); driver.quit(); if ((urlPath.equals("/publisher/assets/webapp/"))) { return "logged in"; } else { return "not logged in"; } }