Example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOfElementLocated.

Prototype

public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator) 

Source Link

Document

An expectation for checking that an element is present on the DOM of a page and visible.

Usage

From source file:org.apache.syncope.fit.console.reference.TaskITCase.java

License:Apache License

@Test
public void execute() {
    seleniumDriver.findElement(By.xpath("//img[@alt=\"Tasks\"]")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='tabs']")));

    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[1]/a")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//tr[4]/td[10]/div/span[6]/a/img")));

    seleniumDriver.findElement(By.xpath("//tr[4]/td[10]/div/span[6]/a/img")).click();

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("feedback")));
    assertTrue(seleniumDriver.findElement(By.tagName("body")).getText()
            .contains("Operation executed successfully"));

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//tr[4]/td[10]/div/span[13]/a/img")));

    seleniumDriver.findElement(By.xpath("//tr[4]/td[10]/div/span[13]/a/img")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//iframe")));
    seleniumDriver.switchTo().frame(0);//  w  w w .  j  a v a 2s  .  com

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[2]/form/div[2]/ul/li[2]/a")));

    seleniumDriver.findElement(By.xpath("//div[2]/form/div[2]/ul/li[2]/a"));

    assertTrue(seleniumDriver.findElements(By.xpath("//div[2]/form/div[2]/div[2]/span/table/tbody/tr/td[4]"))
            .size() > 0);

    seleniumDriver.switchTo().defaultContent();

    seleniumDriver.findElement(By.xpath("//a[@class='w_close']")).click();
}

From source file:org.apache.syncope.fit.console.reference.TaskITCase.java

License:Apache License

@Test
public void delete() {
    seleniumDriver.findElement(By.xpath("//img[@alt=\"Tasks\"]")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='tabs']")));

    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[3]/a")).click();

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//img[@alt='delete icon'])[6]")));

    seleniumDriver.findElement(By.xpath("(//img[@alt='delete icon'])[6]")).click();
    seleniumDriver.switchTo().alert().accept();

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("feedback")));
    assertTrue(seleniumDriver.findElement(By.tagName("body")).getText()
            .contains("Operation executed successfully"));
}

From source file:org.apache.syncope.fit.console.reference.UserITCase.java

License:Apache License

@Test
public void delete() {
    seleniumDriver.findElement(By.xpath("//img[@alt=\"Users\"]")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='tabs']")));

    seleniumDriver.findElement(By.xpath("//*[@id=\"users-contain\"]//*[div=4]/../td[5]/div/span[15]/a"))
            .click();/* ww w . ja  va2  s  .  c  o  m*/

    Alert alert = seleniumDriver.switchTo().alert();
    assertTrue(alert.getText().equals("Do you really want to delete the selected item(s)?"));
    alert.accept();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//iframe")));
    seleniumDriver.switchTo().frame(0);

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='propagation']/span")));

    seleniumDriver.findElement(By.xpath("//*[@id=\"users-contain\"]/a")).click();

    seleniumDriver.switchTo().defaultContent();

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("feedback")));
    assertTrue(seleniumDriver.findElement(By.tagName("body")).getText()
            .contains("Operation executed successfully"));
}

From source file:org.apache.zeppelin.AbstractZeppelinIT.java

License:Apache License

protected void createNewNote() {
    clickAndWait(/*from w  w w . j av  a 2  s . c  o m*/
            By.xpath("//div[contains(@class, \"col-md-4\")]/div/h5/a[contains(.,'Create new" + " note')]"));

    WebDriverWait block = new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC);
    block.until(ExpectedConditions.visibilityOfElementLocated(By.id("noteCreateModal")));
    clickAndWait(By.id("createNoteButton"));
    block.until(ExpectedConditions.invisibilityOfElementLocated(By.id("createNoteButton")));
}

From source file:org.apache.zeppelin.AbstractZeppelinIT.java

License:Apache License

protected void deleteTestNotebook(final WebDriver driver) {
    WebDriverWait block = new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC);
    driver.findElement(By.xpath(".//*[@id='main']//button[@ng-click='moveNoteToTrash(note.id)']"))
            .sendKeys(Keys.ENTER);/*from  w  w w .  jav a2  s  . co m*/
    block.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath(".//*[@id='main']//button[@ng-click='moveNoteToTrash(note.id)']")));
    driver.findElement(By.xpath("//div[@class='modal-dialog'][contains(.,'This note will be moved to trash')]"
            + "//div[@class='modal-footer']//button[contains(.,'OK')]")).click();
    ZeppelinITUtils.sleep(100, false);
}

