Example usage for org.openqa.selenium By linkText

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

Introduction

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

Prototype

public static By linkText(String linkText) 

Source Link

Usage

From source file:dk.netarkivet.systemtest.page.SelectiveHarvestPageHelper.java

License:Open Source License

public static void deactivateHarvest(String name) {
    TestEventManager.getInstance().addStimuli("Deactivating harvest " + name);
    PageHelper.gotoPage(PageHelper.MenuPages.SelectiveHarvests);
    WebElement table = PageHelper.getWebDriver().findElement(By.className("selection_table"));
    List<WebElement> tr_collection = table.findElements(By.tagName("tr"));
    for (WebElement webElement : tr_collection) {
        if (webElement.getText().contains(name)) {
            webElement.findElement(By.linkText("Deactivate")).click();
        }// w w w  .  j a v a  2  s.  c  o m
    }
}

From source file:dk.netarkivet.systemtest.page.SelectiveHarvestPageHelper.java

License:Open Source License

public static void deactivateAllHarvests() {
    TestEventManager.getInstance().addStimuli("Deactivating all harvests");
    PageHelper.gotoPage(PageHelper.MenuPages.SelectiveHarvests);
    if (PageHelper.getWebDriver().getPageSource().contains("Hide inactive harvest definitions")) {
        PageHelper.getWebDriver().findElement(By.linkText("Hide inactive harvest definitions")).click();
    }//w  w  w . jav a 2 s. co  m
    while (!PageHelper.getWebDriver().getPageSource().contains("No selective harvests defined")) {
        // Ensure page is loaded
        PageHelper.getWebDriver().findElement(By.linkText("Create new selective harvest definition"));
        WebElement table = PageHelper.getWebDriver().findElement(By.className("selection_table"));
        List<WebElement> tr_collection = table.findElements(By.tagName("tr"));
        TestEventManager.getInstance().addStimuli(
                "Deactivating harvest: " + tr_collection.get(1).findElements(By.xpath("td")).get(0).getText());
        tr_collection.get(1).findElement(By.linkText("Deactivate")).click();
    }
}

From source file:dk.netarkivet.systemtest.performance.DatabaseMigrationSanityTest.java

License:Open Source License

/**
 * Basic sanity test that the current production database can be consistently upgraded with the latest NAS software.
 * This test is designed to be cheap to run so it can easily be tested on any snapshot.
 *//*from  w w  w  . j  av a  2s .c o  m*/
@Test(groups = { "performancetest" })
public void dbMigrationSanityTest() throws Exception {
    WebDriver driver = new FirefoxDriver();
    TestGUIController TestGUIController = new TestGUIController(testController);
    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
    String baseUrl = testController.ENV.getGuiHost() + ":" + testController.ENV.getGuiPort();
    PageHelper.initialize(driver, baseUrl);
    TestGUIController.waitForGUIToStart(60);
    addFixture("Opening NAS front page.");
    PageHelper.gotoPage(PageHelper.MenuPages.AliasSummary.Frontpage);
    addStep("Ingest some domains", "The domains should be created.");
    DomainWebTestHelper.createDomain(new String[] { "netarkivet.dk", "kb.dk", "kaarefc.dk" });
    WebElement element = null;
    try {
        element = driver.findElement(By.tagName("h4"));
    } catch (Exception e) {
        element = driver.findElement(By.id("message"));
    }
    NASAssert.assertTrue(element.getText().contains("These domains have now been created")
            || element.getText().contains("already exist"));
    addStep("Opening bitpreservation section of GUI.",
            "The page should open and show the number of files in the archive.");
    driver.findElement(By.linkText("Bitpreservation")).click();
    driver.getPageSource().matches("Number of files:.*[0-9]{2}");
    addStep("Create a selective harvest",
            "The harvest should be created successfully and be listed in the HD list");
    String harvestId = "harvest_" + (new Date()).getTime();
    SelectiveHarvestPageHelper.createSelectiveHarvest(harvestId, "a harvest",
            new String[] { "netarkivet.dk", "kb.dk" });
    NASAssert.assertTrue(driver.getPageSource().contains(harvestId),
            harvestId + " not found in harvest list after creation");

}

From source file:dk.netarkivet.systemtest.SeleniumTest.java

