Example usage for org.openqa.selenium By id

List of usage examples for org.openqa.selenium By id

Introduction

In this page you can find the example usage for org.openqa.selenium By id.

Prototype

public static By id(String id) 

Source Link

Usage

From source file:co.edu.uniandes.csw.RigitalApp.test.WorkstationTest.java

@Test
public void testBuscarMaquina() throws Exception {

    driver.findElement(By.xpath("//button[contains(@id,'button-search')]")).click();

    Thread.sleep(2000);/*from   w w  w. j  a va  2  s  .  co  m*/

    driver.findElement(By.id("btn_name")).click();

    Thread.sleep(2000);

    driver.findElement(By.id("name")).clear();

    driver.findElement(By.id("name")).sendKeys("DB2IM");

    Thread.sleep(2000);

    driver.findElement(By.xpath("//button[contains(@id,'button-exec-search')]")).click();

    Thread.sleep(2000);

    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table-striped')]/tbody/tr"));
    boolean success = true;

    for (WebElement webElement : table) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));
        success = success && elems.get(1).getText().contains("DB2IM");
    }

    assertTrue(success);
}

From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java

@Test
public void testCreateUserMaster() throws Exception {

    /**//from  ww  w  . ja  v  a 2s  .  c o m
    * Comando que realiza click sobre el boton "create" del toolbar del maestro. La
    * funcin 'find' encuentra el control y posteriormente hace clic en el
    * mismo. La forma en la que se busca el control es utilizando
    * expresiones xPath ya que los id de los mismos nunca son iguales (se
    * generan con junto con el valor de componentId que vara).
    */
    driver.findElement(By.xpath("//button[@class='btn btn-default dropdown-toggle']")).click();
    Thread.sleep(1000);
    String User = "User Master";
    driver.findElement(By.xpath("//a[contains(text(),'" + User + "')]")).click();
    Thread.sleep(3000);
    //Es necesario cambiar de iframe :)
    driver.switchTo().frame(driver.findElement(By.id("container")));
    driver.findElement(By.xpath("//button[contains(@id,'createButton')]")).click();
    Thread.sleep(2000);
    dataUser = InitializeDataUserMaster.generateUser();
    driver.findElement(By.id("userName")).clear();
    driver.findElement(By.id("userName")).sendKeys(dataUser.getUserName());
    driver.findElement(By.id("firstName")).clear();
    driver.findElement(By.id("firstName")).sendKeys(dataUser.getFirstName());
    driver.findElement(By.id("lastName")).clear();
    driver.findElement(By.id("lastName")).sendKeys(dataUser.getLastName());
    driver.findElement(By.id("docNumber")).clear();
    driver.findElement(By.id("docNumber")).sendKeys(dataUser.getDocNumber());
    String Address = "Address";
    driver.findElement(By.xpath("//a[contains(text(),'" + Address + "')]")).click();
    Thread.sleep(2500);
    //*[@id="93-createButton"] /html/body/div[1]/div[2]/div/div[1]/div[1]/nav/div[2]/form/button
    driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/nav/div[2]/form/button")).click();
    dataAddress = InitializeDataUserMaster.generateAddress();
    Thread.sleep(2000);
    driver.findElement(By.id("street")).clear();
    driver.findElement(By.id("street")).sendKeys(dataAddress.getStreet());
    driver.findElement(By.id("aveneu")).clear();
    driver.findElement(By.id("aveneu")).sendKeys(dataAddress.getAveneu());
    driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/nav/div[2]/form/button[2]"))
            .click();
    Thread.sleep(2000);
    driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click();
    Thread.sleep(2000);
    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    boolean success = false;
    for (WebElement webElement : table) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));
        if (elems.get(0).getText().equals(dataUser.getUserName())
                && elems.get(1).getText().equals(dataUser.getFirstName())) {
            success = true;
        }
    }

    assertTrue(success);
}

From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java