From source file:org.apache.zeppelin.AbstractZeppelinIT.java

License:Apache License

protected void deleteTrashNotebook(final WebDriver driver) {
    WebDriverWait block = new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC);
    driver.findElement(By.xpath(".//*[@id='main']//button[@ng-click='removeNote(note.id)']"))
            .sendKeys(Keys.ENTER);/*  w  w w  .java  2  s. c  o  m*/
    block.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath(".//*[@id='main']//button[@ng-click='removeNote(note.id)']")));
    driver.findElement(
            By.xpath("//div[@class='modal-dialog'][contains(.,'This cannot be undone. Are you sure?')]"
                    + "//div[@class='modal-footer']//button[contains(.,'OK')]"))
            .click();
    ZeppelinITUtils.sleep(100, false);
}

From source file:org.apache.zeppelin.integration.InterpreterModeActionsIT.java

License:Apache License

@Test
public void testGloballyAction() throws Exception {
    try {// w w w .  j a v  a 2  s.co m
        //step 1: (admin) login, set 'globally in shared' mode of python interpreter, logout
        InterpreterModeActionsIT interpreterModeActionsIT = new InterpreterModeActionsIT();
        interpreterModeActionsIT.authenticationUser("admin", "password1");
        pollingWait(By.xpath("//div/button[contains(@class, 'nav-btn dropdown-toggle ng-scope')]"),
                MAX_BROWSER_TIMEOUT_SEC).click();
        clickAndWait(By.xpath("//li/a[contains(@href, '#/interpreter')]"));
        pollingWait(By.xpath("//input[contains(@ng-model, 'searchInterpreter')]"), MAX_BROWSER_TIMEOUT_SEC)
                .sendKeys("python");
        ZeppelinITUtils.sleep(500, false);
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//button[contains(@ng-click, 'valueform.$show();\n"
                + "                  copyOriginInterpreterSettingProperties(setting.id)')]"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]/div[2]/div/div/div[1]/span[1]/button"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//li/a[contains(.,'Globally')]"));
        JavascriptExecutor jse = (JavascriptExecutor) driver;
        jse.executeScript("window.scrollBy(0,250)", "");
        ZeppelinITUtils.sleep(500, false);
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//div/form/button[contains(@type, 'submit')]"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));
        clickAndWait(By.xpath("//a[@class='navbar-brand navbar-title'][contains(@href, '#/')]"));
        interpreterModeActionsIT.logoutUser("admin");
        //step 2: (user1) login, create a new note, run two paragraph with 'python', check result, check process, logout
        //paragraph: Check if the result is 'user1' in the second paragraph
        //System: Check if the number of python interpreter process is '1'
        //System: Check if the number of python process is '1'
        interpreterModeActionsIT.authenticationUser("user1", "password2");
        By locator = By
                .xpath("//div[contains(@class, 'col-md-4')]/div/h5/a[contains(.,'Create new" + " note')]");
        WebElement element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            createNewNote();
        }
        String user1noteId = driver.getCurrentUrl().substring(driver.getCurrentUrl().lastIndexOf("/") + 1);
        waitForParagraph(1, "READY");
        interpreterModeActionsIT.setPythonParagraph(1, "user=\"user1\"");
        waitForParagraph(2, "READY");
        interpreterModeActionsIT.setPythonParagraph(2, "print user");
        collector.checkThat("The output field paragraph contains",
                driver.findElement(
                        By.xpath(getParagraphXPath(2) + "//div[contains(@class, 'text plainTextContent')]"))
                        .getText(),
                CoreMatchers.equalTo("user1"));
        String resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("1"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("1"));

        interpreterModeActionsIT.logoutUser("user1");

        //step 3: (user2) login, create a new note, run two paragraph with 'python', check result, check process, logout
        //paragraph: Check if the result is 'user2' in the second paragraph
        //System: Check if the number of python interpreter process is '1'
        //System: Check if the number of python process is '1'
        interpreterModeActionsIT.authenticationUser("user2", "password3");
        locator = By.xpath("//div[contains(@class, 'col-md-4')]/div/h5/a[contains(.,'Create new" + " note')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            createNewNote();
        }
        waitForParagraph(1, "READY");
        interpreterModeActionsIT.setPythonParagraph(1, "user=\"user2\"");
        waitForParagraph(2, "READY");
        interpreterModeActionsIT.setPythonParagraph(2, "print user");
        collector.checkThat("The output field paragraph contains",
                driver.findElement(
                        By.xpath(getParagraphXPath(2) + "//div[contains(@class, 'text plainTextContent')]"))
                        .getText(),
                CoreMatchers.equalTo("user2"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("1"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("1"));
        interpreterModeActionsIT.logoutUser("user2");

        //step 4: (user1) login, come back note user1 made, run second paragraph, check result, check process,
        //restart python interpreter, check process again, logout
        //paragraph: Check if the result is 'user2' in the second paragraph
        //System: Check if the number of python interpreter process is '1'
        //System: Check if the number of python process is '1'
        interpreterModeActionsIT.authenticationUser("user1", "password2");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        waitForParagraph(2, "FINISHED");
        runParagraph(2);
        try {
            waitForParagraph(2, "FINISHED");
        } catch (TimeoutException e) {
            waitForParagraph(2, "ERROR");
            collector.checkThat("Exception in InterpreterModeActionsIT while running Python Paragraph", "ERROR",
                    CoreMatchers.equalTo("FINISHED"));
        }
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("1"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("1"));

        clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        clickAndWait(
                By.xpath("//div[@data-ng-repeat='item in interpreterBindings' and contains(., 'python')]//a"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']" + "[contains(.,'Do you want to restart python interpreter?')]"
                        + "//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));
        locator = By.xpath(
                "//div[@class='modal-dialog'][contains(.,'Do you want to restart python interpreter?')]");
        LOG.info("Holding on until if interpreter restart dialog is disappeared or not testGloballyAction");
        boolean invisibilityStatus = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.invisibilityOfElementLocated(locator));
        if (invisibilityStatus == false) {
            assertTrue("interpreter setting dialog visibility status", invisibilityStatus);
        }
        locator = By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        }
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("0"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("0"));
        interpreterModeActionsIT.logoutUser("user1");
    } catch (Exception e) {
        handleException("Exception in InterpreterModeActionsIT while testGloballyAction ", e);
    }
}

