Example usage for org.openqa.selenium.interactions Actions build

List of usage examples for org.openqa.selenium.interactions Actions build

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions build.

Prototype

public Action build() 

Source Link

Document

Generates a composite action containing all actions so far, ready to be performed (and resets the internal builder state, so subsequent calls to #build() will contain fresh sequences).

Usage

From source file:com.machinepublishers.jbrowserdriver.diagnostics.Test.java

License:Apache License

private void doTests() {
    JBrowserDriver driver = null;//from  w w w  . j  a  v a  2s.c  o  m
    Thread shutdownHook = null;
    try {
        HttpServer.launch(TEST_PORT_HTTP);
        final File cacheDir = Files.createTempDirectory("jbd_test_cache").toFile();
        final File userDataDir = Files.createTempDirectory("jbd_test_userdata").toFile();
        shutdownHook = new Thread(new Runnable() {
            @Override
            public void run() {
                FileUtils.deleteQuietly(cacheDir);
                FileUtils.deleteQuietly(userDataDir);
            }
        });
        Runtime.getRuntime().addShutdownHook(shutdownHook);
        final String mainPage = "http://" + InetAddress.getLoopbackAddress().getHostAddress() + ":"
                + TEST_PORT_HTTP;
        final int ajaxWait = 150;
        final Settings.Builder builder = Settings.builder().processes(TEST_PORTS_RMI)
                .screen(new Dimension(1024, 768)).logger(null).logJavascript(true).ajaxWait(ajaxWait)
                .cacheDir(cacheDir).cache(true).ignoreDialogs(false);
        driver = new JBrowserDriver(builder.build());

        /*
         * Load a page
         */
        driver.get(mainPage);
        test(driver.getStatusCode() == 200);
        long initialRequestId = HttpServer.previousRequestId();

        /*
         * Load page from cache
         */
        driver.get(mainPage);
        test(driver.getStatusCode() == 200);
        test(HttpServer.previousRequestId() == initialRequestId);
        boolean viaHeader = false;
        for (String line : HttpServer.previousRequest()) {
            if (line.toLowerCase().startsWith("via:")) {
                viaHeader = true;
                break;
            }
        }
        test(!viaHeader);

        /*
         * Driver reset
         */
        driver.reset();
        driver.get(mainPage);
        test(driver.getStatusCode() == 200);
        test(HttpServer.previousRequestId() == initialRequestId);
        driver.reset(builder.cacheDir(null).build());
        driver.get(mainPage);
        test(driver.getStatusCode() == 200);
        test(HttpServer.previousRequestId() != initialRequestId);

        /*
         * Javascript logs
         */
        int messages = 0;
        for (LogEntry entry : driver.manage().logs().get("javascript").filter(Level.ALL)) {
            ++messages;
            test(!StringUtils.isEmpty(entry.getMessage()));
        }
        test(messages == 3);

        /*
         * User-data directory
         */
        driver.findElement(By.id("populate-local-storage")).click();
        driver.findElement(By.id("load-from-local-storage")).click();
        test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText()));
        driver.get(mainPage);
        driver.findElement(By.id("load-from-local-storage")).click();
        test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText()));
        driver.reset();
        driver.get(mainPage);
        driver.findElement(By.id("load-from-local-storage")).click();
        test("".equals(driver.findElement(By.id("local-storage-value-holder")).getText()));
        driver.reset(builder.userDataDirectory(userDataDir).build());
        driver.get(mainPage);
        driver.findElement(By.id("populate-local-storage")).click();
        driver.findElement(By.id("load-from-local-storage")).click();
        test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText()));
        driver.reset();
        driver.get(mainPage);
        driver.findElement(By.id("load-from-local-storage")).click();
        test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText()));

        /*
         * Select DOM elements
         */
        test("test-data-attr".equals(driver.findElement(By.id("divtext1")).getAttribute("data-selected")));
        test(driver.findElement(By.id("divtext1")).getAttribute("undefinedattr") == null);
        test(driver.findElement(By.id("divtext1")).getAttribute("innerText").equals("test1"));
        test(driver.findElements(By.name("divs")).size() == 2);
        test(driver.findElements(By.name("divs")).get(1).getAttribute("innerText").equals("test2"));
        test(driver.findElementByClassName("divclass").getAttribute("id").equals("divtext1"));
        test(driver.findElementsByClassName("divclass").get(1).getAttribute("id").equals("divtext2"));
        test(driver.findElementByCssSelector("#divtext1").getAttribute("id").equals("divtext1"));
        test(driver.findElementsByCssSelector("html > *").get(1).getAttribute("id").equals("testbody"));
        test(driver.findElementById("divtext1").getTagName().equals("div"));
        test(driver.findElementsById("divtext1").get(0).getTagName().equals("div"));
        test(driver.findElementByLinkText("anchor").getAttribute("id").equals("anchor1"));
        test(driver.findElementsByLinkText("anchor").get(1).getAttribute("id").equals("anchor2"));
        test(driver.findElementByName("divs").getAttribute("id").equals("divtext1"));
        test(driver.findElementsByName("divs").get(1).getAttribute("id").equals("divtext2"));
        test(driver.findElementByPartialLinkText("anch").getAttribute("id").equals("anchor1"));
        test(driver.findElementsByPartialLinkText("anch").get(1).getAttribute("id").equals("anchor2"));
        test(driver.findElementByTagName("div").getAttribute("id").equals("divtext1"));
        test(driver.findElementsByTagName("div").get(1).getAttribute("id").equals("divtext2"));
        test(driver.findElementByXPath("//*[@id='divtext1']").getAttribute("id").equals("divtext1"));
        test(driver.findElementByTagName("body").findElement(By.xpath("//*[@id='divtext1']")).getAttribute("id")
                .equals("divtext1"));
        test(driver.findElementsByXPath("//html/*").get(1).getAttribute("id").equals("testbody"));
        test(driver.findElement(By.xpath("//a[contains(@href,'1')]")).getAttribute("id").equals("anchor1"));
        test(driver.findElementsByXPath("//a[contains(@href,'!!!')]").isEmpty());
        test(driver.findElementsByClassName("xx").isEmpty());
        test(driver.findElementsByTagName("xx").isEmpty());
        test(driver.findElementsByCssSelector("#xx").isEmpty());
        Throwable error = null;
        try {
            driver.findElementByTagName("xx");
        } catch (NoSuchElementException e) {
            error = e;
        }
        test(error != null);
        error = null;
        try {
            driver.findElementByCssSelector("#xx");
        } catch (NoSuchElementException e) {
            error = e;
        }
        test(error != null);
        error = null;
        try {
            driver.findElementsByXPath("!!!");
        } catch (WebDriverException e) {
            error = e;
        }
        test(error != null);
        error = null;
        try {
            driver.findElement(By.id("divtext1")).findElements(By.cssSelector("???"));
        } catch (WebDriverException e) {
            error = e;
        }
        test(error != null);

        /*
         * WebElement Equals/HashCode
         */
        test(driver.findElements(By.name("divs")).get(0).equals(driver.findElements(By.name("divs")).get(0)));
        test(driver.findElements(By.name("divs")).get(0).hashCode() == driver.findElements(By.name("divs"))
                .get(0).hashCode());

        /*
         * Typing text
         */
        driver.findElement(By.id("text-input")).sendKeys("testing");
        driver.findElement(By.id("text-input")).sendKeys("");
        test(driver.findElement(By.id("text-input")).getAttribute("value").equals("testing"));
        driver.findElement(By.id("text-input")).sendKeys(JBrowserDriver.KEYBOARD_DELETE);
        test(driver.findElement(By.id("text-input")).getAttribute("value") == null);
        driver.findElement(By.id("text-input")).sendKeys("testing");
        test(driver.findElement(By.id("text-input")).getAttribute("value").equals("testing"));
        driver.findElement(By.id("text-input")).clear();
        test(driver.findElement(By.id("text-input")).getAttribute("value") == null);

        /*
         * Clicking on elements
         */
        test(!driver.findElement(By.id("testoption2")).isSelected());
        driver.findElement(By.id("testoption2")).click();
        test(driver.findElement(By.id("testoption2")).isSelected());
        driver.findElement(By.id("testoption1")).click();
        test(driver.findElement(By.id("testoption1")).isSelected());
        driver.findElement(By.id("anchor5")).click();
        test("anchor clicked".equals(driver.findElement(By.id("testspan")).getText()));

        /*
         * Execute javascript
         */
        test(((WebElement) driver.executeScript("return arguments[0];", driver.findElement(By.id("divtext1"))))
                .getAttribute("innerText").equals("test1"));
        test(((WebElement) driver.executeScript("return arguments[0].parentNode;",
                driver.findElement(By.id("divtext1")))).getTagName().equals("body"));
        test(((WebElement) ((JavascriptExecutor) driver.findElement(By.id("divtext1")))
                .executeAsyncScript("arguments[0](this);")).getAttribute("innerText").equals("test1"));
        test((driver.executeAsyncScript("arguments[1](arguments[0].innerText);",
                driver.findElement(By.id("divtext1")))).equals("test1"));
        Map<String, Object> map = (Map<String, Object>) driver.executeScript("return {"
                + "key1:['value1','value2','value3'], " + "key2:5," + "key3:function(){return 'testing';}, "
                + "key4:undefined, key5:null, key6:1/0, key7:0/0, key8:'', key9:[], key10:{}, key11:[{},{}],"
                + "key12:document.getElementById('divtext1'), " + "key13:document.getElementsByName('divs'), "
                + "key14:[document.getElementById('divtext1'),document.getElementsByName('divs'),{subkey1:'subval1'}]};");
        test(map.size() == 14);
        test(((List) map.get("key1")).size() == 3);
        test(((List) map.get("key1")).get(2).equals("value3"));
        test(((List) map.get("key1")).get(2) instanceof String);
        test(map.get("key2").equals(new Long(5)));
        test("function () {return 'testing';}".equals(map.get("key3"))
                || "function (){return 'testing';}".equals(map.get("key3")));
        test(map.get("key4") == null);
        test(map.get("key5") == null);
        test(Double.isInfinite(((Double) map.get("key6")).doubleValue()));
        test(Double.isNaN(((Double) map.get("key7")).doubleValue()));
        test("".equals(map.get("key8")));
        test(map.get("key9") instanceof List);
        test(map.get("key10") instanceof Map);
        test(((List) map.get("key11")).size() == 2);
        test(((Map) ((List) map.get("key11")).get(1)).isEmpty());
        test("test1".equals(((WebElement) map.get("key12")).getAttribute("innerText")));
        test(((List<WebElement>) map.get("key13")).size() == 2);
        test(((List<WebElement>) map.get("key13")).get(1).getAttribute("innerText").equals("test2"));
        test(((List) map.get("key14")).size() == 3);
        test(((List) ((List) map.get("key14")).get(1)).size() == 2);
        test(((WebElement) ((List) ((List) map.get("key14")).get(1)).get(1)).getAttribute("innerText")
                .equals("test2"));
        test(((Map) ((List) map.get("key14")).get(2)).size() == 1);
        test("subval1".equals(((Map) ((List) map.get("key14")).get(2)).get("subkey1")));
        test(((List) driver.executeScript("return [];")).isEmpty());
        test(((Map) driver.executeScript("return {};")).isEmpty());
        error = null;
        try {
            driver.executeScript("invalid.execute()");
        } catch (WebDriverException e) {
            error = e;
        }
        test(error != null);

        /*
         * DOM element properties
         */
        WebElement element = driver.findElement(By.id("divtext1"));
        Point point = element.getLocation();
        test(point.getX() > 0);
        test(point.getY() > 0);
        Dimension dimension = element.getSize();
        test(dimension.width > 0);
        test(dimension.height > 0);
        Rectangle rect = element.getRect();
        test(rect.x == point.getX());
        test(rect.y == point.getY());
        test(rect.width == dimension.getWidth());
        test(rect.height == dimension.getHeight());
        test("Testing\ntext.".equals(driver.findElement(By.id("text-node1")).getText()));
        test("".equals(driver.findElement(By.id("text-node2")).getText()));
        test("".equals(driver.findElement(By.id("text-node3")).getText()));
        List<WebElement> options = driver.findElementsByCssSelector("#testselect option");
        test(options.size() == 2);
        test(options.get(0).isSelected());
        test(!options.get(1).isSelected());
        test(driver.findElementById("checkbox1").isSelected());
        test(!driver.findElementById("checkbox2").isSelected());

        /*
         * Cookie manager
         */
        driver.manage().addCookie(new Cookie("testname", "testvalue"));
        Cookie cookie = driver.manage().getCookieNamed("testname");
        test(cookie.getValue().equals("testvalue"));
        test(InetAddress.getLoopbackAddress().getHostAddress().equals(cookie.getDomain()));

        /*
         * Screenshots
         */
        test(driver.getScreenshotAs(OutputType.BYTES).length > 0);

        /*
         * File Input Type
         */
        driver.findElement(By.id("upload")).sendKeys("some-file");
        test("event-test".equals(driver.findElement(By.id("file-input-onchange")).getText()));
        test(driver.findElement(By.id("upload")).getAttribute("value").endsWith("some-file"));

        /*
         * Javascript alerts
         */
        driver.findElement(By.tagName("button")).click();
        test(driver.switchTo().alert().getText().equals("test-alert"));
        driver.switchTo().alert().dismiss();
        test(driver.switchTo().alert().getText().equals("test-confirm"));
        driver.switchTo().alert().dismiss();
        test(driver.switchTo().alert().getText().equals("test-prompt"));
        driver.switchTo().alert().sendKeys("test-input");
        driver.switchTo().alert().accept();
        test(driver.findElement(By.id("testspan")).getAttribute("innerHTML").equals("test-input"));

        /*
         * Request headers
         */
        List<String> request = HttpServer.previousRequest();
        if (TEST_PORT_HTTP != 443 && TEST_PORT_HTTP != 80) {
            test(request.get(1).endsWith(":" + TEST_PORT_HTTP));
        }
        test(request.size() > 1);
        Set<String> headers = new HashSet<String>();
        for (String line : request) {
            if (line.contains(":")) {
                headers.add(line.split(":")[0].toLowerCase());
            }
        }
        test(request.size() - 2 == headers.size());

        /*
         * HTTP Post
         */
        driver.findElement(By.id("form-submit")).click();
        test(driver.getStatusCode() == 201);
        test("form-field=test-form-value"
                .equals(HttpServer.previousRequest().get(HttpServer.previousRequest().size() - 1)));

        /*
         * Frames
         */
        driver.switchTo().frame(driver.findElementByTagName("iframe"));
        test(driver.findElementById("iframebody") != null);
        driver.switchTo().parentFrame();
        test(driver.findElementById("testbody") != null);
        driver.switchTo().frame(0);
        test(driver.findElementById("iframebody") != null);
        driver.switchTo().defaultContent();
        driver.switchTo().frame("testiframe");
        test(driver.findElementById("iframebody") != null);
        driver.get(mainPage);
        test(driver.getPageSource() != null);
        driver.switchTo().frame(driver.findElementByTagName("iframe"));
        test(driver.findElementById("iframebody") != null);
        driver.switchTo().parentFrame();
        driver.findElement(By.id("anchor3")).click();
        test(driver.getPageSource() != null);
        driver.switchTo().frame(driver.findElementByTagName("iframe"));
        driver.findElement(By.id("iframe-anchor")).click(); //TODO iframe coord offset needed on any other methods?
        driver.pageWait();
        test(HttpServer.previousRequest().get(0).startsWith("GET /iframe.htm?param=fromiframe"));
        driver.get(mainPage);
        driver.switchTo().frame(driver.findElementByTagName("iframe"));
        Actions actions = new Actions(driver);
        actions.moveToElement(driver.findElement(By.id("iframe-anchor")));
        actions.click();
        actions.build().perform();
        driver.pageWait();
        test(HttpServer.previousRequest().get(0).startsWith("GET /iframe.htm?param=fromiframe"));
        driver.get(mainPage);
        driver.switchTo().frame(driver.findElementByTagName("iframe"));
        driver.getMouse().click(((Locatable) driver.findElement(By.id("iframe-anchor"))).getCoordinates());
        driver.getMouse().mouseMove(((Locatable) driver.findElement(By.id("iframe-anchor"))).getCoordinates(),
                5, 5);
        driver.pageWait();
        test(HttpServer.previousRequest().get(0).startsWith("GET /iframe.htm?param=fromiframe"));
        //TODO fingerprinting
        //System.out.println(driver.findElement(By.id("iframe-useragent")).getAttribute("innerHTML"));
        //System.out.println(driver.findElement(By.id("iframe-nested-useragent")).getAttribute("innerHTML"));

        /*
         * Redirects and cookies
         */
        driver.get(mainPage + "/redirect/site1#testfragment");
        test(HttpServer.previousRequestId() != initialRequestId);
        test(driver.getStatusCode() == 200);
        test(driver.getCurrentUrl().endsWith("/redirect/site2#testfragment"));
        cookie = driver.manage().getCookieNamed("JSESSIONID");
        test(cookie.getValue().equals("ABC123"));
        test(InetAddress.getLoopbackAddress().getHostAddress().equals(cookie.getDomain()));

        /*
         * Cookies set by Javascript
         */
        test("jsCookieValue1".equals(driver.manage().getCookieNamed("jsCookieName1").getValue()));
        test("jsCookieValue2".equals(driver.manage().getCookieNamed("jsCookieName2").getValue()));
        test("jsCookieValue3".equals(driver.manage().getCookieNamed("jsCookieName3").getValue()));
        test("jsCookieValue4".equals(driver.manage().getCookieNamed("jsCookieName4").getValue()));

        /*
         * Window size and position
         */
        driver.manage().window().setSize(new Dimension(5000, 5000));
        test(driver.manage().window().getSize().getWidth() == 1024);
        test(driver.manage().window().getSize().getHeight() == 768);
        driver.manage().window().setSize(new Dimension(800, 600));
        test(driver.manage().window().getSize().getWidth() == 800);
        test(driver.manage().window().getSize().getHeight() == 600);
        driver.manage().window().setPosition(new Point(5000, 5000));
        test(driver.manage().window().getPosition().getX() == 224);
        test(driver.manage().window().getPosition().getY() == 168);
        driver.manage().window().setPosition(new Point(20, 50));
        test(driver.manage().window().getPosition().getX() == 20);
        test(driver.manage().window().getPosition().getY() == 50);
        driver.manage().window().maximize();
        test(driver.manage().window().getPosition().getX() == 0);
        test(driver.manage().window().getPosition().getY() == 0);
        test(driver.manage().window().getSize().getWidth() == 1024);
        test(driver.manage().window().getSize().getHeight() == 768);
        driver.manage().window().setSize(new Dimension(800, 600));
        driver.manage().window().setPosition(new Point(20, 50));
        driver.manage().window().fullscreen();
        test(driver.manage().window().getPosition().getX() == 0);
        test(driver.manage().window().getPosition().getY() == 0);
        test(driver.manage().window().getSize().getWidth() == 1024);
        test(driver.manage().window().getSize().getHeight() == 768);
        driver.manage().window().fullscreen();
        test(driver.manage().window().getPosition().getX() == 20);
        test(driver.manage().window().getPosition().getY() == 50);
        test(driver.manage().window().getSize().getWidth() == 800);
        test(driver.manage().window().getSize().getHeight() == 600);
        driver.manage().window().setSize(new Dimension(400, 200));
        driver.manage().window().setPosition(new Point(10, 30));
        test(driver.manage().window().getPosition().getX() == 10);
        test(driver.manage().window().getPosition().getY() == 30);
        test(driver.manage().window().getSize().getWidth() == 400);
        test(driver.manage().window().getSize().getHeight() == 200);
        driver.manage().window().setSize(new Dimension(1024, 768));
        test(driver.manage().window().getPosition().getX() == 0);
        test(driver.manage().window().getPosition().getY() == 0);
        test(driver.manage().window().getSize().getWidth() == 1024);
        test(driver.manage().window().getSize().getHeight() == 768);

        /*
         * Element visibility
         */
        test(driver.findElement(By.id("iframe-anchor")).isDisplayed());
        test(!driver.findElement(By.id("anchor-visibility-hidden")).isDisplayed());
        test(!driver.findElement(By.id("anchor-display-none")).isDisplayed());
        error = null;
        try {
            driver.findElement(By.id("anchor-visibility-hidden")).click();
        } catch (ElementNotVisibleException e) {
            error = e;
        }
        test(error != null);
        error = null;
        try {
            driver.findElement(By.id("anchor-display-none")).click();
        } catch (ElementNotVisibleException e) {
            error = e;
        }
        test(error != null);

        /*
         * Operations on elements that no longer exist
         */
        WebElement body = driver.findElement(By.tagName("body"));
        test(!StringUtils.isEmpty(body.getAttribute("outerHTML")));
        driver.get("about:blank");
        error = null;
        try {
            body.getAttribute("outerHTML");
        } catch (StaleElementReferenceException e) {
            error = e;
        }
        test(error != null);

        /*
         * Timeouts
         */
        driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.MILLISECONDS);
        error = null;
        try {
            driver.get(mainPage + "/wait-forever");
        } catch (TimeoutException e) {
            error = e;
        }
        test(error != null);

    } catch (Throwable t) {
        outputError(testLabel("failed", curTest + 1, t));
    } finally {
        try {
            driver.quit();
        } catch (Throwable t) {
            outputError(toString(t));
        }
        try {
            HttpServer.stop();
        } catch (Throwable t) {
            outputError(toString(t));
        }
        try {
            Runtime.getRuntime().removeShutdownHook(shutdownHook);
            shutdownHook.run();
        } catch (Throwable t) {
        }
    }
}

