List of usage examples for org.openqa.selenium By xpath
public static By xpath(String xpathExpression)
From source file:at.tugraz.ist.catroweb.catroid.BlockedIpTests.java
License:Open Source License
@Test(dataProvider = "unblockedIps", dependsOnMethods = { "blockedIps" }, groups = { "functionality" }, description = "test unblocked ips") public void unblockedIps(String projectId, String unblockedIp) throws Throwable { try {// w w w. j a v a 2s . co m unblockAllIPs(); blockIp(unblockedIp); openLocation("details/" + projectId); assertFalse(containsElementText(By.xpath("//*[@id='wrapper']/article/div"), "Error".toUpperCase())); assertFalse(isTextPresent("Your IP-Address has been blocked.")); openLocation(); assertFalse(containsElementText(By.xpath("//*[@id='wrapper']/article/div"), "Error".toUpperCase())); assertFalse(isTextPresent("Your IP-Address has been blocked.")); unblockIp(unblockedIp); } catch (AssertionError e) { captureScreen("BlockedIpTests.unblockedIps." + unblockedIp); throw e; } catch (Exception e) { captureScreen("BlockedIpTests.unblockedIps." + unblockedIp); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.DetailsTests.java
License:Open Source License
@Test(dataProvider = "detailsProject", groups = { "functionality", "upload" }, description = "view + download counter test") public void detailsPageCounterLink(HashMap<String, String> dataset) throws Throwable { try {/*from w w w. jav a 2s . co m*/ String response = projectUploader.upload(dataset); String id = CommonFunctions.getValueFromJSONobject(response, "projectId"); String title = dataset.get("projectTitle"); int numOfViews = -1; int numOfViewsAfter = -1; int numOfDownloads = -1; int numOfDownloadsAfter = -1; By viewsElement = By.xpath("//*[@id='projectDetailsContainer']/div[5]/ul/li[5]/div[2]"); By downloadsElement = By.xpath("//*[@id='projectDetailsContainer']/div[5]/ul/li[4]/div[2]/span"); By filesizeElement = By.xpath("//*[@id='projectDetailsContainer']/div[5]/ul/li[3]/div[2]"); By downloadsButton = By.xpath("//*[@id='projectDetailsContainer']/div[3]/div/a[1]/div/span"); openLocation("details/" + id); ajaxWait(); // project title assertTrue(containsElementText(By.id("projectDetailsProjectTitle"), title.toUpperCase())); // test the view counter numOfViews = Integer.parseInt(driver().findElement(viewsElement).getText().split(" ")[0]); driver().navigate().refresh(); ajaxWait(); numOfViewsAfter = Integer.parseInt(driver().findElement(viewsElement).getText().split(" ")[0]); assertEquals(numOfViews + 1, numOfViewsAfter); // test the download counter numOfDownloads = Integer.parseInt(driver().findElement(downloadsElement).getText().split(" ")[0]); driver().findElement(downloadsButton).click(); driver().navigate().refresh(); ajaxWait(); numOfDownloadsAfter = Integer.parseInt(driver().findElement(downloadsElement).getText().split(" ")[0]); assertEquals(numOfDownloads + 1, numOfDownloadsAfter); // check file size double filesize = CommonFunctions.getFileSizeRounded( Config.FILESYSTEM_BASE_PATH + Config.PROJECTS_DIRECTORY + id + Config.PROJECTS_EXTENTION); String filesizeText = driver().findElement(filesizeElement).getText(); String displayedfilesize = filesizeText.substring(0, filesizeText.indexOf(" MB")); if (displayedfilesize.startsWith("<")) { // smaller files are displayed as "< 0.1 MB" assertEquals("< " + String.valueOf(filesize), displayedfilesize); } else { assertEquals(String.valueOf(filesize), displayedfilesize); } HashMap<String, String> versionInfo = CommonFunctions.getVersionInfo(id); String versionInfoText = driver().findElement(By.id("projectDetailsDownloadVersion")).getText(); assertEquals("Pocket Code version: " + versionInfo.get("version_name"), versionInfoText); } catch (AssertionError e) { captureScreen("DetailsTests.detailsPageCounterLink." + dataset.get("projectTitle")); throw e; } catch (Exception e) { captureScreen("DetailsTests.detailsPageCounterLink." + dataset.get("projectTitle")); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.DetailsTests.java
License:Open Source License
@Test(dataProvider = "detailsProject", groups = { "functionality", "upload" }, description = "view + download counter test") public void detailsPageCounterThumbnail(HashMap<String, String> dataset) throws Throwable { try {//from w w w .jav a 2s . co m String response = projectUploader.upload(dataset); String id = CommonFunctions.getValueFromJSONobject(response, "projectId"); int numOfDownloads = -1; int numOfDownloadsAfter = -1; By downloadsElement = By.xpath("//*[@id='projectDetailsContainer']/div[5]/ul/li[4]/div[2]/span"); openLocation("details/" + id); // test the download counter numOfDownloads = Integer.parseInt(driver().findElement(downloadsElement).getText().split(" ")[0]); driver().findElement(By.id("projectDetailsThumbnailImage")).click(); driver().navigate().refresh(); ajaxWait(); numOfDownloadsAfter = Integer.parseInt(driver().findElement(downloadsElement).getText().split(" ")[0]); assertEquals(numOfDownloads + 1, numOfDownloadsAfter); } catch (AssertionError e) { captureScreen("DetailsTests.detailsPageCounterThumbnail." + dataset.get("projectTitle")); throw e; } catch (Exception e) { captureScreen("DetailsTests.detailsPageCounterThumbnail." + dataset.get("projectTitle")); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.DetailsTests.java
License:Open Source License
@Test(dataProvider = "detailsProject", groups = { "functionality", "upload" }, description = "test inappropriate button") public void inappropriateButton(HashMap<String, String> dataset) throws Throwable { try {/*w w w . j a v a 2 s . c o m*/ String response = projectUploader.upload(dataset); String id = CommonFunctions.getValueFromJSONobject(response, "projectId"); openLocation("details/" + id); assertTrue(isElementPresent(By.id("reportAsInappropriateButton"))); driver().findElement(By.id("reportAsInappropriateButton")).click(); ajaxWait(); driver().findElement(By.xpath("//*[@id='reportAsInappropriateDialog']/a")).click(); ajaxWait(); driver().findElement(By.id("loginUsername")).sendKeys(CommonData.getLoginUserDefault()); driver().findElement(By.id("loginPassword")).sendKeys(CommonData.getLoginPasswordDefault()); driver().findElement(By.id("loginSubmitButton")).click(); ajaxWait(); assertTrue(isElementPresent(By.id("reportAsInappropriateButton"))); driver().findElement(By.id("reportAsInappropriateButton")).click(); assertTrue(isVisible(By.id("reportInappropriateReason"))); assertTrue(isVisible(By.id("reportInappropriateReportButton"))); assertTrue(isVisible(By.id("reportInappropriateCancelButton"))); driver().findElement(By.id("reportAsInappropriateButton")).click(); assertFalse(isVisible(By.id("reportInappropriateReason"))); driver().findElement(By.id("reportAsInappropriateButton")).click(); assertTrue(isVisible(By.id("reportInappropriateReason"))); driver().findElement(By.id("reportInappropriateCancelButton")).click(); assertFalse(isVisible(By.id("reportInappropriateReason"))); driver().findElement(By.id("reportAsInappropriateButton")).click(); driver().findElement(By.id("reportInappropriateReportButton")).click(); ajaxWait(); assertFalse(isVisible(By.id("reportInappropriateReason"))); assertFalse(isTextPresent("You reported this project as inappropriate!")); driver().findElement(By.id("reportAsInappropriateButton")).click(); driver().findElement(By.id("reportInappropriateReason")).sendKeys("my selenium reason"); driver().findElement(By.id("reportInappropriateReportButton")).click(); ajaxWait(); assertFalse(isVisible(By.id("reportInappropriateReason"))); ajaxWait(); assertTrue(isTextPresent("You reported this project as inappropriate!")); driver().navigate().refresh(); ajaxWait(); assertTrue(isTextPresent("No entry was found for the given ID")); openAdminLocation("/tools/inappropriateProjects"); clickOkOnNextConfirmationBox(); driver().findElement(By.id("resolve" + id)).click(); assertTrue(isTextPresent("The project was succesfully restored and set to visible!")); assertFalse(isTextPresent(id)); } catch (AssertionError e) { captureScreen("DetailsTests.inappropriateButton." + dataset.get("projectTitle")); throw e; } catch (Exception e) { captureScreen("DetailsTests.inappropriateButton." + dataset.get("projectTitle")); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.DetailsTests.java
License:Open Source License
@Test(groups = { "visibility" }, description = "check if invalid project id redirects to errorpage") public void invalidProjectID() throws Throwable { try {/*from w w w. ja v a 2 s . c om*/ String invalidProject = CommonData.getRandomShortString(10); openLocation("details/" + invalidProject); assertRegExp(".*/error", driver().getCurrentUrl()); assertTrue(isTextPresent("No entry was found for the given ID:")); assertTrue(isTextPresent("ID: " + invalidProject)); assertFalse(isElementPresent(By.xpath("//div[@class='detailsFlexDiv']"))); } catch (AssertionError e) { captureScreen("DetailsTests.invalidProjectID"); throw e; } catch (Exception e) { captureScreen("DetailsTests.invalidProjectID"); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.HeaderTests.java
License:Open Source License
@Test(groups = { "visibility" }, description = "check menu home button") public void headerButtons() throws Throwable { try {/* w ww .j a v a 2 s . c om*/ openLocation(); assertTrue(isVisible(By.id("largeMenu"))); assertTrue(isVisible(By.xpath("//*[@id='largeMenu']/div[2]/a"))); assertTrue(isVisible(By.id("largeSearchButton"))); assertTrue(isVisible(By.xpath("//*[@id='largeMenu']/div[4]/input"))); assertTrue(isVisible(By.id("largeMenuButton"))); assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_TITLE.toUpperCase())); driver().findElement(By.id("largeMenuButton")).click(); assertRegExp(".*/login", driver().getCurrentUrl()); driver().findElement(By.xpath("//*[@id='largeMenu']/div[2]/a")).click(); assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_TITLE.toUpperCase())); driver().findElement(By.xpath("//*[@id='largeMenu']/div[4]/input")).sendKeys("test"); driver().findElement(By.id("largeSearchButton")).click(); assertRegExp(".*/search/.*", driver().getCurrentUrl()); driver().findElement(By.id("largeMenuButton")).click(); driver().findElement(By.id("loginUsername")).sendKeys(CommonData.getLoginUserDefault()); driver().findElement(By.id("loginPassword")).sendKeys(CommonData.getLoginPasswordDefault()); driver().findElement(By.id("loginSubmitButton")).click(); ajaxWait(); assertTrue(containsElementText(By.xpath("//*[@id='largeMenuButton']/button[2]"), CommonData.getLoginUserDefault())); driver().findElement(By.id("largeMenuButton")).click(); assertTrue(isVisible(By.id("menuProfileButton"))); assertTrue(isVisible(By.id("menuLogoutButton"))); driver().findElement(By.id("menuProfileButton")).click(); assertTrue(containsElementText(By.xpath("//*[@id='wrapper']/article/header"), CommonData.getLoginUserDefault().toUpperCase())); driver().findElement(By.id("largeMenuButton")).click(); driver().findElement(By.id("menuLogoutButton")).click(); driver().findElement(By.id("largeMenuButton")).click(); ajaxWait(); assertTrue(containsElementText(By.xpath("//*[@id='wrapper']/article/div[1]"), "Login".toUpperCase())); } catch (AssertionError e) { captureScreen("HeaderTests.headerMenuButtons"); throw e; } catch (Exception e) { captureScreen("HeaderTests.headerMenuButtons"); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.HeaderTests.java
License:Open Source License
@Test(groups = { "visibility" }, description = "check menu home button") public void headerButtonsMobile() throws Throwable { try {// w w w . j a v a 2 s.c o m openMobileLocation(); assertTrue(isVisible(By.id("smallMenuBar"))); assertTrue(isVisible(By.xpath("//*[@id='smallMenuBar']/a"))); assertFalse(isVisible(By.id("smallSearchBar"))); assertTrue(isVisible(By.id("mobileSearchButton"))); assertTrue(isVisible(By.id("mobileMenuButton"))); assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_TITLE.toUpperCase())); driver().findElement(By.id("mobileMenuButton")).click(); assertRegExp(".*/login", driver().getCurrentUrl()); driver().findElement(By.xpath("//*[@id='smallMenuBar']/a")).click(); assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_TITLE.toUpperCase())); driver().findElement(By.id("mobileSearchButton")).click(); assertTrue(isVisible(By.id("smallSearchBar"))); driver().findElement(By.id("mobileSearchButton")).click(); assertFalse(isVisible(By.id("smallSearchBar"))); driver().findElement(By.id("mobileSearchButton")).click(); driver().findElement(By.xpath("//*[@id='smallSearchBar']/input")).sendKeys("test"); driver().findElement(By.xpath("//*[@id='smallSearchBar']/input")).sendKeys(Keys.RETURN); assertRegExp(".*/search/.*", driver().getCurrentUrl()); driver().findElement(By.id("mobileMenuButton")).click(); driver().findElement(By.id("loginUsername")).sendKeys(CommonData.getLoginUserDefault()); driver().findElement(By.id("loginPassword")).sendKeys(CommonData.getLoginPasswordDefault()); driver().findElement(By.id("loginSubmitButton")).click(); ajaxWait(); driver().findElement(By.id("mobileMenuButton")).click(); assertTrue(isVisible(By.id("menuProfileButton"))); assertTrue(isVisible(By.id("menuLogoutButton"))); driver().findElement(By.id("menuProfileButton")).click(); assertTrue(containsElementText(By.xpath("//*[@id='wrapper']/article/header"), CommonData.getLoginUserDefault().toUpperCase())); driver().findElement(By.id("mobileMenuButton")).click(); driver().findElement(By.id("menuLogoutButton")).click(); driver().findElement(By.id("mobileMenuButton")).click(); ajaxWait(); assertTrue(containsElementText(By.xpath("//*[@id='wrapper']/article/div[1]"), "Login".toUpperCase())); } catch (AssertionError e) { captureScreen("HeaderTests.headerButtonsMobile"); throw e; } catch (Exception e) { captureScreen("HeaderTests.headerButtonsMobile"); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.IndexTests.java
License:Open Source License
@Test(groups = { "visibility", "popupwindows" }, description = "click download,header,details -links ") public void index() throws Throwable { try {/*from w ww. j a v a 2 s . com*/ openLocation(); ajaxWait(); // test page title and header title assertTrue(driver().getTitle().matches("^Pocket Code Website.*")); assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_TITLE.toUpperCase())); clickLastVisibleProject(); ajaxWait(); assertRegExp(".*/details/[0-9]+", driver().getCurrentUrl()); driver().navigate().back(); ajaxWait(); assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_TITLE.toUpperCase())); // test home link driver().findElement(By.xpath("//*[@id='largeMenu']/div[2]/a")).click(); } catch (AssertionError e) { captureScreen("IndexTests.index"); throw e; } catch (Exception e) { captureScreen("IndexTests.index"); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.IndexTests.java
License:Open Source License
@Test(groups = { "functionality", "upload" }, description = "page navigation tests") public void pageNavigation() throws Throwable { try {//from ww w. j ava2 s . co 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("//*[@id='newestProjects']/ul/li/a[@title=\"" + projectTitle + "0\"]"))); assertTrue(isVisible(By.id("newestShowMore"))); assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_NEXT_BUTTON)); int pageNr = 0; for (; pageNr < Config.PROJECT_PAGE_SHOW_MAX_PAGES; pageNr++) { driver().findElement(By.id("newestShowMore")).click(); ajaxWait(); } assertTrue(isElementPresent( By.xpath("//*[@id='newestProjects']/ul/li/a[@title=\"" + projectTitle + "0\"]"))); // test session driver().navigate().refresh(); ajaxWait(); assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_TITLE.toUpperCase())); assertTrue(isElementPresent( By.xpath("//*[@id='newestProjects']/ul/li/a[@title=\"" + projectTitle + "0\"]"))); // test links to details page driver().findElement(By.xpath("//*[@id='newestProjects']/ul/li/a")).click(); ajaxWait(); assertRegExp(".*/details.*", driver().getCurrentUrl()); driver().navigate().back(); ajaxWait(); assertTrue(isTextPresent(CommonStrings.NEWEST_PROJECTS_PAGE_TITLE.toUpperCase())); assertTrue(isElementPresent( By.xpath("//*[@id='newestProjects']/ul/li/a[@title=\"" + projectTitle + "0\"]"))); driver().findElement(By.xpath("//*[@id='largeMenu']/div[2]/a")).click(); ajaxWait(); assertFalse(isElementPresent( By.xpath("//*[@id='newestProjects']/ul/li/a[@title=\"" + projectTitle + "0\"]"))); } catch (AssertionError e) { captureScreen("IndexTests.pageNavigation"); throw e; } catch (Exception e) { captureScreen("IndexTests.pageNavigation"); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.IndexTests.java
License:Open Source License
@Test(groups = { "functionality", "upload" }, description = "language select tests") public void languageSelect() throws Throwable { try {/*from w w w .j a va2 s . co m*/ openLocation("termsOfUse"); assertTrue(isTextPresent("Terms of Use".toUpperCase())); assertTrue(isElementPresent(By.xpath("//html[@lang='" + Config.SITE_DEFAULT_LANGUAGE + "']"))); openLocation("termsOfUse", false); assertTrue(isElementPresent(By.id("switchLanguage"))); (new Select(driver().findElement(By.id("switchLanguage")))).selectByValue("de"); ajaxWait(); assertTrue(isTextPresent("Nutzungsbedingungen".toUpperCase())); assertTrue(isElementPresent(By.id("switchLanguage"))); assertTrue(isElementPresent(By.xpath("//html[@lang='de']"))); (new Select(driver().findElement(By.id("switchLanguage")))).selectByValue("en"); ajaxWait(); assertTrue(isTextPresent("Terms of Use".toUpperCase())); assertTrue(isElementPresent(By.xpath("//html[@lang='en']"))); } catch (AssertionError e) { captureScreen("IndexTests.languageSelect"); throw e; } catch (Exception e) { captureScreen("IndexTests.languageSelect"); throw e; } }