Skip to content

Commit

Permalink
Initial selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Bikle committed Sep 23, 2013
1 parent 2f6a15e commit 3274fe7
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 0 deletions.
87 changes: 87 additions & 0 deletions selenium/com/example/tests/Test24.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.example.tests;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Test24 {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();

@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://0.0.0.0:11185";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test
public void test24() throws Exception {
driver.get(baseUrl + "/");
driver.get(baseUrl + "/ImportUrl.html");
driver.findElement(By.id("url")).clear();
driver.findElement(By.id("url")).sendKeys("http://0.0.0.0:11185/datasets/iris.csv");
driver.findElement(By.id("key")).clear();
driver.findElement(By.id("key")).sendKeys("iris22.csv");
driver.findElement(By.xpath("(//button[@onclick='query_submit()'])[2]")).click();
driver.findElement(By.linkText("iris22.csv")).click();
driver.findElement(By.linkText("Parse into hex format")).click();
driver.findElement(By.cssSelector("button.btn.btn-primary")).click();
driver.get(baseUrl + "/GBM.query?key=iris22.hex");
driver.findElement(By.id("source")).clear();
driver.findElement(By.id("source")).sendKeys("iris22.hex");
driver.findElement(By.id("destination_key")).clear();
driver.findElement(By.id("destination_key")).sendKeys("");
new Select(driver.findElement(By.id("vresponse"))).selectByVisibleText("class");
driver.findElement(By.xpath("(//button[@onclick='query_submit()'])[2]")).click();
}

@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}

private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
3 changes: 3 additions & 0 deletions selenium/javaTest24.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

java -cp .:com/example/tests:./junit-4.11.jar:./selenium-server-standalone-2.35.0.jar org.junit.runner.JUnitCore com.example.tests.Test24
6 changes: 6 additions & 0 deletions selenium/javacTest24.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# javacTest24.bash

javac -cp .:com/example/tests:selenium-server-standalone-2.35.0.jar:junit-4.11.jar com/example/tests/Test24.java

Binary file added selenium/junit-4.11.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions selenium/run_h2o.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# ${WORKSPACE}/py/selenium/run_h2o.bash

# I use this script to run an h2o jar file.

# Assume parent set JAVA_HOME
export PATH=${JAVA_HOME}/bin:/usr/bin:/bin

# Hard-code the port and,
# assume I am in the right directory.
# The port needs to match the port I wrote into the Python test(s).
# Dont use this syntax, it causes my h2o-killer to fail:
## ${JAVA_HOME}/bin/java -Xmx50m -jar h2o.jar -port $H2OPORT -name seleniumJenkins
# My h2o-killer can kill this:
java -Xmx50m -jar h2o.jar -port $H2OPORT -name seleniumJenkins

exit
Binary file added selenium/selenium-server-standalone-2.35.0.jar
Binary file not shown.
108 changes: 108 additions & 0 deletions selenium/seleniumTest10.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

# ${WORKSPACE}/selenium/seleniumTest10.bash

# We use this script to test an HTML server.
# We are using WebDriver in Selenium.
# This runs an actual copy of Firefox inside of a vnc-display.

export J2REDIR=/usr/lib/jvm/java-6-oracle/jre
export J2SDKDIR=/usr/lib/jvm/java-6-oracle
export JAVA_HOME=/usr/lib/jvm/java-6-oracle
export LANG=en_US.UTF-8

export PATH=/usr/bin:/bin:${JAVA_HOME}/bin:${JAVA_HOME}/db/bin:${J2REDIR}/bin:/usr/local/bin

export myts=`/bin/date +%Y_%m_%d_%H_%M`
env|sort > /tmp/seleniumTest10_${myts}.bash.txt

# $WORKSPACE is usually set by jenkins.
if [ "$WORKSPACE" == "" ]
then
echo jenkins sets WORKSPACE to a dir.
echo If you are not jenkins do this:
echo export WORKSPACE=/tmp
echo and run
echo $0
echo again
exit 1
fi

pwd

mkdir -p ${WORKSPACE}/tmp/
cd ${WORKSPACE}/tmp/

/bin/rm -f latest h2o-*.zip

# Get an integer which labels the latest build:
/usr/bin/s3cmd get s3://h2o-release/h2o/master/latest latest
/bin/cat latest
latest=`/bin/cat latest`

# debug
# /usr/bin/s3cmd get "s3://h2o-release/h2o/master/${latest}/h2o-*${latest}.zip"
# cp ~jenkins/seleniumJenkinsTmp/h2o_bak.zip h2o-1.7.0.${latest}.zip
latest=1037
cp ~dan/danhub/h2o_1037_bak.zip h2o-1.7.0.${latest}.zip
# debug

# Keep unzip happy, rm-rf the dir it wants to create:
/bin/rm -rf latest h2o-*${latest}

/usr/bin/unzip h2o-*${latest}.zip

# Prep to run h2o in background:
cd h2o-*${latest}
pwd

# H2OPORT is used in 2 places so I specify it here.
# I dont want to use the default value of 54321:
export H2OPORT=11185

# Kill old h2o maybe left behind. We want a new one.
ps waux|grep $H2OPORT|grep java|grep h2o.jar|/usr/bin/awk '{print $2}'|xargs /bin/kill

# Wait a bit:
sleep 3

# I want to run h2o in background:
if [ -f ${WORKSPACE}/selenium/run_h2o.bash ]
then
echo I found:
echo ${WORKSPACE}/selenium/run_h2o.bash
else
echo ${WORKSPACE}/selenium/run_h2o.bash
echo not found, will exit now.
exit 1
fi

# Here:
${WORKSPACE}/selenium/run_h2o.bash > /tmp/run_h2o_bash_{$myts}.txt 2>&1 &

# Wait a bit:
echo 'Running in background now... wait for it...'
sleep 5

echo Here it is:
ps waux|grep $H2OPORT

echo Now I will set DISPLAY to vnc and run python-firefox-selenium test:
# debug
# Currently localhost:1.0 should be tied to vnc server running on same host as jenkins.
export DISPLAY=localhost:1.0
# Dan desk:
# export DISPLAY=localhost:11.0
# debug

echo DISPLAY is:
echo $DISPLAY

cd ${WORKSPACE}/selenium/
bash -x ${WORKSPACE}/selenium/javacTest24.bash
bash -x ${WORKSPACE}/selenium/javaTest24.bash

sleep 2

exit

81 changes: 81 additions & 0 deletions selenium/test24.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://0.0.0.0:11185" />
<title>test18</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">test18</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/ImportUrl.html</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=url</td>
<td>http://0.0.0.0:11185/datasets/iris.csv</td>
</tr>
<tr>
<td>type</td>
<td>id=key</td>
<td>iris22.csv</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//button[@onclick='query_submit()'])[2]</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=iris22.csv</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Parse into hex format</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=button.btn.btn-primary</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/GBM.query?key=iris22.hex</td>
<td></td>
</tr>
<tr>
<td>typeAndWait</td>
<td>id=source</td>
<td>iris22.hex</td>
</tr>
<tr>
<td>typeAndWait</td>
<td>id=destination_key</td>
<td></td>
</tr>
<tr>
<td>selectAndWait</td>
<td>id=vresponse</td>
<td>label=class</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//button[@onclick='query_submit()'])[2]</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>

0 comments on commit 3274fe7

Please sign in to comment.