From source file:com.mkl.websuites.internal.command.impl.key.PressCommand.java

License:Apache License

@Override
protected void runStandardCommand() {
    Actions action = new Actions(browser);
    String[] keyTokens = keyCombination.trim().toUpperCase(Locale.getDefault()).split("-");
    for (String key : keyTokens) {
        if (isModifier(key)) {
            action = action.keyUp(keyFromModifier(key));
        } else {/*from ww w  .j  a  va  2s.c  o  m*/
            action = action.sendKeys(keyFromString(key));
        }
    }
    action.build().perform();
}

From source file:com.pentaho.ctools.cde.reference.AddinReferenceEdit.java

License:Apache License

/**
 *
 * @param value/*  w w  w . j  a  v a  2  s .  com*/
 */
private void ChangeFontSize(String value) {
    this.log.info("ChangeFontSize");
    driver.get(PageUrl.ADDIN_REFERENCE_EDIT);

    //Expand first row - Title
    this.elemHelper.ClickJS(driver, By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[5]/td/span"));
    //Click in HTML to open the Properties
    Actions acts = new Actions(driver);
    acts.click(this.elemHelper.FindElement(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[6]/td[1]")));
    acts.build().perform();
    //Click in field 'Font Size' to be editable
    this.elemHelper.ClickJS(driver, By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr[3]/td[2]"));
    //Write 34
    this.elemHelper.FindElement(driver, By.name("value")).clear();
    this.elemHelper.SendKeys(driver, By.name("value"), value);
    this.elemHelper.FindElement(driver, By.name("value")).submit();
    this.bFontChanged = true;
    //Save the changes
    this.elemHelper.ClickJS(driver, By.linkText("Save"));
    //Wait for element present and invisible
    this.elemHelper.WaitForElementVisibility(driver, By.xpath("//div[@id='notifyBar']"));
    this.elemHelper.WaitForElementInvisibility(driver, By.xpath("//div[@id='notifyBar']"));
}

From source file:com.pentaho.ctools.cde.require.AddinReferenceEdit.java

License:Apache License

/**
 *
 * @param value/* w ww  .  j a va 2  s  .com*/
 */
private void ChangeFontSize(String value) {
    this.log.info("ChangeFontSize");
    driver.get(PageUrl.ADDIN_REFERENCE_REQUIRE_EDIT);

    //Expand first row - Title
    this.elemHelper.ClickJS(driver, By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[5]/td/span"));
    //Click in HTML to open the Properties
    Actions acts = new Actions(driver);
    acts.click(this.elemHelper.FindElement(driver,
            By.xpath("//table[@id='table-cdfdd-layout-tree']/tbody/tr[6]/td[1]")));
    acts.build().perform();
    //Click in field 'Font Size' to be editable
    this.elemHelper.ClickJS(driver, By.xpath("//table[@id='table-cdfdd-layout-properties']/tbody/tr[3]/td[2]"));
    //Write 34
    this.elemHelper.FindElement(driver, By.name("value")).clear();
    this.elemHelper.SendKeys(driver, By.name("value"), value);
    this.elemHelper.FindElement(driver, By.name("value")).submit();
    this.bFontChanged = true;
    //Save the changes
    this.elemHelper.ClickJS(driver, By.linkText("Save"));
    //Wait for element present and invisible
    this.elemHelper.WaitForElementVisibility(driver, By.xpath("//div[@id='notifyBar']"));
    this.elemHelper.WaitForElementInvisibility(driver, By.xpath("//div[@id='notifyBar']"));
}

From source file:com.pentaho.ctools.cdf.CommentComponent.java

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name:/*from  www  .  j ava 2s .  c o  m*/
 *    Display Page
 * Description:
 *    We pretend validate to check if a comment is removed.
 * Steps:
 *    1. Add a comment
 *    2. Remove added comment
 */
@Test
public void tc5_RemoveCoomment_CommentRemoved() {
    this.log.info("tc5_RemoveCoomment_CommentRemoved");
    this.tcRemoveComment = true;
    /*
     * Guarantee no comments displayed
     */
    cleanAllComments();

    String commentText = "Some comment!";
    String noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    String addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);

    /*
     * ## Step 1
     */
    this.elemHelper.ClickJS(driver, By.cssSelector("div.addComment"));
    //Insert the text
    this.elemHelper.FindElement(driver, By.cssSelector("textarea.addCommentText")).sendKeys(commentText);
    this.elemHelper.ClickJS(driver, By.cssSelector("div.saveComment"));
    //wait for the page rendered
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.navigateRefresh")));
    //Check if the comment was added
    String commentAdded = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div"));
    assertEquals(commentAdded, commentText);

    /*
     * ## Step 2
     */
    Actions acts = new Actions(driver);
    acts.moveToElement(this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div")));
    acts.build().perform();
    acts.perform();
    acts.moveToElement(this.elemHelper.FindElement(driver, By.cssSelector("div.archive")));
    acts.click();
    acts.perform();
    //Check we don't have more comments
    noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);
    String refreshComments = this.elemHelper.WaitForElementPresentGetText(driver,
            By.cssSelector("div.navigateRefresh"));
    assertEquals("Refresh", refreshComments);
}

From source file:com.pentaho.ctools.cdf.require.CommentComponent.java

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name:/* w  w w .j  av a2s. com*/
 *    Display Page
 * Description:
 *    We pretend validate to check if a comment is removed.
 * Steps:
 *    1. Add a comment
 *    2. Remove added comment
 */
@Test
public void tc5_RemoveComment_CommentRemoved() {
    this.log.info("tc5_RemoveComment_CommentRemoved");
    this.tcRemoveComment = true;
    /*
     * Guarantee no comments displayed
     */
    cleanAllComments();

    String commentText = "Some comment!";
    String noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    String addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);

    /*
     * ## Step 1
     */
    this.elemHelper.ClickJS(driver, By.cssSelector("div.addComment"));
    //Insert the text
    this.elemHelper.FindElement(driver, By.cssSelector("textarea.addCommentText")).sendKeys(commentText);
    this.elemHelper.ClickJS(driver, By.cssSelector("div.saveComment"));
    //wait for the page rendered
    this.elemHelper.WaitForElementPresence(driver, By.cssSelector("div.navigateRefresh"));
    //Check if the comment was added
    String commentAdded = this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div"));
    assertEquals(commentAdded, commentText);

    /*
     * ## Step 2
     */
    Actions acts = new Actions(driver);
    acts.moveToElement(this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='sampleObject']/div/div/div[1]/div[2]/div")));
    acts.build().perform();
    acts.perform();
    acts.moveToElement(this.elemHelper.FindElement(driver, By.cssSelector("div.archive")));
    acts.click();
    acts.perform();
    //Check we don't have more comments
    noComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.comment"));
    assertEquals("No Comments to show!", noComments);
    addComments = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.addComment"));
    assertEquals("Add Comment", addComments);
    String refreshComments = this.elemHelper.WaitForElementPresentGetText(driver,
            By.cssSelector("div.navigateRefresh"));
    assertEquals("Refresh", refreshComments);
}

From source file:com.pentaho.ctools.utils.ElementHelper.java

License:Apache License

/**
 * This method shall perform the MoveToElement wrap function of WebDriver.
 * We have to do this wrap to avoid StaleElement exceptions.
 * //from ww  w  . j a v  a  2 s .c  o m
 * @param driver
 * @param toLocator
 */
public void MoveToElement(final WebDriver driver, final By toLocator) {
    this.log.debug("MoveToElement::Enter");
    try {
        WebElement element = FindElementInvisible(driver, toLocator);
        if (element != null) {
            Actions acts = new Actions(driver);
            acts.moveToElement(element);
            acts.build().perform();
        } else {
            this.log.warn("Element null!");
        }
    } catch (StaleElementReferenceException sere) {
        this.log.warn("Stale Element Reference Exception");
        MoveToElement(driver, toLocator);
    }
    this.log.debug("MoveToElement::Exit");
}

From source file:com.pentaho.ctools.utils.ElementHelper.java

License:Apache License

/**
 * This method shall perform the MoveToElement wrap function of WebDriver.
 * We have to do this wrap to avoid StaleElement exceptions.
 * // w ww.j  a v  a 2  s . c o  m
 * @param driver
 * @param toLocator
 * @param xOffset
 * @param yOffset
 */
public void MoveToElement(final WebDriver driver, final By toLocator, final int xOffset, final int yOffset) {
    this.log.debug("MoveToElement::Enter");
    try {
        WebElement element = WaitForElementPresenceAndVisible(driver, toLocator);
        if (element != null) {
            Actions acts = new Actions(driver);
            acts.moveToElement(element, xOffset, yOffset);
            acts.build().perform();
        } else {
            this.log.warn("Element null!");
        }
    } catch (StaleElementReferenceException sere) {
        this.log.warn("Stale Element Reference Exception");
        MoveToElement(driver, toLocator, xOffset, yOffset);
    }
    this.log.debug("MoveToElement::Exit");
}

From source file:com.pentaho.gui.web.puc.BrowseFiles.java

License:Apache License

/**
 * This method will empty a folder in the repository given the full path to it, including the folder name
 *
 * Ex. "/public/plugin-samples/pentaho-cdf-dd" the SelectFolder method will be called with the path provided, it it
 * returns false an info will be shown on the logs saying the file wasn't deleted for it wasn't found. If it returns
 * true, all files shown on the files table will be selected, Delete button will be clicked on File Actions, it will
 * wait for popup and confirm the delete action.
 *
 * @param path//from  w  w  w  .j av  a 2s.c  o  m
 */
public void EmptyFolder(String path) {
    if (SelectFolder(path)) {
        WebElement listFiles = this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                By.xpath("//div[@id='fileBrowserFiles']/div[2]"));
        List<WebElement> AllFolderFiles = listFiles.findElements(By.xpath("//div[@class='title']"));

        // Check if the widget named exist
        if (AllFolderFiles != null) {
            if (AllFolderFiles.size() > 0) {
                WebElement[] arrayAllFolderFiles = new WebElement[AllFolderFiles.size()];
                AllFolderFiles.toArray(arrayAllFolderFiles);

                // Where we want to select three files
                // <the widget>
                // <the widget>.cdfde
                // <the widget>.component.xml
                // To do that we select each file (using the CONTROL key) and delete them.
                Actions action = new Actions(this.DRIVER);
                action.keyDown(Keys.CONTROL);
                for (WebElement arrayAllFolderFile : arrayAllFolderFiles) {
                    action.click(arrayAllFolderFile);
                }
                action.keyUp(Keys.CONTROL);
                action.build().perform();

                // Here we still in the iframe
                assertNotNull(this.elemHelper.WaitForElementVisibility(this.DRIVER, By.id("deleteButton")));
                this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("deleteButton")).click();
                // Go back to root html
                this.DRIVER.switchTo().defaultContent();
                assertEquals(this.elemHelper
                        .WaitForElementPresenceAndVisible(this.DRIVER, By.cssSelector("div.gwt-HTML"))
                        .getText(), "Are you sure you want to move all selected items to the trash?");
                this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("okButton")).click();

                // wait for visibility of waiting pop-up
                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("//div[@class='busy-indicator-container waitPopup']"));

                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("//div[@class='spinner large-spinner']"));
                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("(//div[@class='spinner large-spinner'])[2]"));

            }
        }
    } else {
        LOG.info("folder not emptied for it was not found");
    }
}

