use of com.lazerycode.ebselen.handlers.FileHandler in project Ebselen by Ardesco.
the class IDEToEbselen method createFileList.
/**
* Traverse directory and create a list of all the files that need to be converted
*/
public void createFileList() throws Exception {
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);
}
}
use of com.lazerycode.ebselen.handlers.FileHandler in project Ebselen by Ardesco.
the class IDEToEbselen method generateJavaFile.
/**
* 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() + "'");
}
use of com.lazerycode.ebselen.handlers.FileHandler in project Ebselen by Ardesco.
the class IDEToEbselen method convertToXML.
/**
* 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();
}
use of com.lazerycode.ebselen.handlers.FileHandler in project Ebselen by Ardesco.
the class IDEToEbselen method generateTestCode.
/**
* 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];
}
use of com.lazerycode.ebselen.handlers.FileHandler in project Ebselen by Ardesco.
the class CompareImages method compareImages.
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;
}
Aggregations