From source file:org.apache.zeppelin.integration.InterpreterModeActionsIT.java

License:Apache License

@Test
public void testPerUserScopedAction() throws Exception {
    try {/*from  w  ww  .  j av  a  2 s  .co  m*/
        //step 1: (admin) login, set 'Per user in scoped' mode of python interpreter, logout
        InterpreterModeActionsIT interpreterModeActionsIT = new InterpreterModeActionsIT();
        interpreterModeActionsIT.authenticationUser("admin", "password1");
        pollingWait(By.xpath("//div/button[contains(@class, 'nav-btn dropdown-toggle ng-scope')]"),
                MAX_BROWSER_TIMEOUT_SEC).click();

        clickAndWait(By.xpath("//li/a[contains(@href, '#/interpreter')]"));
        pollingWait(By.xpath("//input[contains(@ng-model, 'searchInterpreter')]"), MAX_BROWSER_TIMEOUT_SEC)
                .sendKeys("python");
        ZeppelinITUtils.sleep(500, false);

        clickAndWait(By.xpath("//div[contains(@id, 'python')]//button[contains(@ng-click, 'valueform.$show();\n"
                + "                  copyOriginInterpreterSettingProperties(setting.id)')]"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]/div[2]/div/div/div[1]/span[1]/button"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//li/a[contains(.,'Per User')]"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]/div[2]/div/div/div[1]/span[2]/button"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//li/a[contains(.,'scoped per user')]"));

        JavascriptExecutor jse = (JavascriptExecutor) driver;
        jse.executeScript("window.scrollBy(0,250)", "");
        ZeppelinITUtils.sleep(500, false);
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//div/form/button[contains(@type, 'submit')]"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));
        clickAndWait(By.xpath("//a[@class='navbar-brand navbar-title'][contains(@href, '#/')]"));

        interpreterModeActionsIT.logoutUser("admin");

        //step 2: (user1) login, create a new note, run two paragraph with 'python', check result, check process, logout
        //paragraph: Check if the result is 'user1' in the second paragraph
        //System: Check if the number of python interpreter process is '1'
        //System: Check if the number of python process is '1'
        interpreterModeActionsIT.authenticationUser("user1", "password2");
        By locator = By
                .xpath("//div[contains(@class, 'col-md-4')]/div/h5/a[contains(.,'Create new" + " note')]");
        WebElement element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            createNewNote();
        }
        String user1noteId = driver.getCurrentUrl().substring(driver.getCurrentUrl().lastIndexOf("/") + 1);

        waitForParagraph(1, "READY");
        interpreterModeActionsIT.setPythonParagraph(1, "user=\"user1\"");
        waitForParagraph(2, "READY");
        interpreterModeActionsIT.setPythonParagraph(2, "print user");

        collector.checkThat("The output field paragraph contains",
                driver.findElement(
                        By.xpath(getParagraphXPath(2) + "//div[contains(@class, 'text plainTextContent')]"))
                        .getText(),
                CoreMatchers.equalTo("user1"));

        String resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("1"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("1"));
        interpreterModeActionsIT.logoutUser("user1");

        //step 3: (user2) login, create a new note, run two paragraph with 'python', check result, check process, logout
        //                paragraph: Check if the result is 'user2' in the second paragraph
        //System: Check if the number of python interpreter process is '1'
        //System: Check if the number of python process is '2'
        interpreterModeActionsIT.authenticationUser("user2", "password3");
        locator = By.xpath("//div[contains(@class, 'col-md-4')]/div/h5/a[contains(.,'Create new" + " note')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            createNewNote();
        }
        String user2noteId = driver.getCurrentUrl().substring(driver.getCurrentUrl().lastIndexOf("/") + 1);
        waitForParagraph(1, "READY");
        interpreterModeActionsIT.setPythonParagraph(1, "user=\"user2\"");
        waitForParagraph(2, "READY");
        interpreterModeActionsIT.setPythonParagraph(2, "print user");
        collector.checkThat("The output field paragraph contains",
                driver.findElement(
                        By.xpath(getParagraphXPath(2) + "//div[contains(@class, 'text plainTextContent')]"))
                        .getText(),
                CoreMatchers.equalTo("user2"));

        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("2"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("1"));
        interpreterModeActionsIT.logoutUser("user2");

        //step 4: (user1) login, come back note user1 made, run second paragraph, check result,
        //                restart python interpreter in note, check process again, logout
        //paragraph: Check if the result is 'user1' in the second paragraph
        //System: Check if the number of python interpreter process is '1'
        //System: Check if the number of python process is '1'
        interpreterModeActionsIT.authenticationUser("user1", "password2");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        runParagraph(2);
        try {
            waitForParagraph(2, "FINISHED");
        } catch (TimeoutException e) {
            waitForParagraph(2, "ERROR");
            collector.checkThat("Exception in InterpreterModeActionsIT while running Python Paragraph", "ERROR",
                    CoreMatchers.equalTo("FINISHED"));
        }
        collector.checkThat("The output field paragraph contains",
                driver.findElement(
                        By.xpath(getParagraphXPath(2) + "//div[contains(@class, 'text plainTextContent')]"))
                        .getText(),
                CoreMatchers.equalTo("user1"));

        clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        clickAndWait(
                By.xpath("//div[@data-ng-repeat='item in interpreterBindings' and contains(., 'python')]//a"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']" + "[contains(.,'Do you want to restart python interpreter?')]"
                        + "//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));
        locator = By.xpath(
                "//div[@class='modal-dialog'][contains(.,'Do you want to restart python interpreter?')]");
        LOG.info(
                "Holding on until if interpreter restart dialog is disappeared or not in testPerUserScopedAction");
        boolean invisibilityStatus = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.invisibilityOfElementLocated(locator));
        if (invisibilityStatus == false) {
            assertTrue("interpreter setting dialog visibility status", invisibilityStatus);
        }
        locator = By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        }

        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("1"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("1"));
        interpreterModeActionsIT.logoutUser("user1");

        //step 5: (user2) login, come back note user2 made, restart python interpreter in note, check process, logout
        //System: Check if the number of python interpreter process is '0'
        //System: Check if the number of python process is '0'
        interpreterModeActionsIT.authenticationUser("user2", "password3");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user2noteId + "')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user2noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        clickAndWait(
                By.xpath("//div[@data-ng-repeat='item in interpreterBindings' and contains(., 'python')]//a"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']" + "[contains(.,'Do you want to restart python interpreter?')]"
                        + "//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));
        locator = By.xpath(
                "//div[@class='modal-dialog'][contains(.,'Do you want to restart python interpreter?')]");
        LOG.info(
                "Holding on until if interpreter restart dialog is disappeared or not in testPerUserScopedAction");
        invisibilityStatus = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.invisibilityOfElementLocated(locator));
        if (invisibilityStatus == false) {
            assertTrue("interpreter setting dialog visibility status", invisibilityStatus);
        }
        locator = By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        }

        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("0"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("0"));
        interpreterModeActionsIT.logoutUser("user2");

        //step 6: (user1) login, come back note user1 made, run first paragraph,logout
        //        (user2) login, come back note user2 made, run first paragraph, check process, logout
        //System: Check if the number of python process is '2'
        //System: Check if the number of python interpreter process is '1'
        interpreterModeActionsIT.authenticationUser("user1", "password2");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        waitForParagraph(1, "FINISHED");
        runParagraph(1);
        try {
            waitForParagraph(1, "FINISHED");
        } catch (TimeoutException e) {
            waitForParagraph(1, "ERROR");
            collector.checkThat("Exception in InterpreterModeActionsIT while running Python Paragraph", "ERROR",
                    CoreMatchers.equalTo("FINISHED"));
        }
        interpreterModeActionsIT.logoutUser("user1");

        interpreterModeActionsIT.authenticationUser("user2", "password3");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user2noteId + "')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user2noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        runParagraph(1);
        try {
            waitForParagraph(1, "FINISHED");
        } catch (TimeoutException e) {
            waitForParagraph(1, "ERROR");
            collector.checkThat("Exception in InterpreterModeActionsIT while running Python Paragraph", "ERROR",
                    CoreMatchers.equalTo("FINISHED"));
        }
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("2"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("1"));
        interpreterModeActionsIT.logoutUser("user2");

        //step 7: (admin) login, restart python interpreter in interpreter tab, check process, logout
        //System: Check if the number of python interpreter process is 0
        //System: Check if the number of python process is 0
        interpreterModeActionsIT.authenticationUser("admin", "password1");
        pollingWait(By.xpath("//div/button[contains(@class, 'nav-btn dropdown-toggle ng-scope')]"),
                MAX_BROWSER_TIMEOUT_SEC).click();

        clickAndWait(By.xpath("//li/a[contains(@href, '#/interpreter')]"));
        pollingWait(By.xpath("//input[contains(@ng-model, 'searchInterpreter')]"), MAX_BROWSER_TIMEOUT_SEC)
                .sendKeys("python");
        ZeppelinITUtils.sleep(500, false);

        clickAndWait(By.xpath("//div[contains(@id, 'python')]"
                + "//button[contains(@ng-click, 'restartInterpreterSetting(setting.id)')]"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']" + "[contains(.,'Do you want to restart this interpreter?')]"
                        + "//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));
        locator = By.xpath(
                "//div[@class='modal-dialog'][contains(.,'Do you want to restart python interpreter?')]");
        LOG.info(
                "Holding on until if interpreter restart dialog is disappeared or not in testPerUserScopedAction");
        invisibilityStatus = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.invisibilityOfElementLocated(locator));
        if (invisibilityStatus == false) {
            assertTrue("interpreter setting dialog visibility status", invisibilityStatus);
        }

        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("0"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("0"));

        interpreterModeActionsIT.logoutUser("admin");

    } catch (Exception e) {
        handleException("Exception in InterpreterModeActionsIT while testPerUserScopedAction ", e);
    }
}