@Test
public void testEditAddress() throws Exception {

    driver.get(baseUrl + "/sport.web/userMaster.html");
    Thread.sleep(2000);/* w ww .j a va  2  s  .c o  m*/
    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    if (table.size() > 0) {
        //Trae el ultimo elemento fila y hace click
        driver.findElements(By.linkText("Edit")).get(driver.findElements(By.linkText("Edit")).size() - 1)
                .click();
        Thread.sleep(2000);
        String Address = "Address";
        driver.findElement(By.xpath("//a[contains(text(),'" + Address + "')]")).click();
        Thread.sleep(2500);
        //El mock no esta guardando el detalle address
        driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[3]/div/table/tbody/tr/td[4]/a[1]"))
                .click();//create       

        dataAddress = InitializeDataUserMaster.generateAddress();
        Thread.sleep(2000);
        driver.findElement(By.id("street")).clear();
        driver.findElement(By.id("street")).sendKeys(dataAddress.getStreet());
        driver.findElement(By.id("aveneu")).clear();
        driver.findElement(By.id("aveneu")).sendKeys(dataAddress.getAveneu());
        driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[1]/nav/div[2]/form/button[2]"))
                .click();//save
        Thread.sleep(2000);
        List<WebElement> tables = driver
                .findElements(By.xpath("/html/body/div[1]/div[2]/div/div[1]/div[3]/div/table/tbody/tr"));

        boolean success = false;
        for (WebElement webElement : tables) {
            List<WebElement> elems = webElement.findElements(By.xpath("td"));
            if (elems.get(0).getText().equals(dataAddress.getStreet())
                    && elems.get(1).getText().equals(dataAddress.getAveneu())) {
                success = true;
            }
        }

        driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click();
        Thread.sleep(2000);

        assertTrue(success);

    }
}

From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java

/**
 * CreateUserSport-> Crea un nuevo User y le asocia varios elementos sport
 * /*from   w  w  w. j ava 2  s .  co m*/
 */
@Test
public void createUserSport() throws Exception {

    Thread.sleep(2000);

    driver.get(baseUrl + "/sport.web/userMaster.html");
    Thread.sleep(5000);
    driver.findElement(By.xpath("//button[contains(@id,'createButton')]")).click();
    Thread.sleep(2000);
    driver.findElement(By.id("userName")).clear();
    driver.findElement(By.id("userName")).sendKeys("nombre");
    driver.findElement(By.id("firstName")).clear();
    driver.findElement(By.id("firstName")).sendKeys("nombre1");
    driver.findElement(By.id("lastName")).clear();
    driver.findElement(By.id("lastName")).sendKeys("nombre2");
    //HREF indicando el tab de detalle a seleccionar
    driver.findElement(By.xpath("//a[contains(@href,'sport')]")).click();
    Thread.sleep(2000);
    driver.findElement(By.xpath("//button[contains(@id,'addButton')]")).click();
    //Toma todos los webElement cuyo id sea "selection" y de tipo checkbox.
    List<WebElement> lst = driver
            .findElements(By.xpath("//input[contains(@id,'selection')][@type='checkbox']"));
    for (WebElement lst1 : lst) {
        if (!lst1.isSelected()) {
            lst1.click(); // Si no esta seleccionado hace click en el checkbox, agrega todos los deportes existentes
        }
    }
    driver.findElement(By.id("addButton")).click();
    List<WebElement> tables = driver.findElement(By.xpath("//div[contains(@id,'sport')]"))
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    if (tables.size() != lst.size()) {
        fail();
    }
    driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click();
    Thread.sleep(3000);
    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    boolean fail = false;
    for (WebElement webElement : table) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));
        if (elems.get(0).getText().equals("nombre") && elems.get(1).getText().equals("nombre1")) {
            fail = true;
        }
    }
    assertTrue(fail);
}

From source file:co.edu.uniandes.csw.sport.master.test.SportMasterTest.java

/**
 * editUserSport-> Edita un User existente que tiene varios sports asociados. 1. Elimina todos los elementos sports asociados 2. Agrega varios sports 3. Verfica que el objeto haya sido actualizado
 * //from   w  w w . j  a  v  a 2 s .co  m
 */
