List of usage examples for org.openqa.selenium By id
public static By id(String id)
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 ww. j a va 2s. c o 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 {//w w w.j a va 2 s. c o 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 {/*from www.ja va 2s . 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.HeaderTests.java
License:Open Source License
@Test(groups = { "visibility" }, description = "check menu home button") public void headerButtons() throws Throwable { try {/*from w ww .ja v a 2s.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 = { "functionality", "upload" }, description = "page navigation tests") public void pageNavigation() throws Throwable { try {//from ww w. j a va2s. 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("//*[@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 {/*w ww . j a v a 2 s . c om*/ 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; } }
From source file:at.tugraz.ist.catroweb.catroid.LicenseTests.java
License:Open Source License
@Test(groups = { "visibility" }, description = "check if license links are present on mobile site") public void licenseLinksMobile() throws Throwable { try {/*from w ww. java 2s .co m*/ openMobileLocation(); assertTrue(isElementPresent(By.id("footerMoreButton"))); assertTrue(isElementPresent(By.id("footerLessButton"))); driver().findElement(By.id("footerMoreButton")).click(); assertTrue(isTextPresent("Privacy policy")); assertTrue(isTextPresent("Terms of Use")); assertTrue(isTextPresent("Imprint")); driver().findElement(By.id("footerLessButton")).click(); assertFalse(isTextPresent("Privacy policy")); assertFalse(isTextPresent("Terms of Use")); assertFalse(isTextPresent("Imprint")); } catch (AssertionError e) { captureScreen("LicenseTests.licenseLinksMobile"); throw e; } catch (Exception e) { captureScreen("LicenseTests.licenseLinksMobile"); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.LicenseTests.java
License:Open Source License
@Test(groups = { "visibility" }, description = "check privacy policy link/page") public void privacyPolicyMobile() throws Throwable { try {/*from w w w.j a v a2s.c om*/ openMobileLocation(); assertTrue(isElementPresent(By.id("footerMoreButton"))); driver().findElement(By.id("footerMoreButton")).click(); By privacy = By.xpath("//*[@id='mobileFooterMenu']/ul/li[1]/a"); assertTrue(isElementPresent(privacy)); clickAndWaitForPopUp(privacy); assertRegExp(".*Privacy Policy.*", driver().getTitle()); closePopUp(); } catch (AssertionError e) { captureScreen("LicenseTests.privacyPolicyMobile"); throw e; } catch (Exception e) { captureScreen("LicenseTests.privacyPolicyMobile"); throw e; } }
From source file:at.tugraz.ist.catroweb.catroid.LicenseTests.java
License:Open Source License
@Test(groups = { "visibility", "popupwindows" }, description = "check terms of use link/page") public void termsOfUseMobile() throws Throwable { try {/*from w ww .j a v a 2 s. c o m*/ openMobileLocation(); assertTrue(isElementPresent(By.id("footerMoreButton"))); driver().findElement(By.id("footerMoreButton")).click(); ajaxWait(); driver().findElement(By.xpath("//*[@id='mobileFooterMenu']/ul/li[2]/a")).click(); ajaxWait(); assertTrue(isTextPresent("Welcome to the Catrobat community!")); assertTrue(isTextPresent( "As part of the Catrobat community, you are sharing programs and ideas with people:")); // click onto licenseofuploadedprojects link clickAndWaitForPopUp(By.xpath("//div[@class='licenseText']/ul[3]/li[4]/a[1]")); assertRegExp(".*Licenses of uploaded Catrobat programs.*", driver().getTitle()); closePopUp(); // click onto licenseofsystem link clickAndWaitForPopUp(By.xpath("//div[@class='licenseText']/ul[4]/li[3]/a[1]")); assertRegExp(".*Licenses of the Catrobat System.*", driver().getTitle()); closePopUp(); clickAndWaitForPopUp(By.xpath("//div[@class='licenseText']/ul[4]/li[3]/a[2]")); assertRegExp(".*Catrobat.*", driver().getTitle()); closePopUp(); // click onto termsofservice link clickAndWaitForPopUp(By.xpath("//div[@class='licenseText']/ul[5]/li[3]/a[1]")); assertRegExp(".*Terms of Service.*", driver().getTitle()); closePopUp(); assertTrue(driver().findElement(By.xpath("//p[@class='licenseText'][7]/a")).getAttribute("href") .contains("mailto:webmaster@catrobat.org?subject=Terms%20of%20Use")); } catch (AssertionError e) { captureScreen("LicenseTests.termsOfUseMobile"); throw e; } catch (Exception e) { captureScreen("LicenseTests.termsOfUseMobile"); throw e; } }