List of usage examples for org.openqa.selenium WebDriver getPageSource
String getPageSource();
From source file:org.surfnet.oaaas.selenium.SeleniumSupport.java
License:Apache License
private void consent(WebDriver webdriver) { // consent form assertThat(webdriver.getPageSource(), containsString("Grant permission")); webdriver.findElement(By.id("user_oauth_approval")).click(); }
From source file:org.tomitribe.tribestream.registryng.webapp.EditApplicationPage.java
License:Apache License
public void enterDescription(final WebDriver driver, final String newDescription) { System.out/*from w w w . j a va 2s .c o m*/ .println("Visible: " + descriptionField.findElement(By.cssSelector("div.preview p")).isDisplayed()); System.out .println("Description: " + descriptionField.findElement(By.cssSelector("div.preview p")).getText()); descriptionField.findElement(By.cssSelector("div.preview p")).click(); System.out.println(driver.getPageSource()); new WebDriverWait(driver, 5000) .until((Function<WebDriver, Boolean>) (dontcare -> confirmButton.isDisplayed())); descriptionField.findElement(By.tagName("p")).sendKeys(newDescription); confirmButton.click(); }
From source file:org.wso2.carbon.automation.test.utils.selenium.GRegSeleniumUtils.java
License:Open Source License
public static int getResourceId(WebDriver driver, String resourceName) { int pageCount = 10; int id = 0;//w w w .j av a 2s.c om long currentTime = System.currentTimeMillis(); long actualTime; do { if (driver.getPageSource().contains(resourceName)) { for (int i = 1; i <= pageCount; i++) { if (driver.findElement(By.id("resourceView" + i)).getText().equals(resourceName) || driver .findElement(By.id("resourceView" + i)).getText().equals(resourceName + " " + "..")) { return i; } } } actualTime = System.currentTimeMillis(); } while (!(((actualTime - currentTime) / 1000) > 10)); return id; }
From source file:org.wso2.carbon.automation.test.utils.selenium.StratosUserLogin.java
License:Open Source License
public static void userLogin(WebDriver driver, Selenium selenium, String userName, String password, String productName) throws InterruptedException { driver.findElement(By.xpath("//a[2]/img")).click(); driver.findElement(By.id("username")).sendKeys(userName); driver.findElement(By.id("password")).sendKeys(password); driver.findElement(By.xpath("//tr[4]/td[2]/input")).click(); if (productName.equalsIgnoreCase("manager")) { assertTrue(driver.findElement(By.id("middle")).findElement(By.id("cloudService")).getText() .contains("Application Server"), "Manager Home page Failed"); String pageSource = driver.getPageSource(); assertTrue(pageSource.contains("Mashup Server"), "Manager Home page Failed"); assertTrue(pageSource.contains("Identity Server"), "Manager Home page Failed"); assertTrue(pageSource.contains("Message Broker"), "Manager Home page Failed"); assertTrue(pageSource.contains("Enterprise Service Bus"), "Manager Home page Failed"); } else {/*w w w .jav a2 s. co m*/ assertTrue(driver.findElement(By.className("dashboard-title")).getText().toLowerCase() .contains("quick start dashboard"), "Failed to display service home Page :"); } }
From source file:org.xframium.device.artifact.api.PerfectoArtifactProducer.java
License:Open Source License
@Override protected Artifact _getArtifact(WebDriver webDriver, ArtifactType aType, Map<String, String> parameterMap, ConnectedDevice connectedDevice, String testName, boolean success) { String rootFolder = testName + System.getProperty("file.separator") + connectedDevice.getDevice().getKey() + System.getProperty("file.separator"); switch (aType) { case EXECUTION_DEFINITION: StringBuilder defBuilder = new StringBuilder(); defBuilder.append("DATE=").append(simpleDateFormat.format(new Date(System.currentTimeMillis()))) .append("\r\n"); defBuilder.append("TIME=").append(timeFormat.format(new Date(System.currentTimeMillis()))) .append("\r\n"); defBuilder.append("TEST_CASE=").append(testName).append("\r\n"); defBuilder.append("DEVICE=").append(connectedDevice.getDevice().getKey()).append("\r\n"); defBuilder.append("SUCCESS=").append(success).append("\r\n"); defBuilder.append("MANUFACTURER=").append(connectedDevice.getDevice().getManufacturer()).append("\r\n"); defBuilder.append("MODEL=").append(connectedDevice.getDevice().getModel()).append("\r\n"); return new Artifact(rootFolder + "executionDefinition.properties", defBuilder.toString().getBytes()); case EXECUTION_REPORT: case EXECUTION_REPORT_PDF: return generateExecutionReport("download", parameterMap, "pdf", rootFolder, aType); case FAILURE_SOURCE: return new Artifact(rootFolder + "failureDOM.xml", webDriver.getPageSource().getBytes()); case FAILURE_SOURCE_HTML: return new Artifact(rootFolder + "failureDOM.html", ("<html><head><link href=\"http://www.xframium.org/output/assets/css/prism.css\" rel=\"stylesheet\"><script src=\"http://www.xframium.org/output/assets/js/prism.js\"></script><body><pre class\"line-numbers\"><code class=\"language-markup\">" + webDriver.getPageSource().replace("<", "<").replace(">", ">").replace("\t", " ") + "</code></pre></body></html>").getBytes()); case CONSOLE_LOG: Artifact consoleArtifact = new Artifact(rootFolder + "console.txt", DeviceManager.instance().getLog().getBytes()); DeviceManager.instance().clearLog(); return consoleArtifact; case DEVICE_LOG: try {/*from w w w . jav a 2s .c om*/ ByteArrayInputStream inputStream = new ByteArrayInputStream( generateExecutionReport("download", parameterMap, "xml", rootFolder, aType) .getArtifactData()); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setNamespaceAware(true); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document xmlDocument = dBuilder.parse(inputStream); NodeList nodeList = getNodes(xmlDocument, "//dataItem[@type='log']/attachment"); if (nodeList != null && nodeList.getLength() > 0) { byte[] zipFile = PerfectoMobile.instance().reports().download(parameterMap.get(REPORT_KEY), nodeList.item(0).getTextContent(), false); ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(zipFile)); ZipEntry entry = zipStream.getNextEntry(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] bytesIn = new byte[512]; int bytesRead = 0; while ((bytesRead = zipStream.read(bytesIn)) != -1) { outputStream.write(bytesIn, 0, bytesRead); } zipStream.close(); return new Artifact(rootFolder + "deviceLog.txt", outputStream.toByteArray()); } return new Artifact(rootFolder + "deviceLog.txt", "Could not read file".getBytes()); } catch (Exception e) { log.error("Error download device log data", e); } return null; case EXECUTION_REPORT_CSV: return generateExecutionReport("download", parameterMap, "csv", rootFolder, aType); case EXECUTION_REPORT_HTML: return generateExecutionReport("download", parameterMap, "html", rootFolder, aType); case EXECUTION_REPORT_XML: return generateExecutionReport("download", parameterMap, "xml", rootFolder, aType); case EXECUTION_RECORD_CSV: return generateCSVRecord(connectedDevice.getPopulatedDevice(), testName, rootFolder); case EXECUTION_RECORD_HTML: return generateHTMLRecord(connectedDevice.getPopulatedDevice(), testName, rootFolder, webDriver); case WCAG_REPORT: return generateWCAG(connectedDevice.getPopulatedDevice(), testName, rootFolder); default: return null; } }
From source file:org.xframium.device.artifact.api.SauceLabsArtifactProducer.java
License:Open Source License
@Override protected Artifact _getArtifact(WebDriver webDriver, ArtifactType aType, Map<String, String> parameterMap, ConnectedDevice connectedDevice, String testName, boolean success) { String rootFolder = testName + System.getProperty("file.separator") + connectedDevice.getDevice().getKey() + System.getProperty("file.separator"); try {/*from w w w . jav a2 s .c om*/ switch (aType) { case EXECUTION_DEFINITION: StringBuilder defBuilder = new StringBuilder(); defBuilder.append("DATE=").append(simpleDateFormat.format(new Date(System.currentTimeMillis()))) .append("\r\n"); defBuilder.append("TIME=").append(timeFormat.format(new Date(System.currentTimeMillis()))) .append("\r\n"); defBuilder.append("TEST_CASE=").append(testName).append("\r\n"); defBuilder.append("DEVICE=").append(connectedDevice.getDevice().getKey()).append("\r\n"); defBuilder.append("SUCCESS=").append(success).append("\r\n"); defBuilder.append("MANUFACTURER=").append(connectedDevice.getDevice().getManufacturer()) .append("\r\n"); defBuilder.append("MODEL=").append(connectedDevice.getDevice().getModel()).append("\r\n"); return new Artifact(rootFolder + "executionDefinition.properties", defBuilder.toString().getBytes()); /*case EXECUTION_REPORT: case EXECUTION_REPORT_PDF: return generateExecutionReport( connectedDevice.getPopulatedDevice(), "download", parameterMap, "pdf", rootFolder, aType );*/ case FAILURE_SOURCE: return new Artifact(rootFolder + "failureDOM.xml", webDriver.getPageSource().getBytes()); case FAILURE_SOURCE_HTML: return new Artifact(rootFolder + "failureDOM.html", ("<html><head><link href=\"http://www.xframium.org/output/assets/css/prism.css\" rel=\"stylesheet\"><script src=\"http://www.xframium.org/output/assets/js/prism.js\"></script><body><pre class\"line-numbers\"><code class=\"language-markup\">" + webDriver.getPageSource().replace("<", "<").replace(">", ">").replace("\t", " ") + "</code></pre></body></html>").getBytes()); case CONSOLE_LOG: Artifact consoleArtifact = new Artifact(rootFolder + "console.txt", DeviceManager.instance().getLog().getBytes()); DeviceManager.instance().clearLog(); return consoleArtifact; case DEVICE_LOG: try { if (DataManager.instance().isArtifactEnabled(ArtifactType.SAUCE_LABS)) { CloudDescriptor currentCloud = CloudRegistry.instance().getCloud(); if (connectedDevice.getDevice().getCloud() != null && !connectedDevice.getDevice().getCloud().isEmpty()) currentCloud = CloudRegistry.instance() .getCloud(connectedDevice.getDevice().getCloud()); if (currentCloud.getProvider().equals("SAUCELABS")) { SauceREST sR = new SauceREST(currentCloud.getUserName(), currentCloud.getPassword()); return new Artifact(rootFolder + "deviceLog.txt", sR.downloadLog(connectedDevice.getExecutionId())); } } else { return null; } } catch (Exception e) { log.error("Error download device log data", e); } return null; case EXECUTION_RECORD_CSV: return generateCSVRecord(connectedDevice.getPopulatedDevice(), testName, rootFolder); case EXECUTION_RECORD_HTML: return generateHTMLRecord(connectedDevice.getPopulatedDevice(), testName, rootFolder, webDriver); case WCAG_REPORT: return generateWCAG(connectedDevice.getPopulatedDevice(), testName, rootFolder); default: return null; } } catch (Exception e) { return new Artifact(rootFolder + "generationFailure.txt", e.getMessage().getBytes()); } }
From source file:org.xframium.device.artifact.api.SeleniumArtifactProducer.java
License:Open Source License
@Override protected Artifact _getArtifact(WebDriver webDriver, ArtifactType aType, Map<String, String> parameterMap, ConnectedDevice connectedDevice, String testName, boolean success) { String rootFolder = testName + System.getProperty("file.separator") + connectedDevice.getDevice().getKey() + System.getProperty("file.separator"); switch (aType) { case FAILURE_SOURCE: return new Artifact(rootFolder + "failureDOM.xml", webDriver.getPageSource().getBytes()); case FAILURE_SOURCE_HTML: return new Artifact(rootFolder + "failureDOM.html", ("<html><head><link href=\"http://www.xframium.org/output/assets/css/prism.css\" rel=\"stylesheet\"><script src=\"http://www.xframium.org/output/assets/js/prism.js\"></script><body><pre class\"line-numbers\"><code class=\"language-markup\">" + webDriver.getPageSource().replace("<", "<").replace(">", ">").replace("\t", " ") + "</code></pre></body></html>").getBytes()); case EXECUTION_DEFINITION: StringBuilder defBuilder = new StringBuilder(); defBuilder.append("DATE=").append(simpleDateFormat.format(new Date(System.currentTimeMillis()))) .append("\r\n"); defBuilder.append("TIME=").append(timeFormat.format(new Date(System.currentTimeMillis()))) .append("\r\n"); defBuilder.append("TEST_CASE=").append(testName).append("\r\n"); defBuilder.append("DEVICE=").append(connectedDevice.getDevice().getKey()).append("\r\n"); defBuilder.append("SUCCESS=").append(success).append("\r\n"); defBuilder.append("MANUFACTURER=").append(connectedDevice.getDevice().getManufacturer()).append("\r\n"); defBuilder.append("MODEL=").append(connectedDevice.getDevice().getBrowserName()).append("\r\n"); return new Artifact(rootFolder + "executionDefinition.properties", defBuilder.toString().getBytes()); case CONSOLE_LOG: Artifact consoleArtifact = new Artifact(rootFolder + "console.txt", DeviceManager.instance().getLog().getBytes()); DeviceManager.instance().clearLog(); return consoleArtifact; case DEVICE_LOG: try {//from w w w .j a v a2s . c om LogEntries logEntries = webDriver.manage().logs().get(LogType.BROWSER); if (logEntries != null) { StringBuilder logBuilder = new StringBuilder(); for (LogEntry logEntry : logEntries) logBuilder.append(dateFormat.format(new Date(logEntry.getTimestamp()))).append(": ") .append(logEntry.getMessage()).append("\r\n"); return new Artifact(rootFolder + "deviceLog.txt", logBuilder.toString().getBytes()); } return null; } catch (Exception e) { log.info("Could not generate device logs"); return null; } case EXECUTION_RECORD_CSV: return generateCSVRecord(connectedDevice.getDevice(), testName, rootFolder); case EXECUTION_RECORD_HTML: return generateHTMLRecord(connectedDevice.getDevice(), testName, rootFolder, webDriver); case WCAG_REPORT: return generateWCAG(connectedDevice.getDevice(), testName, rootFolder); default: return null; } }
From source file:org.xframium.gesture.device.action.spi.perfecto.DumpStateAction.java
License:Open Source License
@Override public boolean _executeAction(WebDriver webDriver, List<Object> parameterList) { String executionId = getExecutionId(webDriver); String deviceName = getDeviceName(webDriver); long timeKey = System.currentTimeMillis(); Resolution resolution = Resolution.valueOf(((String) parameterList.get(0)).toLowerCase()); String rootFolder = System.getProperty("__outputFolder"); if (parameterList.size() > 1) rootFolder = (String) parameterList.get(1); File outputFile = new File(new File(rootFolder, executionId), timeKey + ".png"); File DOMFile = new File(new File(rootFolder, executionId), timeKey + ".xml"); String fileKey = "PRIVATE:" + deviceName + ".png"; PerfectoMobile.instance().imaging().screenShot(executionId, deviceName, fileKey, Screen.primary, ImageFormat.png, resolution); byte[] imageData = PerfectoMobile.instance().repositories().download(RepositoryType.MEDIA, fileKey); try {/* w ww . ja v a 2 s . c o m*/ FileOutputStream outputStream = new FileOutputStream(outputFile); outputStream.write(imageData); outputStream.flush(); outputStream.close(); outputStream = new FileOutputStream(DOMFile); outputStream.write(XMLEscape.toXML(webDriver.getPageSource()).getBytes()); outputStream.flush(); outputStream.close(); return true; } catch (Exception e) { throw new IllegalArgumentException("Could not write to file", e); } }
From source file:org.xframium.page.keyWord.step.spi.KWSDumpState.java
License:Open Source License
@Override public synchronized boolean _executeStep(Page pageObject, WebDriver webDriver, Map<String, Object> contextMap, Map<String, PageData> dataMap, Map<String, Page> pageMap) { long startTime = System.currentTimeMillis(); File rootFolder = new File(DataManager.instance().getReportFolder(), RunDetails.instance().getRootFolder()); File useFolder = new File(rootFolder, "artifacts"); useFolder.mkdirs();/*from w w w .ja v a 2s.c o m*/ File screenFile = null; File domFile = null; ; if (webDriver instanceof TakesScreenshot) { OutputStream os = null; try { byte[] screenShot = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.BYTES); screenFile = File.createTempFile("state", ".png", useFolder); screenFile.getParentFile().mkdirs(); os = new BufferedOutputStream(new FileOutputStream(screenFile)); os.write(screenShot); os.flush(); os.close(); } catch (Exception e) { log.error("Error taking screenshot", e); try { os.close(); } catch (Exception e2) { } } finally { if (os != null) try { os.close(); } catch (Exception e) { } } } FileOutputStream outputStream = null; try { File xmlFile = File.createTempFile("dom-", ".xml", useFolder); domFile = new File(xmlFile.getParentFile(), xmlFile.getName().replace(".xml", ".html")); String pageSource = webDriver.getPageSource(); outputStream = new FileOutputStream(xmlFile); if (ApplicationRegistry.instance().getAUT().isWeb()) outputStream.write(XMLEscape.toXML(pageSource).getBytes()); else outputStream.write(XMLEscape.toHTML(pageSource).getBytes()); outputStream.flush(); outputStream.close(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append( "<html><head><link href=\"http://www.xframium.org/output/assets/css/prism.css\" rel=\"stylesheet\"><script src=\"http://www.xframium.org/output/assets/js/prism.js\"></script>"); stringBuilder.append("</script></head><body><pre class\"line-numbers\"><code class=\"language-markup\">" + pageSource.replace("<", "<").replace(">", ">").replace("\t", " ") + "</code></pre></body></html>"); outputStream = new FileOutputStream(domFile); outputStream.write(stringBuilder.toString().getBytes()); outputStream.flush(); outputStream.close(); } catch (Exception e) { throw new IllegalArgumentException("Could not write to file", e); } finally { if (outputStream != null) try { outputStream.close(); } catch (Exception e) { } } String files = domFile.getName() + (screenFile != null ? ("," + screenFile.getName()) : ""); PageManager.instance().addExecutionLog(getExecutionId(webDriver), getDeviceName(webDriver), files, getName(), "KWSDumpState", startTime, System.currentTimeMillis() - startTime, StepStatus.SUCCESS, "", null, getThreshold(), getDescription(), false, null); return true; }
From source file:plugin.shiro.authz.RequireAtControllerTestCase.java
License:Open Source License
@Test @RunAsClient// ww w.j a v a2 s.c o m public void test() throws Exception { driver.get(deploymentURL.toString()); assertNotNull(exception); assertTrue(exception instanceof AuthorizationException); WebElement view = driver.findElement(By.id("view")); view.click(); waitForPresent("Unauthorized"); driver.get(deploymentURL.toString()); WebElement resource = driver.findElement(By.id("resource")); resource.click(); ExpectedCondition<Boolean> c = new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver input) { return input.getPageSource().equals("Unauthorized"); } }; assertTrue(new WebDriverWait(driver, 10).until(c)); driver.get(deploymentURL.toString()); WebElement action = driver.findElement(By.id("action")); action.click(); waitForPresent("Unauthorized"); }