License:Open Source License

private void initialiseSelenium() {
    FirefoxProfile fxProfile = new FirefoxProfile();
    fxProfile.setPreference("browser.download.folderList", 2);
    fxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    try {//from   w ww . j  a  v  a 2  s  .  c  o m
        fxProfile.setPreference("browser.download.dir",
                (File.createTempFile("aaaa", "bbbb")).getParentFile().getAbsolutePath());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
    fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/xml");
    fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "binary/octet-stream");

    driver = new FirefoxDriver(fxProfile);
    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
    baseUrl = testController.ENV.getGuiHost() + ":" + testController.ENV.getGuiPort();
    PageHelper.initialize(driver, baseUrl);
    TestGUIController.waitForGUIToStart(60);
    TestEventManager.getInstance().addFixture("Selecting English as language");
    driver.findElement(By.linkText("English")).click();
}

From source file:Domain.Story2.java

@Test
public void testSearchProduct() {
    driver.get("http://store.demoqa.com/");
    //Clear the search form
    driver.findElement(By.className("search")).clear();
    //Input "Magic" in the search form
    driver.findElement(By.className("search")).sendKeys("Magic" + Keys.RETURN);
    //Wait page forward to product detail page              
    waitUntil(d -> d.findElement(By.linkText("Magic Mouse")).isDisplayed());

    try {/*from   ww  w.j a  va2  s  . c om*/
        //Find the "Magic Mouse" Product link
        WebElement ProductGroup = driver.findElement(By.linkText("Magic Mouse"));
        assertTrue(ProductGroup.isDisplayed());
    } catch (NoSuchElementException nseex) {
        fail();
    }
    driver.manage().deleteAllCookies();
}

From source file:Domain.Story3.java

@Test
public void testAddtoCart() {
    driver.get("http://store.demoqa.com/products-page/product-category/");
    //Find the "Add to Cart" button of the first product and click it
    driver.findElements(By.className("wpsc_buy_button")).get(0).click();
    //Wait adding to cart
    waitUntil(d -> d.findElement(By.linkText("Go to Checkout")).isDisplayed());
    //Click the "Go to Checkout" button in the alert window
    driver.findElement(By.linkText("Go to Checkout")).click();
    //Wait page forward to checkout page
    waitUntil(d -> d.findElement(By.linkText("iPhone 5")).isDisplayed());

    try {/*from  ww w  .j a va  2 s  .  com*/
        //Find the link to the product in the checkout page
        String itemTitle = driver.findElement(By.linkText("iPhone 5")).getText();
        assertTrue(itemTitle.contains("iPhone 5"));
    } catch (NoSuchElementException nseex) {
        fail();
    }
}

From source file:Domain.Story3.java

@Test
public void testRemoveItem() {
    driver.get("http://store.demoqa.com/products-page/product-category/");
    //Find the "Add to Cart" button of the first product and click it
    driver.findElements(By.className("wpsc_buy_button")).get(0).click();
    //Wait adding to cart
    waitUntil(d -> d.findElement(By.linkText("Go to Checkout")).isDisplayed());
    //Click the "Go to Checkout" button in the alert window
    driver.findElement(By.linkText("Go to Checkout")).click();
    //Wait page forward to checkout page
    waitUntil(d -> d.findElement(By.xpath("//input[@value='Remove']")).isDisplayed());
    //Click the remove button
    driver.findElement(By.xpath("//input[@value='Remove']")).click();
    //Wait the remove process finished
    waitUntil(d -> d.findElement(By.className("entry-content")).isDisplayed());

    try {/*from  w  ww .jav a  2s.c o m*/
        //Find the empty infos
        WebElement emptyContent = driver.findElement(By.className("entry-content"));
        assertTrue(emptyContent.isDisplayed());
    } catch (NoSuchElementException nseex) {
        fail();
    }
}

From source file:edu.ncsu.csc.itrust.selenium.CreateHCPTest.java