From source file:org.apache.zeppelin.integration.InterpreterModeActionsIT.java

License:Apache License

@Test
public void testPerUserIsolatedAction() throws Exception {
    try {//from w w  w  .j  av a2 s.  c o m
        //step 1: (admin) login, set 'Per user in isolated' mode of python interpreter, logout
        InterpreterModeActionsIT interpreterModeActionsIT = new InterpreterModeActionsIT();
        interpreterModeActionsIT.authenticationUser("admin", "password1");
        pollingWait(By.xpath("//div/button[contains(@class, 'nav-btn dropdown-toggle ng-scope')]"),
                MAX_BROWSER_TIMEOUT_SEC).click();
        clickAndWait(By.xpath("//li/a[contains(@href, '#/interpreter')]"));
        pollingWait(By.xpath("//input[contains(@ng-model, 'searchInterpreter')]"), MAX_BROWSER_TIMEOUT_SEC)
                .sendKeys("python");
        ZeppelinITUtils.sleep(500, false);
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//button[contains(@ng-click, 'valueform.$show();\n"
                + "                  copyOriginInterpreterSettingProperties(setting.id)')]"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]/div[2]/div/div/div[1]/span[1]/button"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//li/a[contains(.,'Per User')]"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]/div[2]/div/div/div[1]/span[2]/button"));
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//li/a[contains(.,'isolated per user')]"));
        JavascriptExecutor jse = (JavascriptExecutor) driver;
        jse.executeScript("window.scrollBy(0,250)", "");
        ZeppelinITUtils.sleep(500, false);
        clickAndWait(By.xpath("//div[contains(@id, 'python')]//div/form/button[contains(@type, 'submit')]"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));
        clickAndWait(By.xpath("//a[@class='navbar-brand navbar-title'][contains(@href, '#/')]"));
        interpreterModeActionsIT.logoutUser("admin");

        //step 2: (user1) login, create a new note, run two paragraph with 'python', check result, check process, logout
        //paragraph: Check if the result is 'user1' in the second paragraph
        //System: Check if the number of python interpreter process is '1'
        //System: Check if the number of python process is '1'
        interpreterModeActionsIT.authenticationUser("user1", "password2");
        By locator = By
                .xpath("//div[contains(@class, 'col-md-4')]/div/h5/a[contains(.,'Create new" + " note')]");
        WebElement element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            createNewNote();
        }
        String user1noteId = driver.getCurrentUrl().substring(driver.getCurrentUrl().lastIndexOf("/") + 1);
        waitForParagraph(1, "READY");
        interpreterModeActionsIT.setPythonParagraph(1, "user=\"user1\"");
        waitForParagraph(2, "READY");
        interpreterModeActionsIT.setPythonParagraph(2, "print user");

        collector.checkThat("The output field paragraph contains",
                driver.findElement(
                        By.xpath(getParagraphXPath(2) + "//div[contains(@class, 'text plainTextContent')]"))
                        .getText(),
                CoreMatchers.equalTo("user1"));

        String resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("1"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("1"));
        interpreterModeActionsIT.logoutUser("user1");

        //step 3: (user2) login, create a new note, run two paragraph with 'python', check result, check process, logout
        //                paragraph: Check if the result is 'user2' in the second paragraph
        //System: Check if the number of python interpreter process is '2'
        //System: Check if the number of python process is '2'
        interpreterModeActionsIT.authenticationUser("user2", "password3");
        locator = By.xpath("//div[contains(@class, 'col-md-4')]/div/h5/a[contains(.,'Create new" + " note')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            createNewNote();
        }
        String user2noteId = driver.getCurrentUrl().substring(driver.getCurrentUrl().lastIndexOf("/") + 1);
        waitForParagraph(1, "READY");
        interpreterModeActionsIT.setPythonParagraph(1, "user=\"user2\"");
        waitForParagraph(2, "READY");
        interpreterModeActionsIT.setPythonParagraph(2, "print user");

        collector.checkThat("The output field paragraph contains",
                driver.findElement(
                        By.xpath(getParagraphXPath(2) + "//div[contains(@class, 'text plainTextContent')]"))
                        .getText(),
                CoreMatchers.equalTo("user2"));

        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("2"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("2"));
        interpreterModeActionsIT.logoutUser("user2");

        //step 4: (user1) login, come back note user1 made, run second paragraph, check result,
        //                restart python interpreter in note, check process again, logout
        //paragraph: Check if the result is 'user1' in the second paragraph
        //System: Check if the number of python interpreter process is '1'
        //System: Check if the number of python process is '1'
        interpreterModeActionsIT.authenticationUser("user1", "password2");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        runParagraph(2);
        try {
            waitForParagraph(2, "FINISHED");
        } catch (TimeoutException e) {
            waitForParagraph(2, "ERROR");
            collector.checkThat("Exception in InterpreterModeActionsIT while running Python Paragraph", "ERROR",
                    CoreMatchers.equalTo("FINISHED"));
        }
        collector.checkThat("The output field paragraph contains",
                driver.findElement(
                        By.xpath(getParagraphXPath(2) + "//div[contains(@class, 'text plainTextContent')]"))
                        .getText(),
                CoreMatchers.equalTo("user1"));

        clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        clickAndWait(
                By.xpath("//div[@data-ng-repeat='item in interpreterBindings' and contains(., 'python')]//a"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']" + "[contains(.,'Do you want to restart python interpreter?')]"
                        + "//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));

        locator = By.xpath(
                "//div[@class='modal-dialog'][contains(.,'Do you want to restart python interpreter?')]");
        LOG.info(
                "Holding on until if interpreter restart dialog is disappeared or not in testPerUserIsolatedAction");
        boolean invisibilityStatus = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.invisibilityOfElementLocated(locator));
        if (invisibilityStatus == false) {
            assertTrue("interpreter setting dialog visibility status", invisibilityStatus);
        }
        locator = By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        }

        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("1"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("1"));
        interpreterModeActionsIT.logoutUser("user1");

        //step 5: (user2) login, come back note user2 made, restart python interpreter in note, check process, logout
        //System: Check if the number of python interpreter process is '0'
        //System: Check if the number of python process is '0'
        interpreterModeActionsIT.authenticationUser("user2", "password3");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user2noteId + "')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user2noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        clickAndWait(
                By.xpath("//div[@data-ng-repeat='item in interpreterBindings' and contains(., 'python')]//a"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']" + "[contains(.,'Do you want to restart python interpreter?')]"
                        + "//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));

        locator = By.xpath(
                "//div[@class='modal-dialog'][contains(.,'Do you want to restart python interpreter?')]");
        LOG.info(
                "Holding on until if interpreter restart dialog is disappeared or not in testPerUserIsolatedAction");
        invisibilityStatus = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.invisibilityOfElementLocated(locator));
        if (invisibilityStatus == false) {
            assertTrue("interpreter setting dialog visibility status", invisibilityStatus);
        }
        locator = By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            clickAndWait(By.xpath("//*[@id='actionbar']//span[contains(@uib-tooltip, 'Interpreter binding')]"));
        }

        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("0"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("0"));
        interpreterModeActionsIT.logoutUser("user2");

        //step 6: (user1) login, come back note user1 made, run first paragraph,logout
        //        (user2) login, come back note user2 made, run first paragraph, check process, logout
        //System: Check if the number of python process is '2'
        //System: Check if the number of python interpreter process is '2'
        interpreterModeActionsIT.authenticationUser("user1", "password2");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user1noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        waitForParagraph(1, "FINISHED");
        runParagraph(1);
        try {
            waitForParagraph(1, "FINISHED");
        } catch (TimeoutException e) {
            waitForParagraph(1, "ERROR");
            collector.checkThat("Exception in InterpreterModeActionsIT while running Python Paragraph", "ERROR",
                    CoreMatchers.equalTo("FINISHED"));
        }
        interpreterModeActionsIT.logoutUser("user1");

        interpreterModeActionsIT.authenticationUser("user2", "password3");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user2noteId + "')]");
        element = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + user2noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        runParagraph(1);
        try {
            waitForParagraph(1, "FINISHED");
        } catch (TimeoutException e) {
            waitForParagraph(1, "ERROR");
            collector.checkThat("Exception in InterpreterModeActionsIT while running Python Paragraph", "ERROR",
                    CoreMatchers.equalTo("FINISHED"));
        }
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("2"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("2"));
        interpreterModeActionsIT.logoutUser("user2");

        //step 7: (admin) login, restart python interpreter in interpreter tab, check process, logout
        //System: Check if the number of python interpreter process is 0
        //System: Check if the number of python process is 0
        interpreterModeActionsIT.authenticationUser("admin", "password1");
        pollingWait(By.xpath("//div/button[contains(@class, 'nav-btn dropdown-toggle ng-scope')]"),
                MAX_BROWSER_TIMEOUT_SEC).click();

        clickAndWait(By.xpath("//li/a[contains(@href, '#/interpreter')]"));
        pollingWait(By.xpath("//input[contains(@ng-model, 'searchInterpreter')]"), MAX_BROWSER_TIMEOUT_SEC)
                .sendKeys("python");
        ZeppelinITUtils.sleep(500, false);

        clickAndWait(By.xpath("//div[contains(@id, 'python')]"
                + "//button[contains(@ng-click, 'restartInterpreterSetting(setting.id)')]"));
        clickAndWait(By.xpath(
                "//div[@class='modal-dialog']" + "[contains(.,'Do you want to restart this interpreter?')]"
                        + "//div[@class='bootstrap-dialog-footer-buttons']//button[contains(., 'OK')]"));
        locator = By.xpath(
                "//div[@class='modal-dialog'][contains(.,'Do you want to restart python interpreter?')]");
        LOG.info(
                "Holding on until if interpreter restart dialog is disappeared or not in testPerUserIsolatedAction");
        invisibilityStatus = (new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC))
                .until(ExpectedConditions.invisibilityOfElementLocated(locator));
        if (invisibilityStatus == false) {
            assertTrue("interpreter setting dialog visibility status", invisibilityStatus);
        }

        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsPython, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python process is", resultProcessNum, CoreMatchers.equalTo("0"));
        resultProcessNum = (String) CommandExecutor.executeCommandLocalHost(cmdPsInterpreter, false,
                ProcessData.Types_Of_Data.OUTPUT);
        resultProcessNum = resultProcessNum.trim().replaceAll("\n", "");
        collector.checkThat("The number of python interpreter process is", resultProcessNum,
                CoreMatchers.equalTo("0"));
        interpreterModeActionsIT.logoutUser("admin");
    } catch (Exception e) {
        handleException("Exception in InterpreterModeActionsIT while testPerUserIsolatedAction ", e);
    }
}