@Test
public void editUserSport() throws Exception {

    driver.get(baseUrl + "/sport.web/userMaster.html");
    driver.findElements(By.linkText("Edit")).get(driver.findElements(By.linkText("Edit")).size() - 1).click();
    Thread.sleep(2000);
    driver.findElement(By.id("userName")).clear();
    driver.findElement(By.id("userName")).sendKeys("nombre1mod");
    driver.findElement(By.id("firstName")).clear();
    driver.findElement(By.id("firstName")).sendKeys("nombre2mod");
    driver.findElement(By.xpath("//a[contains(@href,'sport')]")).click();
    Thread.sleep(2000);
    List<WebElement> tables = driver
            .findElements(By.xpath("/html/body/div[1]/div[2]/div/div[2]/div[3]/div/table/tbody/tr"));
    SportDTO sport;
    Thread.sleep(2000);
    for (WebElement table : tables) {
        driver.findElements(By.linkText("Delete")).get(driver.findElements(By.linkText("Delete")).size() - 1)
                .click();
        Thread.sleep(2000);
    }

    driver.findElement(By.xpath("//button[contains(@id,'addButton')]")).click();
    List<WebElement> lst = driver
            .findElements(By.xpath("//input[contains(@id,'selection')][@type='checkbox']"));
    for (WebElement lst1 : lst) {
        if (!lst1.isSelected()) {
            lst1.click();
        }
    }
    driver.findElement(By.id("addButton")).click();
    Thread.sleep(2000);
    driver.findElement(By.xpath("//button[contains(@id,'saveButton')]")).click();
    Thread.sleep(3000);
    List<WebElement> table = driver
            .findElements(By.xpath("//table[contains(@class,'table striped')]/tbody/tr"));
    boolean fail = false;
    for (WebElement webElement : table) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));
        if (elems.get(0).getText().equals("nombre1mod") && elems.get(1).getText().equals("nombre2mod")) {
            fail = true;
        }
    }
    assertTrue(fail);
}

From source file:co.edu.uniandes.csw.SportGroup.web.test.SportClubIT.java

@Test
@RunAsClient//from w w  w .j a v  a 2s.c  o  m
public void t1createCountry() throws InterruptedException {
    Thread.sleep(1500);
    boolean success = false;
    driver.findElement(By.partialLinkText("Country")).click();
    Thread.sleep(3000);
    driver.findElement(By.id("createBtn")).click();
    Thread.sleep(2000);
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys("Colombia");
    driver.findElement(By.id("population")).clear();
    driver.findElement(By.id("population")).sendKeys("80000000");
    driver.findElement(By.id("saveBtn")).click();
    Thread.sleep(2000);
    List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr"));
    for (WebElement webElement : rows) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));
        if (elems.get(0).getText().equals("Colombia") && elems.get(1).getText().equals("80000000")) {
            success = true;
        }
    }
    assertTrue(success);
    Thread.sleep(1000);
}

From source file:co.edu.uniandes.csw.SportGroup.web.test.SportClubIT.java

@Test
@RunAsClient//  ww w. java2  s  . com
public void t2createSport() throws Exception {
    boolean success = false;
    driver.findElement(By.partialLinkText("Sport")).click();
    Thread.sleep(3000);
    driver.findElement(By.id("createBtn")).click();
    Thread.sleep(2000);
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys("Futbol");
    driver.findElement(By.id("minAge")).clear();
    driver.findElement(By.id("minAge")).sendKeys("3");
    driver.findElement(By.id("maxAge")).clear();
    driver.findElement(By.id("maxAge")).sendKeys("90");
    driver.findElement(By.id("rules")).clear();
    driver.findElement(By.id("rules")).sendKeys("No rules");
    Select contries = new Select(driver.findElement(By.id("country")));
    contries.selectByVisibleText("Colombia");
    driver.findElement(By.id("saveBtn")).click();
    Thread.sleep(3000);
    List<WebElement> rows = driver.findElements(By.xpath("//table[contains(@id,'recordList')]/tbody/tr"));
    for (WebElement webElement : rows) {
        List<WebElement> elems = webElement.findElements(By.xpath("td"));
        if (elems.get(0).getText().equals("Futbol") && elems.get(5).getText().equals("Colombia")) {
            success = true;
        }
    }
    assertTrue(success);
    Thread.sleep(1000);
}

From source file:co.edu.uniandes.csw.stamps.tests.selenium.pages.artist.ArtistListPage.java

License:Open Source License

private String findAddressByIndex(Integer index) {
    return browser.findElement(By.id(index + "-address")).getText();
}

From source file:co.edu.uniandes.csw.stamps.tests.selenium.pages.artist.ArtistListPage.java

License:Open Source License

private String findQualificationByIndex(Integer index) {
    return browser.findElement(By.id(index + "-qualification")).getText();
}

From source file:co.edu.uniandes.csw.stamps.tests.selenium.pages.artist.ArtistListPage.java

License:Open Source License

private String findPopularityByIndex(Integer index) {
    return browser.findElement(By.id(index + "-popularity")).getText();
}