Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ abstract public class AbstractZeppelinIT {
protected WebDriver driver;

protected final static Logger LOG = LoggerFactory.getLogger(AbstractZeppelinIT.class);
protected static final long MAX_IMPLICIT_WAIT = 30;
protected static final long MAX_BROWSER_TIMEOUT_SEC = 30;
protected static final long MAX_PARAGRAPH_TIMEOUT_SEC = 60;

Expand All @@ -59,6 +60,19 @@ protected void sleep(long millis, boolean logOutput) {
}
}

protected void setTextOfParagraph(int paragraphNo, String text) {
String editorId = driver.findElement(By.xpath(getParagraphXPath(paragraphNo) + "//div[contains(@class, 'editor')]")).getAttribute("id");
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver).executeScript("ace.edit('" + editorId + "'). setValue('" + text + "')");
} else {
throw new IllegalStateException("This driver does not support JavaScript!");
}
}

protected void runParagraph(int paragraphNo) {
driver.findElement(By.xpath(getParagraphXPath(paragraphNo) + "//span[@class='icon-control-play']")).click();
}


protected String getParagraphXPath(int paragraphNo) {
return "//div[@ng-controller=\"ParagraphCtrl\"][" + paragraphNo + "]";
Expand Down Expand Up @@ -135,40 +149,6 @@ protected void deleteTestNotebook(final WebDriver driver) {
sleep(100, true);
}

public enum HelperKeys implements CharSequence {
OPEN_PARENTHESIS(Keys.chord(Keys.SHIFT, "9")),
EXCLAMATION(Keys.chord(Keys.SHIFT, "1")),
PERCENTAGE(Keys.chord(Keys.SHIFT, "5")),
SHIFT_ENTER(Keys.chord(SHIFT, ENTER));

private final CharSequence keyCode;

HelperKeys(CharSequence keyCode) {
this.keyCode = keyCode;
}

public char charAt(int index) {
return index == 0 ? keyCode.charAt(index) : '\ue000';
}

public int length() {
return 1;
}

public CharSequence subSequence(int start, int end) {
if (start == 0 && end == 1) {
return String.valueOf(this.keyCode);
} else {
throw new IndexOutOfBoundsException();
}
}

public String toString() {
return String.valueOf(this.keyCode);
}

}

protected void handleException(String message, Exception e) throws Exception {
LOG.error(message, e);
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.fail;

Expand Down Expand Up @@ -114,6 +115,8 @@ public static WebDriver getWebDriver() {

long start = System.currentTimeMillis();
boolean loaded = false;
driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT,
TimeUnit.SECONDS);
driver.get(url);

while (System.currentTimeMillis() - start < 60 * 1000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public void testCreateNewButton() throws Exception {
"//div[@class='modal-footer']//button[contains(.,'OK')]")).click();
ZeppelinITUtils.sleep(1000, false);

WebElement oldParagraphEditor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea"));
oldParagraphEditor.sendKeys(" original paragraph ");
setTextOfParagraph(1, " original paragraph ");

WebElement newPara = driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class,'new-paragraph')][1]"));
action.moveToElement(newPara).click().build().perform();
Expand All @@ -98,8 +97,7 @@ public void testCreateNewButton() throws Exception {
collector.checkThat("Paragraph is created above",
driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'editor')]")).getText(),
CoreMatchers.equalTo(""));
WebElement aboveParagraphEditor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea"));
aboveParagraphEditor.sendKeys(" this is above ");
setTextOfParagraph(1, " this is above ");

newPara = driver.findElement(By.xpath(getParagraphXPath(2) + "//div[contains(@class,'new-paragraph')][2]"));
action.moveToElement(newPara).click().build().perform();
Expand All @@ -109,8 +107,7 @@ public void testCreateNewButton() throws Exception {
collector.checkThat("Paragraph is created below",
driver.findElement(By.xpath(getParagraphXPath(3) + "//div[contains(@class, 'editor')]")).getText(),
CoreMatchers.equalTo(""));
WebElement belowParagraphEditor = driver.findElement(By.xpath(getParagraphXPath(3) + "//textarea"));
belowParagraphEditor.sendKeys(" this is below ");
setTextOfParagraph(3, " this is below ");

collector.checkThat("The output field of paragraph1 contains",
driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'editor')]")).getText(),
Expand Down Expand Up @@ -163,7 +160,7 @@ public void testRemoveButton() throws Exception {
deleteTestNotebook(driver);

} catch (Exception e) {
handleException("Exception in ParagraphActionsIT while testMoveUpAndDown ", e);
handleException("Exception in ParagraphActionsIT while testRemoveButton ", e);
}
}