From source file:org.apache.zeppelin.integration.PersonalizeActionsIT.java

License:Apache License

@Test
public void testSimpleAction() throws Exception {
    try {/*from w  ww.jav  a 2s  . co  m*/
        // step 1 : (admin) create a new note, run a paragraph and turn on personalized mode
        AuthenticationIT authenticationIT = new AuthenticationIT();
        PersonalizeActionsIT personalizeActionsIT = new PersonalizeActionsIT();
        authenticationIT.authenticationUser("admin", "password1");
        By locator = By
                .xpath("//div[contains(@class, \"col-md-4\")]/div/h5/a[contains(.,'Create new" + " note')]");
        WebDriverWait wait = new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC);
        WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            createNewNote();
        }
        String noteId = driver.getCurrentUrl().substring(driver.getCurrentUrl().lastIndexOf("/") + 1);
        waitForParagraph(1, "READY");
        personalizeActionsIT.setParagraphText("Before");
        collector.checkThat("The output field paragraph contains",
                driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'markdown-body')]"))
                        .getText(),
                CoreMatchers.equalTo("Before"));
        pollingWait(
                By.xpath(
                        "//*[@id='actionbar']" + "//button[contains(@uib-tooltip, 'Switch to personal mode')]"),
                MAX_BROWSER_TIMEOUT_SEC).click();
        clickAndWait(
                By.xpath("//div[@class='modal-dialog'][contains(.,'Do you want to personalize your analysis?')"
                        + "]//div[@class='modal-footer']//button[contains(.,'OK')]"));
        authenticationIT.logoutUser("admin");

        // step 2 : (user1) make sure it is on personalized mode and 'Before' in result of paragraph
        authenticationIT.authenticationUser("user1", "password2");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]");
        wait = new WebDriverWait(driver, MAX_BROWSER_TIMEOUT_SEC);
        element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        collector.checkThat("The personalized mode enables",
                driver.findElement(By.xpath("//*[@id='actionbar']"
                        + "//button[contains(@class, 'btn btn-default btn-xs ng-scope ng-hide')]"))
                        .getAttribute("uib-tooltip"),
                CoreMatchers.equalTo("Switch to personal mode (owner can change)"));
        waitForParagraph(1, "READY");
        runParagraph(1);
        collector.checkThat("The output field paragraph contains",
                driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'markdown-body')]"))
                        .getText(),
                CoreMatchers.equalTo("Before"));
        authenticationIT.logoutUser("user1");

        // step 3 : (admin) change paragraph contents to 'After' and check result of paragraph
        authenticationIT.authenticationUser("admin", "password1");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]");
        element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        waitForParagraph(1, "FINISHED");
        personalizeActionsIT.setParagraphText("After");
        collector.checkThat("The output field paragraph contains",
                driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'markdown-body')]"))
                        .getText(),
                CoreMatchers.equalTo("After"));
        authenticationIT.logoutUser("admin");

        // step 4 : (user1) check whether result is 'Before' or not
        authenticationIT.authenticationUser("user1", "password2");
        locator = By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]");
        element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
        if (element.isDisplayed()) {
            pollingWait(By.xpath("//*[@id='notebook-names']//a[contains(@href, '" + noteId + "')]"),
                    MAX_BROWSER_TIMEOUT_SEC).click();
        }
        collector.checkThat("The output field paragraph contains",
                driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'markdown-body')]"))
                        .getText(),
                CoreMatchers.equalTo("Before"));
        authenticationIT.logoutUser("user1");
    } catch (Exception e) {
        handleException("Exception in PersonalizeActionsIT while testSimpleAction ", e);
    }
}