enabled windmill-based UI testing (type ./gridworks test to try)

git-svn-id: http://google-refine.googlecode.com/svn/trunk@406 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-04-07 08:28:53 +00:00
parent 6114530723
commit 6dbe794658
3 changed files with 151 additions and 59 deletions

156
gridworks
View File

@ -19,6 +19,11 @@ error() {
exit 1 exit 1
} }
warn() {
echo "$1"
exit 0
}
usage() { usage() {
cat <<EOF cat <<EOF
Usage: $0 [options] <action> Usage: $0 [options] <action>
@ -82,6 +87,37 @@ check_macosx() {
fi fi
} }
check_downloaders() {
CURL="`which curl`"
WGET="`which wget`"
if [ "$CURL" == "" ] && [ "$WGET" == "" ]; then
error "We need either 'curl' or 'wget' present in PATH to download external dependencies."
fi
}
check_python() {
PYTHON="`which python`"
if [ "$PYTHON" == "" ] ; then
error "This action requires you to have 'python' installed. You can download it for free at http://www.python.org/"
fi
PYTHON_VERSION="`python --version 2>&1 | cut -f 2 -d ' ' | cut -f 1,2 -d .`"
if [ "$PYTHON_VERSION" != "2.5" ] && [ "$PYTHON_VERSION" != "2.6" ] ; then
error "This action requires python version 2.5.x or 2.6.x. You can download it for free at http://www.python.org/"
fi
}
check_running() {
check_downloaders
URL="http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/"
if [ "$CURL" != "" ] ; then
NOT_RUNNING=`curl -s $URL > /dev/null || echo not_running`
elif [ "$WGET" != "" ] ; then
NOT_RUNNING=`wget -q -O - $URL > /dev/null || echo not_running`
fi
}
get_version() { get_version() {
VERSION=$1 VERSION=$1
@ -104,24 +140,16 @@ get_revision() {
REVISION=`echo $INFO | sed 's/.*Revision: /r/' | sed 's/ .*//'` REVISION=`echo $INFO | sed 's/.*Revision: /r/' | sed 's/ .*//'`
} }
get_url_file() {
return `echo $1 | sed 's|.*/||'`
}
download() { download() {
URL=$1 URL=$1
DEST=$2 DEST=$2
CURL="`which curl`"
WGET="`which wget`"
if [ "$CURL" == "" ] && [ "$WGET" == "" ]; then check_downloaders
error "We need either 'curl' or 'wget' present in PATH to download external dependencies."
fi
if [ "$CURL" != "" ] ; then if [ "$CURL" != "" ] ; then
curl -L -o $DEST $URL || exit 1 curl -L -o $DEST $URL || exit "Error while downloading $URL"
elif [ "$WGET" != "" ] ; then elif [ "$WGET" != "" ] ; then
wget -O $DEST $URL || exit 1 wget -O $DEST $URL || error "Error while downloading $URL"
fi fi
} }
@ -135,28 +163,42 @@ tool_download() {
download $URL $FILE download $URL $FILE
fi fi
if [ ! -d "$DIR" ] ; then if [ ! -d "$DIR" ] ; then
tar xzf $FILE || exit 1 tar xzf $FILE || error "Error while expanding $FILE"
fi fi
cd .. cd ..
} }
load_data() {
FILE=$1
NAME=$2
URL="http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/command/create-project-from-upload"
CURL="`which curl`"
if [ "$CURL" == "" ] ; then
error "We need 'curl' present in PATH to upload data to gridworks."
else
curl -s -F "project-file=@$FILE" -F "project-name=$NAME" $URL > /dev/null || error "Error while uploading $FILE to Gridworks"
echo "Loaded $FILE as $NAME"
fi
}
# ---------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
build_prepare() { build_prepare() {
if [ ! -d $GRIDWORKS_BUILD_DIR ] ; then if [ ! -d $GRIDWORKS_BUILD_DIR ] ; then
mkdir $GRIDWORKS_BUILD_DIR || exit 1 mkdir $GRIDWORKS_BUILD_DIR || error "Error while making directory $GRIDWORKS_BUILD_DIR"
fi fi
} }
dist_prepare() { dist_prepare() {
if [ ! -d $GRIDWORKS_DIST_DIR ] ; then if [ ! -d $GRIDWORKS_DIST_DIR ] ; then
mkdir $GRIDWORKS_DIST_DIR || exit 1 mkdir $GRIDWORKS_DIST_DIR || error "Error while making directory $GRIDWORKS_DIST_DIR"
fi fi
} }
tools_prepare() { tools_prepare() {
if [ ! -d $GRIDWORKS_TOOLS_DIR ] ; then if [ ! -d $GRIDWORKS_TOOLS_DIR ] ; then
mkdir $GRIDWORKS_TOOLS_DIR || exit 1 mkdir $GRIDWORKS_TOOLS_DIR || error "Error while making directory $GRIDWORKS_TOOLS_DIR"
fi fi
} }
@ -173,7 +215,7 @@ ant_prepare() {
download $ANT_URL $ANT_FILE download $ANT_URL $ANT_FILE
fi fi
if [ ! -d $ANT_DIR ] ; then if [ ! -d $ANT_DIR ] ; then
tar xzf $ANT_FILE -C . || exit 1 tar xzf $ANT_FILE -C . || error "Error while expanding $ANT_FILE"
fi fi
export ANT_HOME="`pwd`/$ANT_DIR" export ANT_HOME="`pwd`/$ANT_DIR"
cd .. cd ..
@ -203,6 +245,9 @@ jarbundler_prepare() {
} }
windmill_prepare() { windmill_prepare() {
WINDMILL="`which windmill`"
if [ "$WINDMILL" == "" ] ; then
check_python
tools_prepare tools_prepare
WINDMILL_URL="http://github.com/windmill/windmill/tarball/1.3beta2" WINDMILL_URL="http://github.com/windmill/windmill/tarball/1.3beta2"
@ -210,6 +255,19 @@ windmill_prepare() {
WINDMILL_DIR="windmill-1.3beta2" WINDMILL_DIR="windmill-1.3beta2"
tool_download $WINDMILL_URL $WINDMILL_FILE $WINDMILL_DIR tool_download $WINDMILL_URL $WINDMILL_FILE $WINDMILL_DIR
WINDMILL="$GRIDWORKS_TOOLS_DIR/windmill"
if [ ! -f $WINDMILL ] ; then
cd $GRIDWORKS_TOOLS_DIR
WINDMILL_SRC=`find . -type d -depth 1 | grep windmill`
cd $WINDMILL_SRC
echo "About to install Windmill with 'sudo', you might be asked to input your admin password"
WINDMILL=`sudo python setup.py develop | grep 'Installing windmill script to' | sed 's|.* /|/|'`/windmill
cd ..
ln -s $WINDMILL windmill
cd ..
fi
fi
} }
findbugs_prepare() { findbugs_prepare() {
@ -229,7 +287,7 @@ ant() {
#export ANT_OPTS="-Xmx1024M" #export ANT_OPTS="-Xmx1024M"
$ANT -f build.xml $ANT_PARAMS -Dbuild.dir="$GRIDWORKS_BUILD_DIR" -Ddist.dir="$GRIDWORKS_DIST_DIR" -Dversion="$VERSION" -Dnum_version="$NUM_VERSION" -Drevision="$REVISION" $1 || exit 1 $ANT -f build.xml $ANT_PARAMS -Dbuild.dir="$GRIDWORKS_BUILD_DIR" -Ddist.dir="$GRIDWORKS_DIST_DIR" -Dversion="$VERSION" -Dnum_version="$NUM_VERSION" -Drevision="$REVISION" $1 || error "Error while running ant task '$1'"
} }
# ---------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------
@ -282,7 +340,7 @@ mac_dist() {
get_revision get_revision
ANT_PARAMS="-Djarbundler.dir=${GRIDWORKS_TOOLS_DIR}/${JARBUNDLER_DIR}" ANT_PARAMS="-Djarbundler.dir=${GRIDWORKS_TOOLS_DIR}/${JARBUNDLER_DIR}"
ant mac || exit 1 ant mac
mkdir -p "$GRIDWORKS_BUILD_DIR/mac/.background" mkdir -p "$GRIDWORKS_BUILD_DIR/mac/.background"
cp src/graphics/dmg_background/dmg_background.png "$GRIDWORKS_BUILD_DIR/mac/.background/dmg_background.png" cp src/graphics/dmg_background/dmg_background.png "$GRIDWORKS_BUILD_DIR/mac/.background/dmg_background.png"
@ -297,7 +355,7 @@ mac_dist() {
echo "Building MacOSX DMG for $TITLE" echo "Building MacOSX DMG for $TITLE"
hdiutil create -srcfolder "$GRIDWORKS_BUILD_DIR/mac" -volname "$TITLE" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${SIZE}m "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" || error "can't create empty DMG" hdiutil create -srcfolder "$GRIDWORKS_BUILD_DIR/mac" -volname "$TITLE" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${SIZE}m "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" || error "can't create empty DMG"
DEVICE=`hdiutil attach -readwrite -noverify -noautoopen "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" | egrep '^/dev/' | sed 1q | awk '{print $1}'` DEVICE=`hdiutil attach -readwrite -noverify -noautoopen "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" | egrep '^/dev/' | sed 1q | awk '{print $1}'`
hdiutil attach "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" hdiutil attach "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" || error "Can't attach temp DMG"
echo ' echo '
tell application "Finder" tell application "Finder"
@ -321,11 +379,11 @@ mac_dist() {
eject eject
end tell end tell
end tell end tell
' | osascript || error "error running applescript" ' | osascript || error "Error running applescript"
sync sync
sync sync
hdiutil detach $DEVICE hdiutil detach $DEVICE || error "Error while detaching $DEVICE"
if [ -f "$GRIDWORKS_DIST_DIR/gridworks-$VERSION-$REVISION.dmg" ] ; then if [ -f "$GRIDWORKS_DIST_DIR/gridworks-$VERSION-$REVISION.dmg" ] ; then
rm "$GRIDWORKS_DIST_DIR/gridworks-$VERSION-$REVISION.dmg" rm "$GRIDWORKS_DIST_DIR/gridworks-$VERSION-$REVISION.dmg"
@ -338,12 +396,36 @@ mac_dist() {
} }
test() { test() {
ui_test $1
server_test $1 server_test $1
ui_test $1
} }
ui_test() { ui_test() {
windmill_prepare windmill_prepare
GRIDWORKS_DATA_DIR="${GRIDWORKS_TEST_DIR}/temp"
add_option "-Dgridworks.headless=true"
run fork
echo "Waiting for Gridworks to load..."
sleep 5
echo "... proceed with the tests."
echo ""
load_data "$GRIDWORKS_TEST_DIR/data/food.csv" "Food"
sleep 3
echo ""
echo "Starting Windmill..."
$WINDMILL firefox http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/ test=$GRIDWORKS_TEST_DIR/windmill exit > /dev/null
echo ""
echo "Killing Gridworks"
kill -9 $GRIDWORKS_PID
echo "Cleaning up"
rm -rf $GRIDWORKS_DATA_DIR
} }
server_test() { server_test() {
@ -364,13 +446,15 @@ server_test() {
RUN_CMD="$JAVA -cp $CLASSPATH $OPTS org.junit.runner.JUnitCore $TESTS" RUN_CMD="$JAVA -cp $CLASSPATH $OPTS org.junit.runner.JUnitCore $TESTS"
echo "$RUN_CMD" #echo "$RUN_CMD"
echo "" #echo ""
exec $RUN_CMD $RUN_CMD || error "Failed passing server tests"
} }
run() { run() {
FORK=$1
if [ ! -d $GRIDWORKS_BUILD_DIR/classes ] ; then if [ ! -d $GRIDWORKS_BUILD_DIR/classes ] ; then
is_jar=`ls $GRIDWORKS_LIB_DIR | grep gridworks` is_jar=`ls $GRIDWORKS_LIB_DIR | grep gridworks`
if [ "$is_jar" == "" ] ; then if [ "$is_jar" == "" ] ; then
@ -379,6 +463,12 @@ run() {
fi fi
fi fi
check_running
if [ "$NOT_RUNNING" == "" ] ; then
warn "Gridworks is already running."
fi
if [ -d $GRIDWORKS_BUILD_DIR/classes ] ; then if [ -d $GRIDWORKS_BUILD_DIR/classes ] ; then
add_option "-Dgridworks.autoreloading=true" add_option "-Dgridworks.autoreloading=true"
fi fi
@ -395,12 +485,18 @@ run() {
RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.metaweb.gridworks.Gridworks" RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.metaweb.gridworks.Gridworks"
echo "Starting Gridworks at 'http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/'"
echo ""
#echo "$RUN_CMD" #echo "$RUN_CMD"
#echo "" #echo ""
exec $RUN_CMD echo "Starting Gridworks at 'http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/'"
echo ""
if [ "$FORK" == "" ] ; then
exec "$RUN_CMD"
else
sh -c "$RUN_CMD" &
GRIDWORKS_PID="$!"
fi
} }
execute() { execute() {
@ -413,8 +509,8 @@ execute() {
RUN_CMD="$JAVA -cp $CLASSPATH $OPTS $*" RUN_CMD="$JAVA -cp $CLASSPATH $OPTS $*"
echo "$RUN_CMD" #echo "$RUN_CMD"
echo "" #echo ""
exec $RUN_CMD $* exec $RUN_CMD $*
} }

View File

@ -104,8 +104,11 @@ public class Gridworks {
GridworksServer server = new GridworksServer(); GridworksServer server = new GridworksServer();
server.init(host,port); server.init(host,port);
boolean headless = Configurations.getBoolean("gridworks.headless",false);
if (!headless) {
GridworksClient client = new GridworksClient(); GridworksClient client = new GridworksClient();
client.init(host,port); client.init(host,port);
}
// hook up the signal handlers // hook up the signal handlers
new ShutdownSignalHandler("TERM", server); new ShutdownSignalHandler("TERM", server);

View File

@ -3,42 +3,40 @@ from windmill.authoring import WindmillTestClient
def test_gridworks(): def test_gridworks():
client = WindmillTestClient(__name__) client = WindmillTestClient(__name__)
#currently depends on their being a copy of food.csv # food.csv tests
#TODO get working with upload somehow client.click(link=u'Food')
client.click(link=u'WM Food 1')
client.waits.forPageLoad(timeout=u'20000') client.waits.forPageLoad(timeout=u'20000')
#create text facet from 1st word of Short Description # create text facet from 1st word of Short Description
filter_column(client, 'Shrt_Desc') filter_column(client, 'Shrt_Desc')
client.click(jquery=u'(".menu-item:contains(\'Custom Text Facet\')")[0]') client.click(jquery=u'(".menu-item:contains(\'Custom Text Facet\')")[0]')
client.type(jquery=u'(".expression-preview-code")[0]', text=u"value.split(',')[0]") client.type(jquery=u'(".expression-preview-code")[0]', text=u"value.split(',')[0]")
client.click(jquery=u'("button:contains(\'OK\')")[0]') client.click(jquery=u'("button:contains(\'OK\')")[0]')
assert_expected_top_value(client, 'SPAGHETTIOS')
client.click(jquery=u'("a:contains(\'re-sort by count\')")[0]') client.click(jquery=u'("a:contains(\'re-sort by count\')")[0]')
assert_expected_top_value(client, 'BEEF') assert_expected_top_value(client, 'BEEF')
#Filter down to BEEF. Result == 457 rows # Filter down to BEEF. Result == 457 rows
client.click(jquery=u'("a.facet-choice-label:contains(\'BEEF\')")[0]') client.click(jquery=u'("a.facet-choice-label:contains(\'BEEF\')")[0]')
client.asserts.assertText(jquery=u'("span.viewPanel-summary-row-count")[0]', validator=u'457') client.asserts.assertText(jquery=u'("span.viewPanel-summary-row-count")[0]', validator=u'457')
#create numeric filter from Water column # create numeric filter from Water column
#assert that there's NOT a facet panel named 'Water' yet # assert that there's NOT a facet panel named 'Water' yet
assert client.execJS(js=u'$(".facet-panel span:contains(\'Water\')").length')['output'] == 0 assert client.execJS(js=u'$(".facet-panel span:contains(\'Water\')").length')['output'] == 0
filter_column(client, 'Water') filter_column(client, 'Water')
client.click(jquery=u'(".menu-item:contains(\'Numeric Facet\')")[0]') client.click(jquery=u'(".menu-item:contains(\'Numeric Facet\')")[0]')
#assert that there's a facet panel named 'Water' # assert that there's a facet panel named 'Water'
assert client.execJS(js=u'$(".facet-panel span:contains(\'Water\')").length')['output'] > 0 assert client.execJS(js=u'$(".facet-panel span:contains(\'Water\')").length')['output'] > 0
#drag to filter down set. Result == 10 rows # drag to filter down set. Result == 10 rows
client.dragDropElem(jquery=u'("a.ui-slider-handle")[0]', pixels=u'150, 0') client.dragDropElem(jquery=u'("a.ui-slider-handle")[0]', pixels=u'150, 0')
client.asserts.assertText(jquery=u'("span.viewPanel-summary-row-count")[0]', validator=u'457') client.asserts.assertText(jquery=u'("span.viewPanel-summary-row-count")[0]', validator=u'457')
#Next TODO # Next TODO
#lowercase the Shrt_Desc # lowercase the Shrt_Desc
#TitleCase the Shrt_Desc # TitleCase the Shrt_Desc
''' '''
#history test -- in progress # history test -- in progress
client.mouseOver(classname=u'history-panel-body-collapsed') client.mouseOver(classname=u'history-panel-body-collapsed')
client.waits.forElement(link=u"Create new column Desc, split based on column Shrt_Desc by filling 0 rows with gel:split(value , ',')", timeout=u'8000') client.waits.forElement(link=u"Create new column Desc, split based on column Shrt_Desc by filling 0 rows with gel:split(value , ',')", timeout=u'8000')
client.click(jquery=u'(".history-future .history-entry")[0]') client.click(jquery=u'(".history-future .history-entry")[0]')
@ -57,8 +55,3 @@ def filter_column(client, column):
def assert_expected_top_value(client, expected_value): def assert_expected_top_value(client, expected_value):
actual_value = client.execJS(js=u'$("a.facet-choice-label")[0].text')['output'].strip() actual_value = client.execJS(js=u'$("a.facet-choice-label")[0].text')['output'].strip()
assert actual_value == expected_value, "Expected actual_value to be '{0}'. Got '{1}'".format(expected_value, actual_value) assert actual_value == expected_value, "Expected actual_value to be '{0}'. Got '{1}'".format(expected_value, actual_value)