From source file:com.pentaho.gui.web.puc.BrowseFiles.java

License:Apache License

/**
 * Given the path to a folder this method will delete all files located in that folder that contain a specific string
 * in the name//from ww  w  .j a v a 2s . c o m
 *
 * Ex. "/public/plugin-samples/pentaho-cdf-dd" the SelectFolder method will be called with the path provided, it it
 * returns false an info will be shown on the logs saying the file wasn't deleted for it wasn't found.
 *
 * If it returns true, all files containing string "name" provided in the name will be selected, Delete button will be
 * clicked on File Actions, it will wait for popup and confirm the delete action.
 *
 * @param path
 * @param name
 */
public void DeleteMultipleFilesByName(String path, String name) {
    LOG.debug("DeleteMultipleFilesByName::Enter");
    if (SelectFolder(path)) {
        LOG.debug("Deleting [" + path + "] with name [" + name + "]");

        WebElement elemWidgetFile = this.elemHelper.WaitForElementPresence(this.DRIVER,
                By.cssSelector("div[title='" + name + ".wcdf']"), 1);
        if (elemWidgetFile != null) {
            WebElement listFiles = this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                    By.xpath("//div[@id='fileBrowserFiles']/div[2]"));
            List<WebElement> theNamedFiles = listFiles
                    .findElements(By.xpath("//div[@class='title' and contains(text(),'" + name + "')]"));

            // Check if the widget named exist
            if (theNamedFiles != null) {
                if (theNamedFiles.size() > 0) {
                    WebElement[] arraytheNamedFiles = new WebElement[theNamedFiles.size()];
                    theNamedFiles.toArray(arraytheNamedFiles);

                    // Where we want to select three files
                    // <the widget>
                    // <the widget>.cdfde
                    // <the widget>.component.xml
                    // To do that we select each file (using the CONTROL key) and delete them.
                    Actions action = new Actions(this.DRIVER);
                    action.keyDown(Keys.CONTROL);
                    for (WebElement arraytheNamedFile : arraytheNamedFiles) {
                        action.click(arraytheNamedFile);
                    }
                    action.keyUp(Keys.CONTROL);
                    action.build().perform();

                    // Here we still in the iframe
                    assertNotNull(this.elemHelper.WaitForElementVisibility(this.DRIVER, By.id("deleteButton")));
                    this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("deleteButton"))
                            .click();
                    // Go back to root html
                    this.DRIVER.switchTo().defaultContent();
                    assertEquals(
                            this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                                    By.cssSelector("div.gwt-HTML")).getText(),
                            "Are you sure you want to move all selected items to the trash?");
                    this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("okButton")).click();

                    // wait for visibility of waiting pop-up
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='busy-indicator-container waitPopup']"));

                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.id("applicationShell")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//iframe[@id='browser.perspective']")));
                    this.DRIVER.switchTo().frame("browser.perspective");

                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.id("fileBrowser")));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='spinner large-spinner']"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("(//div[@class='spinner large-spinner'])[2]"));

                    this.elemHelper.Click(this.DRIVER, By.id("refreshBrowserIcon"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='spinner large-spinner']"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("(//div[@class='spinner large-spinner'])[2]"));

                    // Assert Panels
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserFolders']")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserFiles']")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserButtons']")));
                    LOG.info("Exit: Assert browser perspective shown");
                } else {
                    LOG.debug("No file exist!");
                }
            } else {
                LOG.debug("Null - No file exist!");
            }
        } else {
            LOG.warn("The widget does not exist.");
        }
    } else {
        LOG.info("Files were not deleted or folder was not found!");
    }
}