Commit 4c6610a0 authored by Michael Suzuki's avatar Michael Suzuki
Browse files

tidy amp demo,and added mechanism to slow test down to allow every one to see...

tidy amp demo,and added mechanism to slow test down to allow every one to see the demo page with selenium
parent 8e10982a
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -68,5 +68,16 @@
            <groupId>${alfresco.groupId}</groupId>
            <artifactId>alfresco-repository</artifactId>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.39.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>servlet-api-2.5</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>
+16 −4
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 */
package org.alfresco.demoamp;

import org.alfresco.demoamp.po.HelloWorldPage;
import org.alfresco.demoamp.po.DemoPage;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -43,17 +43,22 @@ public class DemoTestIT
    
    @AfterClass
    public static void teardown()
    {
        if(driver != null)
        {
            driver.quit();
        }
    }

    @Test
    public void titleDisplayed()
    {
        HelloWorldPage page = new HelloWorldPage(driver);
        DemoPage page = new DemoPage(driver);
        Assert.assertNotNull(page);
        Assert.assertTrue(page.isTitleVisible());
        Assert.assertEquals("Welcome to Demoamp", page.getTitle());
    }
    
    /**
     * Message should include the directory name
     * and number of folders currently in that directory.
@@ -61,9 +66,16 @@ public class DemoTestIT
    @Test
    public void messageIsDisplayed()
    {
        HelloWorldPage page = new HelloWorldPage(driver);
        DemoPage page = new DemoPage(driver);
        Assert.assertNotNull(page);
        Assert.assertTrue(page.isMessageVisible());
        Assert.assertEquals("Company Home has 7 folders", page.getMessage());
    }

    @Test
    public void findLogo()
    {
        DemoPage page = new DemoPage(driver);
        Assert.assertFalse(page.hasLogo());
    }
}
+53 −3
Original line number Diff line number Diff line
@@ -14,14 +14,22 @@
 */
package org.alfresco.demoamp.po;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.FluentWait;

import com.google.common.base.Predicate;
/**
 * Hello World Page object used in Summit Demo.
 * Demo page object that encapsulates the demo webscript hello world page.
 * @author Michael Suzuki
 *
 */
public class HelloWorldPage
public class DemoPage
{
    private static final By TITLE_LOCATOR = By.id("demo-title");
    private static final By MESSAGE_LOCATOR = By.id("demo-message");
@@ -31,7 +39,7 @@ public class HelloWorldPage
     * Constructor
     * @param driver
     */
    public HelloWorldPage(WebDriver driver)
    public DemoPage(WebDriver driver)
    {
        this.driver = driver;
    }
@@ -53,4 +61,46 @@ public class HelloWorldPage
    {
        return driver.findElement(MESSAGE_LOCATOR).getText();
    }
    /**
     * Sample find with wait element to keep searching for a set time.
     * @return true if the logo is exists
     */
    public boolean hasLogo()
    {
        try
        {
            return findAndWait(By.id("logo"), 6000, 1000).isDisplayed();
            
        }
        catch(TimeoutException te){ }
        return false;
    }
    /**
     * Mechanism to keep looking for an element on the page.
     * @param by selector
     * @param limit max time to wait in ms
     * @param interval time to wait between calls in ms
     * @return
     */
    public WebElement findAndWait(final By by, final long limit, final long interval)
    {
        FluentWait<By> fluentWait = new FluentWait<By>(by);
        fluentWait.pollingEvery(interval, TimeUnit.MILLISECONDS);
        fluentWait.withTimeout(limit, TimeUnit.MILLISECONDS);
        fluentWait.until(new Predicate<By>()
        {
            public boolean apply(By by)
            {
                try
                {
                    return driver.findElement(by).isDisplayed();
                }
                catch (NoSuchElementException ex)
                {
                    return false;
                }
            }
        });
        return driver.findElement(by);
    }
}
+17 −1
Original line number Diff line number Diff line
@@ -25,9 +25,11 @@
package org.alfresco.demoamp;

/**
 * This class does nothing except dump some output to <i>system.out</i>.
 * This is a simple class that generates a message for demo hello world,
 * and also outputs to <i>system.out</i> a message.
 * NB: This code is taken from Alfresco Eclipse SDK Samples 
 * @author Derek Hulley
 * @author Michael Suzuki
 */
public class Demo
{
@@ -35,4 +37,18 @@ public class Demo
    {
        System.out.println("SDK Demo AMP class has been loaded");
    }
    /**
     * Generates a message.
     * @param directoryName String directory identifier
     * @param folders int count of folders for that directory
     * @return String message 
     */
    public static String generateMessage(final String directoryName, final int folders)
    {
        if(directoryName == null || directoryName.isEmpty())
        {
            throw new RuntimeException("Directory name is required");
        }
        return String.format("%s has %d folders", directoryName, folders);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public class DemoComponent extends DeclarativeWebScript
        NodeRef companyHome = getCompanyHome();
        String companyHomeName = (String) nodeService.getProperty(companyHome, ContentModel.PROP_NAME);
        int directoryCount = childNodesCount(companyHome);
        HelloWorldMessage msg = new HelloWorldMessage(companyHomeName, directoryCount);
        String msg = Demo.generateMessage(companyHomeName, directoryCount);
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("demoMessage", msg);
        return model;
Loading