package com.redheap.selenium;

import com.redheap.selenium.pages.FileExplorer;
import com.redheap.selenium.pages.RichClientDemo;

import java.util.logging.Logger;

import org.junit.Assert;
import org.junit.Test;

public class RichClientDemoTest extends TestCaseBase<RichClientDemo> {

    private static final String HOME_PAGE = "http://jdevadf.oracle.com/adf-richclient-demo/faces/index.jspx";
    private static final Logger logger = Logger.getLogger(RichClientDemoTest.class.getName());

    public RichClientDemoTest() {
        super(HOME_PAGE, RichClientDemo.class);
    }

    @Test
    public void testHomepageLoad() {
        logger.info("***** testHomepageLoad");
        getPage();
    }

    @Test
    public void testNavigationToFileExplorer() throws Exception {
        logger.info("***** testNavigationToFileExplorer");
        FileExplorer page = getPage().clickFileExplorerLink().clickTreeTableTab();
        //page.getScreenshotAs(new ScreenshotFile(new File("explorer-tree-table.png")));
    }

    @Test
    public void testExpandTagGuideNodeA() {
        logger.info("***** testExpandTagGuideNodeA");
        RichClientDemo page = getPage();
        int expandedNodesBefore = page.getTagGuideTreeExpandedNodeCount();
        page.clickLayoutTreeNode();
        Assert.assertEquals("number of expanded node should increase", expandedNodesBefore + 1,
                            page.getTagGuideTreeExpandedNodeCount());
    }

    @Test
    public void testExpandTagGuideNodeB() {
        // test the same as testExpandTagGuideNode to make sure cookies were cleared between tests so tree
        // should start with collapsed nodes again (not clearing cookies retains state and thus collapsed state
        // from testExpandTagGuideNodeA test)
        logger.info("***** testExpandTagGuideNodeB");
        RichClientDemo page = getPage();
        int expandedNodesBefore = page.getTagGuideTreeExpandedNodeCount();
        page.clickLayoutTreeNode();
        Assert.assertEquals("number of expanded node should increase", expandedNodesBefore + 1,
                            page.getTagGuideTreeExpandedNodeCount());
    }

    public static void main(String[] args) {
        String[] args2 = { RichClientDemoTest.class.getName() };
        org.junit.runner.JUnitCore.main(args2);
    }

}


@@ -24,16 +24,130 @@
 enium;%0A%0A
+import com.redheap.selenium.junit.SavePageSourceOnFailure;%0Aimport com.redheap.selenium.junit.ScreenshotOnFailure;%0A
 import c
@@ -237,16 +237,38 @@
 tDemo;%0A%0A
+import java.io.File;%0A%0A
 import j
@@ -335,20 +335,79 @@
 g.junit.
-Test
+Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.TestWatcher
 ;%0A%0Apubli
@@ -481,113 +481,234 @@
     
-private static final String HOME_PAGE = %22http://jdevadf.oracle.com/adf-richclient-demo/faces/index.jspx%22;
+@Rule%0A    public TestWatcher screenshotOnFailure = new ScreenshotOnFailure(getDriver(), new File(%22errors%22));%0A    @Rule%0A    public TestWatcher saveSourceOnFailure = new SavePageSourceOnFailure(getDriver(), new File(%22errors%22));%0A
 %0A   

include screenshot & source on failure