public void testCreateValidHCP() throws Exception {
    WebDriver driver = login("9000000001", "pw");

    assertLogged(TransactionType.HOME_VIEW, 9000000001L, 0L, "");
    assertEquals("iTrust - Admin Home", driver.getTitle());

    driver.findElement(By.linkText("Add HCP")).click();

    assertEquals("iTrust - Add HCP", driver.getTitle());

    driver.findElement(By.name("firstName")).sendKeys("Laurie");
    driver.findElement(By.name("lastName")).sendKeys("Williams");
    driver.findElement(By.name("email")).sendKeys("laurie@ncsu.edu");
    driver.findElement(By.name("email")).submit();

    String newMID = driver.findElement(By.className("fTable")).findElements(By.cssSelector("td")).get(1)
            .getText();//from   w  w w. jav a  2 s.c om

    driver.findElement(By.partialLinkText("Continue")).click();

    assertEquals("iTrust - Edit Personnel", driver.getTitle());

    driver.findElement(By.name("streetAddress1")).sendKeys("900 Main Campus Dr");
    driver.findElement(By.name("streetAddress2")).sendKeys("Box 2509");
    driver.findElement(By.name("city")).sendKeys("Raleigh");
    Select select = new Select(driver.findElement(By.name("state")));
    select.selectByValue("NC");
    driver.findElement(By.name("zip")).sendKeys("27606-1234");
    driver.findElement(By.name("phone")).sendKeys("919-100-1000");
    driver.findElement(By.name("phone")).submit();

    assertTrue(driver.getPageSource().contains("Information Successfully Updated"));
    assertLogged(TransactionType.LHCP_CREATE, 9000000001L, Long.parseLong(newMID), "");
}

From source file:edu.ncsu.csc.itrust.selenium.CreateHCPTest.java

public void testEditValidPersonnel() throws Exception {
    WebDriver driver = login("9000000001", "pw");

    assertLogged(TransactionType.HOME_VIEW, 9000000001L, 0L, "");
    assertEquals("iTrust - Admin Home", driver.getTitle());

    driver.findElement(By.linkText("Edit Personnel")).click();

    assertEquals("iTrust - Please Select a Personnel", driver.getTitle());

    driver.findElement(By.name("FIRST_NAME")).sendKeys("Kelly");
    driver.findElement(By.name("LAST_NAME")).sendKeys("Doctor");
    driver.findElement(By.name("FIRST_NAME")).submit();

    driver.findElement(By.cssSelector("input[value='9000000000']")).submit();

    driver.findElement(By.name("city")).clear();
    driver.findElement(By.name("city")).sendKeys("Brooklyn");
    driver.findElement(By.name("city")).submit();

    assertTrue(driver.getPageSource().contains("Information Successfully Updated"));
    assertLogged(TransactionType.LHCP_EDIT, 9000000001L, 9000000000L, "");

    driver.findElement(By.linkText("Edit Personnel")).click();

    assertEquals("iTrust - Please Select a Personnel", driver.getTitle());
}

From source file:edu.ncsu.csc.itrust.selenium.CreateHCPTest.java

public void testEditHospitalAssignments() throws Exception {
    gen.clearAllTables();/*w  ww .j  a  v a 2  s  .co m*/
    gen.standardData();

    WebDriver driver = login("9000000001", "pw");

    assertLogged(TransactionType.HOME_VIEW, 9000000001L, 0L, "");
    assertEquals("iTrust - Admin Home", driver.getTitle());

    driver.findElement(By.linkText("Edit HCP Assignment to Hospital")).click();

    assertEquals("iTrust - Please Select a Personnel", driver.getTitle());

    driver.findElement(By.name("FIRST_NAME")).sendKeys("Kelly");
    driver.findElement(By.name("LAST_NAME")).sendKeys("Doctor");
    driver.findElement(By.name("FIRST_NAME")).submit();

    driver.findElement(By.cssSelector("input[value='9000000000']")).submit();

    assertEquals("iTrust - Hospital Staffing Assignments", driver.getTitle());

    driver.findElement(By.linkText("Assign")).click();

    assertTrue(driver.getPageSource().contains("HCP has been assigned"));
    assertLogged(TransactionType.LHCP_ASSIGN_HOSPITAL, 9000000001L, 9000000000L, "");

    driver.findElement(By.linkText("Unassign")).click();

    assertTrue(driver.getPageSource().contains("HCP has been unassigned"));
    assertLogged(TransactionType.LHCP_REMOVE_HOSPITAL, 9000000001L, 9000000000L, "");
}