Creating extent report
private void createBackgroundNode( String featureName) {
//String backGround = FeatureFileMap.values().stream().filter(p->p.contains("Background:")).f
int key = 0 ;
for(Map.Entry<Integer, String> entry :FeatureFileMap.entrySet()) {
if(entry.getValue().contains("Background:")){
System.out.println(entry.getKey());
key =entry.getKey();
break;
}
}
Markup m = MarkupHelper.createLabel("Background", ExtentColor.BLUE);
backGround = scenario.createNode(m.getMarkup());
while(true) {
key ++;
String stepDetails = FeatureFileMap.get(key);
String[] stepDetaislToken = stepDetails.trim().split("\\s",2);
if(stepDetaislToken.length < 2) {
continue;
}
String StepType = stepDetaislToken[0];
String StepDesc = stepDetaislToken[1];
if(stepDetails.contains("Scenario") ||stepDetails.contains("@")) {
System.out.println("Inside Scenaraio");
break;
}
Markup m2 = MarkupHelper.createLabel(StepType, ExtentColor.BLUE);
if(stepDetails.contains("Given")) {
ExtentTest stepNode = backGround.createNode(Given.class, m2.getMarkup()+""+StepDesc);
}
else if(stepDetails.contains("When")) {
ExtentTest stepNode = backGround.createNode(When.class, m2.getMarkup()+""+StepDesc);
}
else if(stepDetails.contains("Then")) {
ExtentTest stepNode = backGround.createNode(Then.class, m2.getMarkup()+""+StepDesc);
}
else if(stepDetails.contains("And")) {
ExtentTest stepNode = backGround.createNode(And.class, m2.getMarkup()+""+StepDesc);
}
else if(stepDetails.contains("But")) {
ExtentTest stepNode = backGround.createNode(But.class, m2.getMarkup()+""+StepDesc);
}
else {
break;
}
}
}
package util;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;
import org.apache.commons.io.FileUtils;
public class FileCopyUtil {
public static void main(String args[]) throws InterruptedException, ExecutionException {
System.out.println("Started...");
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> copyFile());
System.out.println("Waiting...");
System.out.println("Finally "+future.get());
}
private static String copyFile() {
File srcDir = new File(System.getProperty("user.dir") + "/extent");
if (!srcDir.exists()) {
return "FAIL: Src dir " + srcDir.getAbsolutePath() + "doesnot exists";
}
File destDir = new File(System.getProperty("user.dir") + "/newReport");
try {
// Thread.sleep(5000);
BasicFileAttributes attr = Files.readAttributes(srcDir.toPath(), BasicFileAttributes.class);
System.out.println(attr.creationTime());
FileUtils.moveDirectory(srcDir, destDir);
// boolean status = srcDir.renameTo(destDir);
return "SuCCESS";
} catch ( IOException e) {
e.printStackTrace();
}
return "FAIL";
}
}
public static String getPdfContent(String urlLink, int startPage, int endPage) {
PDDocument pdfDocument = null;
String docText = null;
URL url;
try {
url = new URL(urlLink);
pdfDocument = PDDocument.load(url.openStream());
PDFTextStripper pdfTextStripper = new PDFTextStripper();
pdfTextStripper.setStartPage(startPage);
pdfTextStripper.setEndPage(endPage);
docText = pdfTextStripper.getText(pdfDocument);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return docText;
}
public static String getPdfContent(String urlLink) {
PDDocument pdfDocument = null;
String docText = null;
URL url;
try {
url = new URL(urlLink);
pdfDocument = PDDocument.load(url.openStream());
PDFTextStripper pdfTextStripper = new PDFTextStripper();
docText = pdfTextStripper.getText(pdfDocument);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Number of Pages: " + pdfDocument.getPages().getCount());
return docText;
}
}