Example usage for org.openqa.selenium By xpath

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

Introduction

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

Prototype

public static By xpath(String xpathExpression) 

Source Link

Usage

From source file:at.tugraz.ist.catroweb.catroid.PasswordRecoveryTests.java

License:Open Source License

@Test(groups = { "functionality" }, description = "check password recovery redirection if logged in")
public void passwordRecoveryRedirectWhenLoggedIn() throws Throwable {
    try {//  w w  w  .j a v  a  2  s. c o m
        login("index");
        openLocation("index", false);
        ajaxWait();
        driver().findElement(By.id("largeMenuButton")).click();
        ajaxWait();
        captureScreen("PasswordRecoveryTests.passwordRecoveryRedirectWhenLoggedIn");
        assertTrue(isVisible(By.id("menuProfileButton")));
        driver().findElement(By.id("menuProfileButton")).click();
        ajaxWait();
        assertTrue(containsElementText(By.xpath("//*[@id='largeMenuButton']/button[2]"),
                CommonData.getLoginUserDefault()));

        openLocation("passwordrecovery");

        assertFalse(isTextPresent("Recover your password".toUpperCase()));
        assertTrue(containsElementText(By.xpath("//*[@id='largeMenuButton']/button[2]"),
                CommonData.getLoginUserDefault()));
    } catch (AssertionError e) {
        captureScreen("PasswordRecoveryTests.passwordRecoveryRedirectWhenLoggedIn");
        throw e;
    } catch (Exception e) {
        captureScreen("PasswordRecoveryTests.passwordRecoveryRedirectWhenLoggedIn");
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.PasswordRecoveryTests.java

License:Open Source License

@Test(dataProvider = "passwordRecoveryResetUsernames", groups = { "functionality",
        "popupwindows" }, description = "check password recovery")
public void passwordRecoveryReset(HashMap<String, String> dataset) throws Throwable {
    try {/*www.j a  v  a  2  s  . c o  m*/
        // do registration process first, to create a new user with known password
        openLocation("registration");

        driver().findElement(By.id("registrationUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("registrationPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("registrationEmail")).sendKeys(dataset.get("registrationEmail"));
        driver().findElement(By.id("registrationCountry")).sendKeys(dataset.get("registrationCountry"));
        driver().findElement(By.id("registrationCity")).sendKeys(dataset.get("registrationCity"));
        driver().findElement(By.id("registrationMonth")).sendKeys(dataset.get("registrationMonth"));
        driver().findElement(By.id("registrationYear")).sendKeys(dataset.get("registrationYear"));
        driver().findElement(By.id("registrationGender")).sendKeys(dataset.get("registrationGender"));
        driver().findElement(By.id("registrationSubmit")).click();
        ajaxWait();
        assertTrue(containsElementText(By.xpath("//*[@id='largeMenuButton']/button[2]"),
                dataset.get("registrationUsername")));

        // goto lost password page and test reset by email and nickname, at first
        // use some wrong nickname or email
        logout("passwordrecovery");
        assertTrue(isTextPresent("Enter your nickname or email address:"));
        assertTrue(isElementPresent(By.id("passwordRecoveryUserdata")));
        assertTrue(isElementPresent(By.id("passwordRecoverySendLink")));

        driver().findElement(By.id("passwordRecoveryUserdata")).clear();
        driver().findElement(By.id("passwordRecoveryUserdata"))
                .sendKeys(dataset.get("registrationUsername") + " to test");
        driver().findElement(By.id("passwordRecoverySendLink")).click();

        ajaxWait();
        assertTrue(isTextPresent("The nickname or email address was not found."));

        // check error message
        assertTrue(isTextPresent("Enter your nickname or email address:"));
        assertTrue(isElementPresent(By.id("passwordRecoveryUserdata")));
        assertTrue(isElementPresent(By.id("passwordRecoverySendLink")));

        // now use real name
        driver().findElement(By.id("passwordRecoveryUserdata")).clear();
        driver().findElement(By.id("passwordRecoveryUserdata")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("passwordRecoverySendLink")).click();
        ajaxWait();

        // get recovery url and open it
        String recoveryUrl = driver().findElement(By.xpath("//*[@id='recoveryMessage']")).getText();
        assertTrue(recoveryUrl.contains(Config.TESTS_BASE_PATH + "passwordrecovery?c="));
        recoveryUrl = recoveryUrl.substring(recoveryUrl.indexOf("passwordrecovery"));

        openLocation(recoveryUrl);
        ajaxWait();

        // enter 2short password
        assertTrue(isTextPresent("Please enter your new password:"));
        driver().findElement(By.id("passwordSavePassword")).clear();
        driver().findElement(By.id("passwordSavePassword")).sendKeys("short");
        driver().findElement(By.id("passwordSavePassword2")).clear();
        driver().findElement(By.id("passwordSavePassword2")).sendKeys("short");

        driver().findElement(By.id("passwordSaveSubmit")).click();
        ajaxWait();

        assertTrue(isTextPresent("Please enter your new password:"));
        assertTrue(isElementPresent(By.id("passwordSavePassword")));
        assertTrue(driver().findElement(By.xpath("//*[@id='recoveryMessage']")).getText()
                .contains("password must have at least"));

        // enter the new password correctly
        driver().findElement(By.id("passwordSavePassword")).clear();
        driver().findElement(By.id("passwordSavePassword"))
                .sendKeys(dataset.get("registrationPassword") + " new");
        driver().findElement(By.id("passwordSavePassword2")).clear();
        driver().findElement(By.id("passwordSavePassword2"))
                .sendKeys(dataset.get("registrationPassword") + " new");

        driver().findElement(By.id("passwordSaveSubmit")).click();
        ajaxWait();
        assertTrue(containsElementText(By.xpath("//*[@id='largeMenuButton']/button[2]"),
                dataset.get("registrationUsername")));

        // and try to login with the old credentials to verify password recovery
        // worked
        logout();
        driver().findElement(By.id("largeMenuButton")).click();
        ajaxWait();
        assertTrue(isElementPresent(By.id("loginSubmitButton")));
        assertTrue(isVisible(By.id("loginSubmitButton")));
        assertTrue(isVisible(By.id("loginUsername")));
        assertTrue(isVisible(By.id("loginPassword")));

        driver().findElement(By.id("loginUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("loginPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("loginSubmitButton")).click();

        ajaxWait();
        assertTrue(isTextPresent("The password or username was incorrect."));

        // check bad login
        assertTrue(isVisible(By.id("loginSubmitButton")));

        // and try to login now with the new credentials
        assertTrue(isVisible(By.id("loginSubmitButton")));
        assertTrue(isVisible(By.id("loginUsername")));
        assertTrue(isVisible(By.id("loginPassword")));
        driver().findElement(By.id("loginUsername")).clear();
        driver().findElement(By.id("loginUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("loginPassword")).clear();
        driver().findElement(By.id("loginPassword")).sendKeys(dataset.get("registrationPassword") + " new");
        driver().findElement(By.id("loginSubmitButton")).click();
        ajaxWait();

        // check login
        driver().findElement(By.xpath("//*[@id='largeMenu']/div[2]/a")).click();
        assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_TITLE.toUpperCase()));

        ajaxWait();
        driver().findElement(By.id("largeMenuButton")).click();
        ajaxWait();
        assertTrue(isVisible(By.id("menuProfileButton")));
        driver().findElement(By.id("menuProfileButton")).click();
        ajaxWait();
        assertTrue(containsElementText(By.xpath("//*[@id='largeMenuButton']/button[2]"),
                dataset.get("registrationUsername")));

        // logout
        logout();
        ajaxWait();
        driver().findElement(By.id("largeMenuButton")).click();
        ajaxWait();
        assertTrue(isVisible(By.id("loginSubmitButton")));
        assertTrue(isVisible(By.id("loginUsername")));
        assertTrue(isVisible(By.id("loginPassword")));

        // Recovery URL should not work again
        driver().get(this.webSite + Config.TESTS_BASE_PATH.substring(1) + recoveryUrl);
        ajaxWait();

        assertEquals(driver().findElement(By.xpath("//*[@id='recoveryMessage']")).getText(),
                "Recovery hash was not found.");

        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
    } catch (AssertionError e) {
        captureScreen("PasswordRecoveryTests.passwordRecoveryReset." + dataset.get("registrationUsername"));
        throw e;
    } catch (Exception e) {
        captureScreen("PasswordRecoveryTests.passwordRecoveryReset." + dataset.get("registrationUsername"));
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.ProfileTests.java

License:Open Source License

@Test(dataProvider = "loginAndChangeData", groups = { "functionality",
        "visibility" }, description = "check profile page")
public void profilePageChangeUserData(HashMap<String, String> dataset) throws Throwable {
    try {/*from  w  w  w .j  a  v a  2 s.c o  m*/
        openLocation("registration/");

        driver().findElement(By.id("registrationUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("registrationPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("registrationEmail")).sendKeys(dataset.get("registrationEmail"));
        driver().findElement(By.id("registrationMonth")).sendKeys(dataset.get("registrationMonth"));
        driver().findElement(By.id("registrationYear")).sendKeys(dataset.get("registrationYear"));
        driver().findElement(By.id("registrationGender")).sendKeys(dataset.get("registrationGender"));
        (new Select(driver().findElement(By.id("registrationCountry"))))
                .selectByValue(dataset.get("registrationCountryID"));
        driver().findElement(By.id("registrationCity")).sendKeys(dataset.get("registrationCity"));
        driver().findElement(By.id("registrationSubmit")).click();
        ajaxWait();

        assertTrue(isTextPresent(dataset.get("registrationUsername")));
        assertEquals(dataset.get("registrationEmail"),
                driver().findElement(By.xpath("//*[@id='profileEmail']/input")).getAttribute("value"));

        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isVisible(By.xpath("//*[@id='profileNewPassword']/input")));
        assertTrue(isVisible(By.xpath("//*[@id='profileRepeatPassword']/input")));
        assertTrue(isVisible(By.id("profileSaveChanges")));

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("changedPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("changedPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("saved!"));

        openLocation("profile/");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("changedPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent(CommonStrings.PROFILE_PASSWORD_DIDNT_MATCH));

        openLocation("profile/");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("emptyPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("emptyPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        openLocation("profile/");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("shortPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("shortPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("Your password must have at least 6 characters."));

        openLocation("profile/");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("saved!"));

        openLocation("profile/");
        By countrySelect = By.xpath("//*[@id='wrapper']/article/div[1]/div[2]/div[1]/div[4]/select");
        Select selectCountry = new Select(driver().findElement(countrySelect));
        assertEquals(dataset.get("registrationCountry"), selectCountry.getFirstSelectedOption().getText());

        selectCountry.selectByValue(dataset.get("changedCountryID"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("saved!"));

        openLocation("profile/");
        selectCountry = new Select(driver().findElement(countrySelect));
        assertEquals(dataset.get("changedCountry"), selectCountry.getFirstSelectedOption().getText());

        selectCountry.selectByValue(dataset.get("registrationCountryID"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("saved!"));

        openLocation("profile/");
        selectCountry = new Select(driver().findElement(countrySelect));
        assertEquals(dataset.get("registrationCountry"), selectCountry.getFirstSelectedOption().getText());

        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
    } catch (AssertionError e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profilePage." + dataset.get("registrationUsername"));
        throw e;
    } catch (Exception e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profilePage." + dataset.get("registrationUsername"));
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.ProfileTests.java

License:Open Source License

@Test(dataProvider = "loginAndChangeData", groups = { "functionality",
        "visibility" }, description = "upadte user avatar")
public void profileChangeAvatarTest(HashMap<String, String> dataset) throws Throwable {
    try {/*from  www .  j a  va  2 s.  com*/
        openLocation("registration/");

        driver().findElement(By.id("registrationUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("registrationPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("registrationEmail")).sendKeys(dataset.get("registrationEmail"));
        (new Select(driver().findElement(By.id("registrationCountry"))))
                .selectByValue(dataset.get("registrationCountryID"));
        driver().findElement(By.id("registrationMonth")).sendKeys(dataset.get("registrationMonth"));
        driver().findElement(By.id("registrationYear")).sendKeys(dataset.get("registrationYear"));
        driver().findElement(By.id("registrationGender")).sendKeys(dataset.get("registrationGender"));
        driver().findElement(By.id("registrationSubmit")).click();
        ajaxWait();

        By avatarImage = By.xpath("//*[@id='wrapper']/article/div[1]/div[1]/img");
        assertTrue(driver().findElement(avatarImage).getAttribute("src")
                .contains("images/symbols/avatar_default.png"));
        makeVisible(By.id("profileAvatarFile"), "");
        makeVisible(By.id("profileAvatarFileWrapper"),
                "arguments[0].style.width='100px';arguments[0].style.height='100px';");
        driver().findElement(By.id("profileAvatarFile"))
                .sendKeys(Config.FILESYSTEM_BASE_PATH + Config.SELENIUM_GRID_TESTDATA + "test.zip");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(driver().findElement(avatarImage).getAttribute("src")
                .contains("images/symbols/avatar_default.png"));
        assertTrue(isTextPresent("Invalid image, allowed image types are gif, png or jpeg."));

        driver().findElement(By.id("profileAvatarFile"))
                .sendKeys(Config.FILESYSTEM_BASE_PATH + Config.SELENIUM_GRID_TESTDATA + "catrobat.png");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertFalse(driver().findElement(avatarImage).getAttribute("src")
                .contains("images/symbols/avatar_default.png"));

        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
    } catch (AssertionError e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profileChangeAvatarTest." + dataset.get("registrationUsername"));
        throw e;
    } catch (Exception e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profileChangeAvatarTest." + dataset.get("registrationUsername"));
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.ProfileTests.java

License:Open Source License

@Test(dataProvider = "emailTest", groups = { "functionality",
        "visibility" }, description = "check add/delete email")
public void profilePageEmailTest(HashMap<String, String> dataset) throws Throwable {
    try {//from  w  w  w  .j ava2s .  co  m
        openLocation("registration/");

        driver().findElement(By.id("registrationUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("registrationPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("registrationEmail")).sendKeys(dataset.get("registrationEmail"));
        (new Select(driver().findElement(By.id("registrationCountry"))))
                .selectByValue(dataset.get("registrationCountryID"));
        driver().findElement(By.id("registrationMonth")).sendKeys(dataset.get("registrationMonth"));
        driver().findElement(By.id("registrationYear")).sendKeys(dataset.get("registrationYear"));
        driver().findElement(By.id("registrationGender")).sendKeys(dataset.get("registrationGender"));
        driver().findElement(By.id("registrationSubmit")).click();
        ajaxWait();

        assertTrue(containsElementText(By.xpath("//*[@id='wrapper']/article/header"),
                dataset.get("registrationUsername").toUpperCase()));

        clickOkOnNextConfirmationBox();
        driver().findElement(By.xpath("//*[@id='profileEmail']/input")).clear();
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();
        assertTrue(isTextPresent(
                "Error while updating this e-mail address. You must have at least one validated e-mail address."));

        openLocation("profile/");

        driver().findElement(By.xpath("//*[@id='profileSecondEmail']/input"))
                .sendKeys(dataset.get("registrationEmail"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("This email address already exists."));

        openLocation("profile/");

        driver().findElement(By.xpath("//*[@id='profileSecondEmail']/input"))
                .sendKeys(dataset.get("secondEmail"));
        driver().findElement(By.id("profileSaveChanges")).click();

        Alert alert = driver().switchTo().alert();
        String message = alert.getText();
        alert.accept();
        assertRegExp(".*/emailvalidation.*", message);

        // get validation url and open it
        String validationUrl = getValidationUrl(message);
        openLocation(validationUrl + "_invalid");
        assertTrue(isTextPresent("Recovery hash was not found."));
        openLocation(validationUrl);
        assertTrue(isTextPresent("You have successfully validated your email address."));

        openLocation("profile/");
        ajaxWait();

        clickOkOnNextConfirmationBox();
        driver().findElement(By.xpath("//*[@id='profileEmail']/input")).clear();
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();
        assertTrue(isTextPresent("saved!"));

        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
    } catch (AssertionError e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profilePage." + dataset.get("registrationUsername"));
        throw e;
    } catch (Exception e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profilePage." + dataset.get("registrationUsername"));
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.ProfileTests.java

License:Open Source License

@Test(dataProvider = "emailTest", groups = { "functionality",
        "visibility" }, description = "Tests user profile page")
public void profileForeignProfilePage(HashMap<String, String> dataset) throws Throwable {
    try {/*from   ww w  . j  a  va 2s.c om*/
        openLocation("registration/");

        driver().findElement(By.id("registrationUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("registrationPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("registrationEmail")).sendKeys(dataset.get("registrationEmail"));
        (new Select(driver().findElement(By.id("registrationCountry"))))
                .selectByValue(dataset.get("registrationCountryID"));
        driver().findElement(By.id("registrationMonth")).sendKeys(dataset.get("registrationMonth"));
        driver().findElement(By.id("registrationYear")).sendKeys(dataset.get("registrationYear"));
        driver().findElement(By.id("registrationGender")).sendKeys(dataset.get("registrationGender"));
        driver().findElement(By.id("registrationSubmit")).click();
        ajaxWait();

        logout("profile/" + dataset.get("registrationUsername"));
        // not logged in, view foreign profile
        assertFalse(isElementPresent(By.id("profileNewPassword")));
        assertFalse(isElementPresent(By.id("profileRepeatPassword")));
        assertFalse(isElementPresent(By.id("profileCountry")));
        assertFalse(isElementPresent(By.id("profileEmail")));
        assertFalse(isElementPresent(By.id("profileSecondEmail")));
        assertFalse(isElementPresent(By.id("profileSaveChanges")));
        assertFalse(isTextPresent("MY PROJECTS"));
        assertTrue(isTextPresent("PROJECTS OF " + dataset.get("registrationUsername").toUpperCase()));
        assertFalse(isElementPresent(By.id("registrationSubmit")));
        assertFalse(isTextPresent("Login".toUpperCase()));
        assertTrue(isTextPresent(dataset.get("registrationUsername").toUpperCase()));

        // /profile/ without username should redirect to login page when not logged in
        openLocation("profile/");
        assertTrue(isTextPresent("Login".toUpperCase()));

        login("profile/" + dataset.get("registrationUsername"));
        // logged in as catroweb, view foreign profile
        assertTrue(isTextPresent(dataset.get("registrationUsername").toUpperCase()));
        assertTrue(isTextPresent(dataset.get("registrationCountry")));
        assertTrue(isTextPresent("0"));
        assertFalse(isElementPresent(By.id("profileNewPassword")));
        assertFalse(isElementPresent(By.id("profileRepeatPassword")));
        assertFalse(isElementPresent(By.id("profileCountry")));
        assertFalse(isElementPresent(By.id("profileEmail")));
        assertFalse(isElementPresent(By.id("profileSecondEmail")));
        assertFalse(isElementPresent(By.id("profileSaveChanges")));
        assertFalse(isTextPresent("MY PROJECTS"));
        assertTrue(isTextPresent("PROJECTS OF " + dataset.get("registrationUsername").toUpperCase()));
        assertFalse(isElementPresent(By.id("registrationSubmit")));
        assertFalse(isTextPresent("Login".toUpperCase()));
        assertTrue(isTextPresent(dataset.get("registrationUsername").toUpperCase()));

        String projectTitle = dataset.get("registrationUsername");
        String authToken = CommonFunctions.getAuthenticationToken(dataset.get("registrationUsername"));
        projectUploader.upload(CommonData.getUploadPayload(projectTitle, "", "", "", "", "",
                dataset.get("registrationUsername"), authToken));
        assertProjectPresent(projectTitle);

        openLocation("profile/" + dataset.get("registrationUsername"));
        assertTrue(isTextPresent("1"));

        // /profile/ without username should show own profile when logged in
        openLocation("profile/");
        assertFalse(isTextPresent("Login".toUpperCase()));
        assertFalse(isTextPresent(dataset.get("registrationUsername").toUpperCase()));
        assertTrue(isTextPresent(CommonData.getLoginUserDefault().toUpperCase()));
        assertTrue(isElementPresent(By.id("profileNewPassword")));
        assertTrue(isElementPresent(By.id("profileRepeatPassword")));
        assertTrue(isElementPresent(By.xpath("/html/body/div/article/div/div[2]/div/div[4]/select")));
        assertTrue(isElementPresent(By.id("profileEmail")));
        assertTrue(isElementPresent(By.id("profileSecondEmail")));
        assertTrue(isElementPresent(By.id("profileSaveChanges")));
        assertTrue(isTextPresent("MY PROJECTS"));
        assertTrue(isElementPresent(By.id("profileSaveChanges")));

        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
    } catch (AssertionError e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profileForeignProfilePage." + dataset.get("registrationUsername"));
        throw e;
    } catch (Exception e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profileForeignProfilePage." + dataset.get("registrationUsername"));
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.SearchTests.java

License:Open Source License

@Test(dataProvider = "randomProjects", groups = { "functionality",
        "upload" }, description = "search for random title and description")
public void titleAndDescription(HashMap<String, String> dataset) throws Throwable {
    try {//from   w w w .  j a v a 2  s  . c  o  m
        projectUploader.upload(dataset);

        String projectTitle = dataset.get("projectTitle");
        String projectDescription = dataset.get("projectDescription");

        openLocation("search/?q=" + projectTitle + "&p=1");
        ajaxWait();

        assertTrue(isTextPresent(CommonStrings.SEARCH_PROJECTS_PAGE_TITLE.toUpperCase()));
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitle + "\"]")));

        // test description
        driver().findElement(By.xpath("//*[@id='largeMenu']/div[4]/input")).clear();
        driver().findElement(By.xpath("//*[@id='largeMenu']/div[4]/input")).sendKeys(projectDescription);
        driver().findElement(By.id("largeSearchButton")).click();
        ajaxWait();
        assertTrue(isTextPresent(CommonStrings.SEARCH_PROJECTS_PAGE_TITLE.toUpperCase()));
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitle + "\"]")));
    } catch (AssertionError e) {
        captureScreen("SearchTests.titleAndDescription." + dataset.get("projectTitle"));
        log(dataset.get("projectTitle"));
        log(dataset.get("projectDescription"));
        throw e;
    } catch (Exception e) {
        captureScreen("SearchTests.titleAndDescription." + dataset.get("projectTitle"));
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.SearchTests.java

License:Open Source License

@Test(groups = { "functionality" }, description = "checks all search boxes and buttons")
public void searchBoxesAndButton() throws Throwable {
    try {/*  ww w .j  a va2 s .co m*/
        String projectTitleA = "searchFunctionalityA" + CommonData.getRandomShortString(22);
        projectUploader.upload(CommonData.getUploadPayload(projectTitleA, CommonData.getRandomLongString(200),
                "", "", "", "", "", ""));
        String projectTitleB = "searchFunctionalityA" + CommonData.getRandomShortString(22);
        projectUploader.upload(CommonData.getUploadPayload(projectTitleB, CommonData.getRandomLongString(200),
                "", "", "", "", "", ""));

        By largeTopSearchBox = By.xpath("//*[@id='largeMenu']/div[4]/input");
        By largeFooterSearchBox = By.xpath("//*[@id='largeFooterMenu']/div[2]/span[2]/input");
        By mobileSearchBox = By.xpath("//*[@id='smallSearchBar']/input");

        // large layout search bar on the top
        openLocation();
        assertTrue(isVisible(By.id("largeSearchButton")));
        assertTrue(isVisible(largeTopSearchBox));

        driver().findElement(largeTopSearchBox).sendKeys(projectTitleA);
        driver().findElement(largeTopSearchBox).sendKeys(Keys.RETURN);
        ajaxWait();
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));
        assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitleB + "\"]")));

        driver().findElement(largeTopSearchBox).clear();
        driver().findElement(largeTopSearchBox).sendKeys(projectTitleB);
        driver().findElement(largeTopSearchBox).sendKeys(Keys.RETURN);
        ajaxWait();
        assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleB + "\"]")));

        openLocation();
        driver().findElement(largeTopSearchBox).sendKeys(projectTitleA);
        driver().findElement(By.id("largeSearchButton")).click();
        ajaxWait();
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));

        driver().findElement(largeTopSearchBox).clear();
        driver().findElement(largeTopSearchBox).sendKeys(projectTitleB);
        driver().findElement(By.id("largeSearchButton")).click();
        ajaxWait();
        assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleB + "\"]")));

        // large layout search bar on the bottom
        openLocation();
        assertTrue(isVisible(By.id("footerSearchButton")));
        assertTrue(isVisible(largeFooterSearchBox));

        driver().findElement(largeFooterSearchBox).sendKeys(projectTitleA);
        driver().findElement(largeFooterSearchBox).sendKeys(Keys.RETURN);
        ajaxWait();
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));
        assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitleB + "\"]")));

        driver().findElement(largeFooterSearchBox).clear();
        driver().findElement(largeFooterSearchBox).sendKeys(projectTitleB);
        driver().findElement(largeFooterSearchBox).sendKeys(Keys.RETURN);
        ajaxWait();
        assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleB + "\"]")));

        openLocation();
        driver().findElement(largeFooterSearchBox).sendKeys(projectTitleA);
        driver().findElement(By.id("footerSearchButton")).click();
        ajaxWait();
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));

        driver().findElement(largeFooterSearchBox).clear();
        driver().findElement(largeFooterSearchBox).sendKeys(projectTitleB);
        driver().findElement(By.id("footerSearchButton")).click();
        ajaxWait();
        assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleB + "\"]")));

        // mobile layout search bar on the top
        openMobileLocation();
        assertTrue(isVisible(By.id("mobileSearchButton")));
        assertFalse(isVisible(mobileSearchBox));

        driver().findElement(By.id("mobileSearchButton")).click();
        driver().findElement(mobileSearchBox).sendKeys(projectTitleA);
        driver().findElement(mobileSearchBox).sendKeys(Keys.RETURN);
        ajaxWait();
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));
        assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitleB + "\"]")));

        driver().findElement(mobileSearchBox).clear();
        driver().findElement(mobileSearchBox).sendKeys(projectTitleB);
        driver().findElement(mobileSearchBox).sendKeys(Keys.RETURN);
        ajaxWait();
        assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitleA + "\"]")));
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitleB + "\"]")));
    } catch (AssertionError e) {
        captureScreen("SearchTests.searchBoxesAndButton");
        throw e;
    } catch (Exception e) {
        captureScreen("SearchTests.searchBoxesAndButton");
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.SearchTests.java

License:Open Source License

@Test(dataProvider = "specialChars", groups = { "functionality",
        "upload" }, description = "search forspecial chars")
public void specialChars(String specialchars) throws Throwable {
    try {/*  w  w w.jav a2 s  . com*/
        String projectPrefix = "searchtest" + CommonData.getRandomShortString(10);
        String projectTitle = projectPrefix + specialchars;
        String htmlProjectTitle = projectTitle.replace("&", "&amp;").replace("\"", "&quot;");
        projectUploader.upload(CommonData.getUploadPayload(projectTitle, CommonData.getRandomLongString(200),
                "", "", "", "", "", ""));

        openLocation();
        ajaxWait();

        By searchBox = By.xpath("//*[@id='largeMenu']/div[4]/input");
        for (int i = projectTitle.length() - specialchars.length(); i < projectTitle.length(); i++) {
            driver().findElement(searchBox).clear();
            driver().findElement(searchBox)
                    .sendKeys(projectPrefix + projectTitle.substring(projectPrefix.length(), i + 1));
            driver().findElement(By.id("largeSearchButton")).click();
            ajaxWait();
            assertTrue(isElementPresent(By.xpath("//a[@title=\"" + htmlProjectTitle + "\"]")));

            driver().findElement(searchBox).clear();
            driver().findElement(searchBox).sendKeys(CommonData.getRandomShortString(10));
            driver().findElement(By.id("largeSearchButton")).click();
            ajaxWait();
        }
    } catch (AssertionError e) {
        captureScreen("SearchTests.specialChars");
        throw e;
    } catch (Exception e) {
        captureScreen("SearchTests.specialChars");
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.SearchTests.java

License:Open Source License

@Test(groups = { "functionality", "upload" }, description = "search test with page navigation")
public void pageNavigation() throws Throwable {
    try {/*  ww w .j  a  v a  2 s  .  c o  m*/
        String projectTitle = CommonData.getRandomShortString(10);
        openLocation();
        ajaxWait();

        int uploadCount = Config.PROJECT_PAGE_LOAD_MAX_PROJECTS * (Config.PROJECT_PAGE_SHOW_MAX_PAGES + 1);
        System.out.println("*** NOTICE *** Uploading " + uploadCount + " projects");
        for (int i = 0; i < uploadCount; i++) {
            projectUploader.upload(CommonData.getUploadPayload(projectTitle + i, "pagenavigationtest", "", "",
                    "", "", "", ""));
            if ((i % Config.PROJECT_PAGE_LOAD_MAX_PROJECTS) == 0) {
                driver().findElement(By.xpath("//*[@id='largeMenu']/div[2]/a")).click();
            }
        }

        driver().findElement(By.xpath("//*[@id='largeMenu']/div[2]/a")).click();
        ajaxWait();
        assertFalse(isElementPresent(By.xpath("//a[@title=\"" + projectTitle + "0\"]")));

        By searchBox = By.xpath("//*[@id='largeMenu']/div[4]/input");
        driver().findElement(searchBox).clear();
        driver().findElement(searchBox).sendKeys(projectTitle);
        driver().findElement(By.id("largeSearchButton")).click();
        ajaxWait();

        int pageNr = 0;
        for (; pageNr < Config.PROJECT_PAGE_SHOW_MAX_PAGES; pageNr++) {
            driver().findElement(By.id("moreResults")).click();
            ajaxWait();
            assertRegExp(".*p=" + (pageNr + 2) + ".*", driver().getCurrentUrl());
        }
        pageNr++;
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitle + "0\"]")));

        // test links to details page
        driver().findElement(By.xpath("//*[@id='searchResultContainer']/ul/li/a")).click();
        ajaxWait();
        assertRegExp(".*/details.*", driver().getCurrentUrl());
        driver().navigate().back();
        ajaxWait();
        assertTrue(isTextPresent(CommonStrings.SEARCH_PROJECTS_PAGE_TITLE.toUpperCase()));
        assertRegExp(CommonStrings.WEBSITE_TITLE + " - " + CommonStrings.SEARCH_PROJECTS_PAGE_TITLE + " - "
                + projectTitle + " - " + (pageNr) + "", driver().getTitle());
        assertTrue(isElementPresent(By.xpath("//a[@title=\"" + projectTitle + "0\"]")));
    } catch (AssertionError e) {
        captureScreen("SearchTests.pageNavigation");
        throw e;
    } catch (Exception e) {
        captureScreen("SearchTests.pageNavigation");
        throw e;
    }
}