Expand All @@ -176,16 +173,14 @@ public void testMoveUpAndDown() throws Exception {
createNewNote();

waitForParagraph(1, "READY");
WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea"));
paragraph1Editor.sendKeys("1");
setTextOfParagraph(1, "1");

driver.findElement(By.xpath(getParagraphXPath(1) + "//span[@class='icon-settings']")).click();
driver.findElement(By.xpath(getParagraphXPath(1) + "//ul/li/a[@ng-click='insertNew()']")).click();


waitForParagraph(2, "READY");
WebElement paragraph2Editor = driver.findElement(By.xpath(getParagraphXPath(2) + "//textarea"));
paragraph2Editor.sendKeys("2");
setTextOfParagraph(2, "2");


collector.checkThat("The paragraph1 value contains",
Expand Down Expand Up @@ -236,9 +231,7 @@ public void testDisableParagraphRunButton() throws Exception {
createNewNote();

waitForParagraph(1, "READY");
WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea"));
paragraph1Editor.sendKeys("println" + Keys.chord(Keys.SHIFT, "9") + "\""
+ "abcd\")");
setTextOfParagraph(1, "println (\"abcd\")");

driver.findElement(By.xpath(getParagraphXPath(1) + "//span[@class='icon-settings']")).click();
driver.findElement(By.xpath(getParagraphXPath(1) + "//ul/li/a[@ng-click='toggleEnableDisable()']")).click();
Expand Down Expand Up @@ -275,9 +268,7 @@ public void testClearOutputButton() throws Exception {

waitForParagraph(1, "READY");
String xpathToOutputField=getParagraphXPath(1) + "//div[contains(@ng-if,'getResultType()')]";
WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea"));
paragraph1Editor.sendKeys("println" + Keys.chord(Keys.SHIFT, "9") + "\""
+ "abcd\")");
setTextOfParagraph(1, "println (\"abcd\")");
collector.checkThat("Before Run Output field contains ",
driver.findElement(By.xpath(xpathToOutputField)).getText(),
CoreMatchers.equalTo(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.zeppelin.AbstractZeppelinIT.HelperKeys.*;
import static org.openqa.selenium.Keys.*;

public class SparkParagraphIT extends AbstractZeppelinIT {
private static final Logger LOG = LoggerFactory.getLogger(SparkParagraphIT.class);

Expand Down Expand Up @@ -67,17 +64,10 @@ public void testSpark() throws Exception {
return;
}
try {
WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea"));
paragraph1Editor.sendKeys("sc.version");
paragraph1Editor.sendKeys(SHIFT_ENTER);
setTextOfParagraph(1, "sc.version");
runParagraph(1);

waitForParagraph(1, "FINISHED");
WebElement paragraph1Result = driver.findElement(By.xpath(
getParagraphXPath(1) + "//div[@class=\"tableDisplay\"]"));
Float sparkVersion = Float.parseFloat(paragraph1Result.getText().split("= ")[1].substring(0, 3));

WebElement paragraph2Editor = driver.findElement(By.xpath(getParagraphXPath(2) + "//textarea"));


/*
equivalent of
Expand All @@ -90,50 +80,15 @@ case class Bank(age: Integer, job: String, marital: String, education: String, b
val bank = bankText.map(s => s.split(";")).filter(s => s(0) != "\"age\"").map(s => Bank(s(0).toInt,s(1).replaceAll("\"", ""),s(2).replaceAll("\"", ""),s(3).replaceAll("\"", ""),s(5).replaceAll("\"", "").toInt)).toDF()
bank.registerTempTable("bank")
*/
paragraph2Editor.sendKeys("import org.apache.commons.io.IOUtils" +
ENTER +

"import java.net.URL" +
ENTER +

"import java.nio.charset.Charset" +
ENTER +

"val bankText = sc.parallelize" + OPEN_PARENTHESIS +
"IOUtils.toString" + OPEN_PARENTHESIS + "new URL" + OPEN_PARENTHESIS
+ "\"https://s3.amazonaws.com/apache" + SUBTRACT + "zeppelin/tutorial/bank/bank." +
"csv\"),Charset.forName" + OPEN_PARENTHESIS + "\"utf8\"))" +
".split" + OPEN_PARENTHESIS + "\"\\n\"))" +
ENTER +

"case class Bank" + OPEN_PARENTHESIS +
"age: Integer, job: String, marital: String, education: String, balance: Integer)" +
ENTER +
ENTER +

"val bank = bankText.map" + OPEN_PARENTHESIS + "s => s.split" +
OPEN_PARENTHESIS + "\";\")).filter" + OPEN_PARENTHESIS +
"s => s" + OPEN_PARENTHESIS + "0) " + EXCLAMATION +
"= \"\\\"age\\\"\").map" + OPEN_PARENTHESIS +
"s => Bank" + OPEN_PARENTHESIS + "s" + OPEN_PARENTHESIS +
"0).toInt,s" + OPEN_PARENTHESIS + "1).replaceAll" +
OPEN_PARENTHESIS + "\"\\\"\", \"\")," +
"s" + OPEN_PARENTHESIS + "2).replaceAll" +
OPEN_PARENTHESIS + "\"\\\"\", \"\")," +
"s" + OPEN_PARENTHESIS + "3).replaceAll" +
OPEN_PARENTHESIS + "\"\\\"\", \"\")," +
"s" + OPEN_PARENTHESIS + "5).replaceAll" +
OPEN_PARENTHESIS + "\"\\\"\", \"\").toInt" + ")" +
")" + (sparkVersion < 1.3f ? "" : ".toDF" + OPEN_PARENTHESIS + ")") +
ENTER +

"bank.registerTempTable" + OPEN_PARENTHESIS + "\"bank\")"
);
paragraph2Editor.sendKeys("" + END + BACK_SPACE + BACK_SPACE +
BACK_SPACE + BACK_SPACE + BACK_SPACE + BACK_SPACE +
BACK_SPACE + BACK_SPACE + BACK_SPACE + BACK_SPACE + BACK_SPACE);

paragraph2Editor.sendKeys(SHIFT_ENTER);
setTextOfParagraph(2, "import org.apache.commons.io.IOUtils\\n" +
"import java.net.URL\\n" +
"import java.nio.charset.Charset\\n" +
"val bankText = sc.parallelize(IOUtils.toString(new URL(\"https://s3.amazonaws.com/apache-zeppelin/tutorial/bank/bank.csv\"),Charset.forName(\"utf8\")).split(\"\\\\n\"))\\n" +
"case class Bank(age: Integer, job: String, marital: String, education: String, balance: Integer)\\n" +
"\\n" +
"val bank = bankText.map(s => s.split(\";\")).filter(s => s(0) != \"\\\\\"age\\\\\"\").map(s => Bank(s(0).toInt,s(1).replaceAll(\"\\\\\"\", \"\"),s(2).replaceAll(\"\\\\\"\", \"\"),s(3).replaceAll(\"\\\\\"\", \"\"),s(5).replaceAll(\"\\\\\"\", \"\").toInt)).toDF()\\n" +
"bank.registerTempTable(\"bank\")");
runParagraph(2);

try {
waitForParagraph(2, "FINISHED");
Expand Down Expand Up @@ -164,14 +119,11 @@ public void testPySpark() throws Exception {
return;
}
try {
WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea"));

paragraph1Editor.sendKeys(PERCENTAGE + "pyspark" + ENTER +
"for x in range" + OPEN_PARENTHESIS + "0, 3):" + ENTER +
" print \"test loop " + PERCENTAGE + "d\" " +
PERCENTAGE + " " + OPEN_PARENTHESIS + "x)" + ENTER);
setTextOfParagraph(1, "%pyspark\\n" +
"for x in range(0, 3):\\n" +
" print \"test loop %d\" % (x)");

paragraph1Editor.sendKeys(SHIFT_ENTER);
runParagraph(1);

try {
waitForParagraph(1, "FINISHED");
Expand Down Expand Up @@ -199,12 +151,9 @@ public void testSqlSpark() throws Exception {
return;
}
try {
WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea"));

paragraph1Editor.sendKeys(PERCENTAGE + "sql" + ENTER +
setTextOfParagraph(1,"%sql\\n" +
"select * from bank limit 1");

paragraph1Editor.sendKeys(SHIFT_ENTER);
runParagraph(1);

try {
waitForParagraph(1, "FINISHED");
Expand Down
Loading