// Path: cubano-concordion/src/main/java/org/concordion/cubano/driver/concordion/pagegrabber/GrabWebPage.java
// public class GrabWebPage {
//     private static final Logger LOGGER = LoggerFactory.getLogger(GrabWebPage.class);
//     private WebDriver driver;
// 
//     /**
//      * Constructor.
//      *
//      * @param browser Browser driver
//      */
//     public GrabWebPage(WebDriver browser) {
//         this.driver = browser;
//     }
// 
// 
//     /**
//      * Save the page source and all linked resources that reside on the same host.
//      *
//      * @param outputDirPath Destination folder
//      * @param fileName      Name of HTML file
//      * @throws Exception exception
//      */
//     public void getWebPage(String outputDirPath, String fileName) throws Exception {
//         File outputDir = new File(outputDirPath);
// 
//         try {
//             if (outputDir.exists() && outputDir.isFile()) {
//                 throw new RuntimeException("output directory path is wrong, please provide some directory path");
//             } else if (!outputDir.exists()) {
//                 if (!outputDir.mkdirs()) {
//                     throw new IOException("Unable to create the folder " + outputDir.getPath());
//                 }
//             }
// 
//             // Output file name
//             File outputFile = new File(outputDir, fileName);
// 
//             // if file doesn't exists, then create it
//             if (!outputFile.exists()) {
//                 if (!outputFile.createNewFile()) {
//                     throw new IOException("Unable to create the file " + outputFile.getPath());
//                 }
//             }
// 
//             // can we write this file
//             if (!outputFile.canWrite()) {
//                 throw new IOException("Cannot write to file - " + outputFile.getAbsolutePath());
//             }
// 
//             LOGGER.debug("Downloading WebPage {}", driver.getCurrentUrl());
//             new GrabUtility(driver).savePageTo(outputDirPath, fileName);
// 
//         } catch (Exception e) {
//             LOGGER.error(e.getMessage());
//             throw e;
//         }
//     }
// }


import java.io.File;
import org.concordion.api.Element;
import org.concordion.api.Resource;
import org.concordion.cubano.driver.concordion.pagegrabber.GrabWebPage;
import org.concordion.ext.storyboard.Card;
import org.concordion.ext.storyboard.CardImage;
import org.concordion.ext.storyboard.StockCardImage;
import org.concordion.internal.ConcordionBuilder;
package org.concordion.cubano.driver.concordion;



/**
 * Downloads HTML etc for page under test for offline analysis.
 *
 * @author Andrew Sumner
 */
public class WebPageContentCard extends Card {
    private GrabWebPage pageGrabber;
    private String dataFileName = "";
    private CardImage cardImage = StockCardImage.HTML;

    protected void setPageGrabber(final GrabWebPage pageGrabber) {
        this.pageGrabber = pageGrabber;
    }

    @Override
    protected void captureData() {
        dataFileName = getFileName(getResource().getName(), getItemIndex(), "html");
        dataFileName = dataFileName.substring(0, dataFileName.length() - 5) + "/NoSuchElement.html";

        Resource resource = getResource().getRelativeResource(dataFileName);
        File file = new File(ConcordionBuilder.getBaseOutputDir(), resource.getPath());

        try {
            pageGrabber.getWebPage(file.getParent(), file.getName());
        } catch (Exception e) {
            // Unable to write file
            this.dataFileName = "";
        }
    }

    @Override
    protected void addHTMLToContainer(final Element container) {
        String imageName = getResource().getRelativePath(cardImage.getResource());

        Element img = new Element("img");
        img.setId(this.getDescription());
        img.addStyleClass("sizeheight");
        img.addAttribute("src", imageName);

// Path: cubano-concordion/src/main/java/org/concordion/cubano/driver/concordion/pagegrabber/GrabWebPage.java
// public class GrabWebPage {
//     private static final Logger LOGGER = LoggerFactory.getLogger(GrabWebPage.class);
//     private WebDriver driver;
// 
//     /**
//      * Constructor.
//      *
//      * @param browser Browser driver
//      */
//     public GrabWebPage(WebDriver browser) {
//         this.driver = browser;
//     }
// 
// 
//     /**
//      * Save the page source and all linked resources that reside on the same host.
//      *
//      * @param outputDirPath Destination folder
//      * @param fileName      Name of HTML file
//      * @throws Exception exception
//      */
//     public void getWebPage(String outputDirPath, String fileName) throws Exception {
//         File outputDir = new File(outputDirPath);
// 
//         try {
//             if (outputDir.exists() && outputDir.isFile()) {
//                 throw new RuntimeException("output directory path is wrong, please provide some directory path");
//             } else if (!outputDir.exists()) {
//                 if (!outputDir.mkdirs()) {
//                     throw new IOException("Unable to create the folder " + outputDir.getPath());
//                 }
//             }
// 
//             // Output file name
//             File outputFile = new File(outputDir, fileName);
// 
//             // if file doesn't exists, then create it
//             if (!outputFile.exists()) {
//                 if (!outputFile.createNewFile()) {
//                     throw new IOException("Unable to create the file " + outputFile.getPath());
//                 }
//             }
// 
//             // can we write this file
//             if (!outputFile.canWrite()) {
//                 throw new IOException("Cannot write to file - " + outputFile.getAbsolutePath());
//             }
// 
//             LOGGER.debug("Downloading WebPage {}", driver.getCurrentUrl());
//             new GrabUtility(driver).savePageTo(outputDirPath, fileName);
// 
//         } catch (Exception e) {
//             LOGGER.error(e.getMessage());
//             throw e;
//         }
//     }
// }


// Path: cubano-concordion/src/main/java/org/concordion/cubano/driver/concordion/WebPageContentCard.java
import java.io.File;
import org.concordion.api.Element;
import org.concordion.api.Resource;
import org.concordion.cubano.driver.concordion.pagegrabber.GrabWebPage;
import org.concordion.ext.storyboard.Card;
import org.concordion.ext.storyboard.CardImage;
import org.concordion.ext.storyboard.StockCardImage;
import org.concordion.internal.ConcordionBuilder;

package org.concordion.cubano.driver.concordion;



/**
 * Downloads HTML etc for page under test for offline analysis.
 *
 * @author Andrew Sumner
 */
public class WebPageContentCard extends Card {
    private GrabWebPage pageGrabber;
    private String dataFileName = "";
    private CardImage cardImage = StockCardImage.HTML;

    protected void setPageGrabber(final GrabWebPage pageGrabber) {
        this.pageGrabber = pageGrabber;
    }

    @Override
    protected void captureData() {
        dataFileName = getFileName(getResource().getName(), getItemIndex(), "html");
        dataFileName = dataFileName.substring(0, dataFileName.length() - 5) + "/NoSuchElement.html";

        Resource resource = getResource().getRelativeResource(dataFileName);
        File file = new File(ConcordionBuilder.getBaseOutputDir(), resource.getPath());

        try {
            pageGrabber.getWebPage(file.getParent(), file.getName());
        } catch (Exception e) {
            // Unable to write file
            this.dataFileName = "";
        }
    }

    @Override
    protected void addHTMLToContainer(final Element container) {
        String imageName = getResource().getRelativePath(cardImage.getResource());

        Element img = new Element("img");
        img.setId(this.getDescription());
        img.addStyleClass("sizeheight");
        img.addAttribute("src", imageName);

        if (dataFileName.isEmpty()) {