public CompareImages(String localFile, WebElement remoteImage, WebDriver driver) throws Exception { this.localFileObject = new FileHandler(localFile); this.remoteImageObject = remoteImage; this.driver = driver; }
public File getLocalImage() throws Exception { return this.localFileObject.getFile(); }
/** * Cleans the relevant file and generates a valid XML file ready for processing to Sel 2 java File. * * @param absoluteFilename - name of the file to convert. * @return String - location of the converted file. */ public String convertToXML(String absoluteFilename) throws Exception { FileHandler fromSelIDE = new FileHandler(absoluteFilename); FileHandler toXML = new FileHandler(System.getProperty("java.io.tmpdir") + File.separator + fromSelIDE.getFileName() + ".xml", true); if (fromSelIDE.getFile().isDirectory()) { LOGGER.error("Cannot convert directory {} into a Selenium Test!", fromSelIDE.getFileName()); return null; } //Clean up html so that we can read it as XML properly HtmlCleaner cleaner = new HtmlCleaner(); CleanerProperties XMLPrefs = cleaner.getProperties(); XMLPrefs.setUseEmptyElementTags(true); XMLPrefs.setTranslateSpecialEntities(true); XMLPrefs.setTransResCharsToNCR(true); XMLPrefs.setOmitComments(true); XMLPrefs.setOmitComments(true); XMLPrefs.setOmitDoctypeDeclaration(true); XMLPrefs.setNamespacesAware(false); TagNode tagNode = new HtmlCleaner(XMLPrefs).clean(fromSelIDE.getFile()); new PrettyXmlSerializer(XMLPrefs).writeToStream(tagNode, toXML.getWritableFileOutputStream(), "utf-8"); toXML.close(); return toXML.getAbsoluteFile(); }
FileHandler checkFileType = new FileHandler(startPoint); if (!checkFileType.getFile().isDirectory()) { LOGGER.error("The file '{}' is not a directory, will only try to convert this file...", checkFileType.getFileName()); if (checkFileType.getFile().isFile()) { fileList.add(checkFileType.getFilePath() + checkFileType.getFileName()); checkFileType.close(); return; checkFileType.close(); LOGGER.error("Scanning all files in the directory '{}'...", checkFileType.getFileName()); ArrayList scanList = new ArrayList(); scanList.add(startPoint); while (scanList.size() > 0) { FileHandler directoryToScan = new FileHandler(scanList.get(0).toString()); File[] listOfFiles = directoryToScan.getFile().listFiles(); for (File currentFile : listOfFiles) { FileHandler examineFile = new FileHandler(currentFile.getAbsolutePath()); if (!examineFile.getExtension().equals("java")) { if (examineFile.getFile().isFile()) { fileList.add(examineFile.getFilePath() + examineFile.getFileName()); } else if (examineFile.getFile().isDirectory()) { if (walkTree) { scanList.add(currentFile); examineFile.close(); directoryToScan.close(); scanList.remove(0);
/** * Writes Sky Selenium format test code into a Java file ready for tests to be run * * @param name - Name of the test * @throws Exception */ public void generateJavaFile(String name) throws Exception { Properties props = new Properties(); props.setProperty("resource.loader", "class"); props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); props.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader"); VelocityEngine ve = new VelocityEngine(props); VelocityContext context = new VelocityContext(); context.put("template", name); context.put("templateclass", name + ".class"); context.put("testname", name); context.put("testdata", testCode); Template ebselenTemplate = ve.getTemplate(ebselenTestTemplate); FileHandler convertedFile = new FileHandler(conversionLocation + File.separator + name + ".java", true); StringWriter writer = new StringWriter(); ebselenTemplate.merge(context, writer); convertedFile.write(writer.toString()); convertedFile.close(); LOGGER.info("Selenium IDE test converted and saved as '" + convertedFile.getFilePath() + convertedFile.getFileName() + "'"); }
client.setState(mimicCookieState(driver.manage().getCookies())); HttpMethod getRequest = new GetMethod(downloadURL.getPath()); FileHandler downloadedFile = new FileHandler(downloadPath + downloadURL.getFile().replaceFirst("/|\\\\", ""), true); try { int status = client.executeMethod(getRequest); byte[] block = new byte[len]; while ((bytes = in.read(block, offset, len)) > -1) { downloadedFile.getWritableFileOutputStream().write(block, 0, bytes); downloadedFile.close(); in.close(); LOGGER.info("File downloaded to '{}'", downloadedFile.getAbsoluteFile()); } catch (Exception Ex) { LOGGER.error("Download failed: {}", Ex); getRequest.releaseConnection(); return downloadedFile.getAbsoluteFile();
/** * Reads in a sky.sns.selenium IDE file and creates Sky Selenium format test code * * @param filename - Selenium IDE file to convert * @return Name of the Selenium IDE file * @throws Exception */ public String generateTestCode(String filename) throws Exception { FileHandler convertFrom = new FileHandler(convertToXML(filename)); XMLHandler seleniumXMLFile = new XMLHandler(convertFrom.getFile()); int commandCount = seleniumXMLFile.performXPathQueryReturnInteger("count(/html/body/table/tbody/tr)"); for (int i = 1; i <= commandCount; i++) { String command = ""; String target = ""; String value = ""; try { command = seleniumXMLFile.performXPathQueryReturnString("//table/tbody/tr[" + i + "]/td[1]"); target = seleniumXMLFile.performXPathQueryReturnString("/html/body/table/tbody/tr[" + i + "]/td[2]"); value = seleniumXMLFile.performXPathQueryReturnString("/html/body/table/tbody/tr[" + i + "]/td[3]"); } catch (Exception Ex) { LOGGER.warn("Invalid command '{}' found", command); } addToTestCode(codeGenerator.convertCommandToEbselenCode(command, target, value)); } convertFrom.close(); return convertFrom.getFileName().split("\\.")[0]; }
/** * Write the current XML object to file. * * @param absoluteFileName - Absolute filename to write XML object to * @return String - Directory that file has been written to * @throws Exception */ public String writeXMLFile(String absoluteFileName) throws Exception { if (this.xmlDocument == null) { LOGGER.error("The Document object is null, unable to generate a file!"); return null; } Source source = new DOMSource(this.xmlDocument); FileHandler outputFile = new FileHandler(absoluteFileName, true); try { Result output = new StreamResult(outputFile.getWriteableFile()); TransformerFactory.newInstance().newTransformer().transform(source, output); } catch (TransformerConfigurationException Ex) { LOGGER.error(" Error creating file: " + Ex); } catch (TransformerException Ex) { LOGGER.error(" Error creating file: " + Ex); } outputFile.close(); return outputFile.getAbsoluteFile(); } }
FileHandler cssStyle = new FileHandler(new File(this.htmlCSSFile)); cssStyle.copyFileTo(this.outputDirectory + cssStyle.getFileName());
public Boolean compareImages() throws Exception { FileDownloader downloadRemoteImage = new FileDownloader(driver); FileHandler downloadedImage = new FileHandler(downloadRemoteImage.imageDownloader(this.remoteImageObject)); if (generateMessageDigest(this.localFileObject.getFile()).equals(generateMessageDigest(downloadedImage.getFile()))) { return true; } return false; }
public CompareImages(File localFile, WebElement remoteImage, WebDriver driver) throws Exception { this.localFileObject = new FileHandler(localFile); this.remoteImageObject = remoteImage; this.driver = driver; }
public void changeLocalFileTo(File localfile) throws Exception { this.localFileObject = new FileHandler(localfile); }
public void changeLocalFileTo(String localfile) throws Exception { this.localFileObject = new FileHandler(localfile); }