List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)
From source file:org.mousephenotype.cda.selenium.ChartsPageTest.java
License:Apache License
@Test @Ignore//from ww w . j av a 2 s . c o m public void testExampleCategorical() throws Exception { String testName = "testExampleCategorical"; RunStatus status = new RunStatus(); Date start = new Date(); int targetCount = 1; testUtils.logTestStartup(logger, this.getClass(), testName, targetCount, 1); String mgiGeneAcc = "MGI:2444584"; String impressParameter = "ESLIM_001_001_004"; String zygosity = "homozygote"; String geneSymbol = "Mysm1"; String target = paBaseUrl + "/charts?accession=" + mgiGeneAcc + "¶meter_stable_id=" + impressParameter + "&zygosity=" + zygosity; logger.info("Target: " + target); driver.get(target); String title = wait.until(ExpectedConditions.presenceOfElementLocated(By.className("title"))).getText(); System.out.println("title=" + title); if (!title.contains(geneSymbol)) { status.addError("ERROR: Expected title to contain '" + geneSymbol + "' but was '" + title + "'. URL: " + target + "'"); } else { status.successCount++; } testUtils.printEpilogue(testName, start, status, targetCount, targetCount); }
From source file:org.mousephenotype.cda.selenium.ChartsPageTest.java
License:Apache License
@Test @Ignore/* w w w . ja va2 s. co m*/ public void testExampleCategorical2() throws Exception { String testName = "testExampleCategorical2"; RunStatus status = new RunStatus(); Date start = new Date(); int targetCount = 1; testUtils.logTestStartup(logger, this.getClass(), testName, targetCount, 1); String mgiGeneAcc = "MGI:98373"; String impressParameter = "M-G-P_014_001_001"; String zygosity = "homozygote"; String geneSymbol = "Sparc"; String target = paBaseUrl + "/charts?accession=" + mgiGeneAcc + "¶meter_stable_id=" + impressParameter + "&zygosity=" + zygosity; logger.info("Target: " + target); driver.get(target); String title = wait.until(ExpectedConditions.presenceOfElementLocated(By.className("title"))).getText(); if (!title.contains(geneSymbol)) { status.addError("ERROR: Expected title to contain '" + geneSymbol + "' but was '" + title + "'. URL: " + target + "'"); } else { status.successCount++; } testUtils.printEpilogue(testName, start, status, targetCount, targetCount); System.out.println(); }
From source file:org.mousephenotype.cda.selenium.GenePageTest.java
License:Apache License
/** * Finds all MGI_ACCESSION_IDs in the genotype-phenotype * core that do not start with 'MGI'.// www. ja v a2s.c o m * * <p><em>Limit the number of test iterations by adding an entry to * testIterations.properties with this test's name as the lvalue and the * number of iterations as the rvalue. -1 means run all iterations.</em></p> * * @throws SolrServerException */ @Test //@Ignore public void testForBadGeneIds() throws Exception { RunStatus status = new RunStatus(); String testName = "testForBadGeneIds"; List<String> geneIds = new ArrayList(geneService.getAllNonConformingGenes()); String target = ""; String message; Date start = new Date(); int targetCount = testUtils.getTargetCount(env, testName, geneIds, 10); testUtils.logTestStartup(logger, this.getClass(), testName, targetCount, geneIds.size()); // Loop through all non-conforming genes, testing each one for valid page load. int i = 0; WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds); for (String geneId : geneIds) { if (i >= targetCount) { break; } i++; target = paBaseUrl + "/genes/" + geneId; System.out.println("gene[" + i + "] URL: " + target); try { driver.get(target); wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("span#enu"))); } catch (NoSuchElementException | TimeoutException te) { message = "Expected page for MGI_ACCESSION_ID " + geneId + "(" + target + ") but found none."; te.printStackTrace(); status.addError(message); } catch (Exception e) { status.addError("EXCEPTION processing target URL " + target + ": " + e.getLocalizedMessage()); e.printStackTrace(); continue; } message = "SUCCESS: MGI_ACCESSION_ID " + geneId + ". URL: " + target; Thread.sleep(threadWaitInMilliseconds); } if ((!geneIds.isEmpty()) && (!status.hasErrors())) status.successCount++; testUtils.printEpilogue(testName, start, status, targetCount, geneIds.size()); }
From source file:org.mousephenotype.cda.selenium.ImpcImagesTest.java
License:Apache License
private void geneIdsTestEngine(String testName, List<String> geneIds) throws SolrServerException { RunStatus masterStatus = new RunStatus(); String target = ""; Date start = new Date(); testUtils.logTestStartup(logger, this.getClass(), testName, geneIds.size(), geneIds.size()); // Loop through all genes, testing each one for valid page load. int i = 0;//from ww w . ja v a 2s.c o m WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds); for (String geneId : geneIds) { RunStatus status = new RunStatus(); target = paBaseUrl + "/genes/" + geneId; try { driver.get(target); wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("span#enu"))); GenePage genePage = new GenePage(driver, wait, target, geneId, paBaseUrl); if (genePage.hasImpcImages()) { List<String> parameters = genePage.getAssociatedImpcImageUrls(); if (parameters.isEmpty()) { status.addError("Parameter list is empty!"); } } else { status.addError("No IMPC Images found for " + target); } } catch (Exception e) { e.printStackTrace(); status.addError(e.getLocalizedMessage()); } if (status.hasErrors()) { System.out.println("[" + i + "] [FAIL]. URL: " + target + ". REASON: " + StringUtils.join(status.getErrorMessages(), ", ")); } else { status.successCount++; System.out.println("[" + i + "] [PASS]. URL: " + target); } i++; masterStatus.add(status); } testUtils.printEpilogue(testName, start, masterStatus, geneIds.size(), geneIds.size()); }
From source file:org.mousephenotype.cda.selenium.PhenotypePageStatistics.java
License:Apache License
/** * Walks the phenotype core collecting the count of: [phenotype] table only, * image(s) only, both, and none./* w w w .j a v a 2 s . com*/ * * @throws SolrServerException */ @Test public void testCollectTableAndImageStatistics() throws SolrServerException, IOException { RunStatus masterStatus = new RunStatus(); String testName = "testCollectTableAndImageStatistics"; List<String> phenotypeIds = new ArrayList(mpService.getAllPhenotypes()); String target = ""; List<String> phenotypeTableOnly = new ArrayList(); List<String> imagesOnly = new ArrayList(); List<String> both = new ArrayList(); String message; Date start = new Date(); int pagesWithPhenotypeTableCount = 0; int pagesWithImageCount = 0; int pagesWithBoth = 0; List<String> urlsWithNeitherPhenotypeTableNorImage = new ArrayList(); int targetCount = testUtils.getTargetCount(env, testName, phenotypeIds, 10); testUtils.logTestStartup(logger, this.getClass(), testName, targetCount, phenotypeIds.size()); // Loop through first targetCount phenotype MGI links, testing each one for valid page load. int i = 0; for (String phenotypeId : phenotypeIds) { RunStatus status = new RunStatus(); if (i >= targetCount) { break; } i++; boolean found = false; target = paBaseUrl + "/phenotypes/" + phenotypeId; logger.debug("phenotype[" + i + "] URL: " + target); try { driver.get(target); (new WebDriverWait(driver, timeoutInSeconds)) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("h1#top"))); found = true; boolean hasPhenotypeTable = false; boolean hasImage = false; // Are there any phenotype associations? List<WebElement> elementList = driver.findElements(By.cssSelector("div.alert")); hasPhenotypeTable = !testUtils.contains(elementList, NO_PHENOTYPE_ASSOCIATIONS); // Are there any images? elementList = driver.findElements(By.cssSelector("h2#section")); if (testUtils.contains(elementList, "Images")) { List<WebElement> imagesAccordion = driver .findElements(By.cssSelector("div.accordion-body ul li")); if (imagesAccordion.isEmpty()) { status.addError("ERROR: Found Image tag but there were no image links"); } else { hasImage = true; } } if (hasPhenotypeTable && hasImage) { pagesWithBoth++; both.add(driver.getCurrentUrl()); } else if (hasPhenotypeTable) { pagesWithPhenotypeTableCount++; phenotypeTableOnly.add(driver.getCurrentUrl()); } else if (hasImage) { pagesWithImageCount++; imagesOnly.add(driver.getCurrentUrl()); } else { urlsWithNeitherPhenotypeTableNorImage.add(driver.getCurrentUrl()); } } catch (Exception e) { e.printStackTrace(); status.addError("EXCEPTION processing target URL " + target + ": " + e.getLocalizedMessage()); } if (found) { status.successCount++; } else { status.addError("h1 with id 'top' not found."); } masterStatus.add(status); } System.out.println("\nPhenotype pages with tables but no images: " + pagesWithPhenotypeTableCount); for (String s : phenotypeTableOnly) { System.out.println(s); } System.out.println(); System.out.println("Phenotype pages with images but no tables: " + pagesWithImageCount); for (String s : imagesOnly) { System.out.println(s); } System.out.println(); System.out.println("Phenotype pages with both tables and images: " + pagesWithBoth); for (String s : both) { System.out.println(s); } System.out.println(); if (!urlsWithNeitherPhenotypeTableNorImage.isEmpty()) { System.out.println("WARNING: The following " + urlsWithNeitherPhenotypeTableNorImage.size() + " results had neither phenotype table nor images:"); System.out.println("WARNING: Phenotype pages with neither phenotype table nor images: " + urlsWithNeitherPhenotypeTableNorImage.size()); for (String s : urlsWithNeitherPhenotypeTableNorImage) { System.out.println("\t" + s); } } testUtils.printEpilogue(testName, start, masterStatus, targetCount, phenotypeIds.size()); }
From source file:org.mousephenotype.cda.selenium.PhenotypePageTest.java
License:Apache License
/** * Checks the MGI links for the first MAX_MGI_LINK_CHECK_COUNT phenotype ids * Fetches all gene IDs (MARKER_ACCESSION_ID) with phenotype associations * from the genotype-phenotype core and tests to make sure there is an MGI * link for each.//from w ww . j av a2 s. c o m * * <p><em>Limit the number of test iterations by adding an entry to * testIterations.properties with this test's name as the lvalue and the * number of iterations as the rvalue. -1 means run all iterations.</em></p> * * @throws SolrServerException */ @Test @Ignore public void testMGI_MPLinksAreValid() throws SolrServerException, IOException { RunStatus status = new RunStatus(); String testName = "testMGI_MPLinksAreValid"; List<String> phenotypeIds = new ArrayList(genotypePhenotypeService.getAllPhenotypesWithGeneAssociations()); String target = ""; String message; Date start = new Date(); int targetCount = testUtils.getTargetCount(env, testName, phenotypeIds, 10); testUtils.logTestStartup(logger, this.getClass(), testName, targetCount, phenotypeIds.size()); // Loop through first targetCount phenotype MGI links, testing each one for valid page load. int i = 0; for (String phenotypeId : phenotypeIds) { if (i >= targetCount) { break; } i++; WebElement phenotypeLink; target = paBaseUrl + "/phenotypes/" + phenotypeId; logger.debug("phenotype[" + i + "] URL: " + target); try { driver.get(target); phenotypeLink = wait.until(ExpectedConditions .presenceOfElementLocated(By.cssSelector("div.inner a").linkText(phenotypeId))); testUtils.scrollToTop(driver, phenotypeLink); } catch (NoSuchElementException | TimeoutException te) { message = "Expected page for MP_TERM_ID " + phenotypeId + "(" + target + ") but found none."; status.addError(message); commonUtils.sleep(threadWaitInMilliseconds); continue; } try { phenotypeLink.click(); WebElement mgiMpIdElement = wait .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='ontotree']"))); if (!mgiMpIdElement.getText().startsWith("Mammalian Phenotype Ontology")) { message = "Expected valid phenotype page for " + phenotypeId + "(" + target + ")."; status.addError(message); } } catch (Exception e) { message = "EXCEPTION processing target URL " + target + ": " + e.getLocalizedMessage(); e.printStackTrace(); status.addError(message); } } testUtils.printEpilogue(testName, start, status, targetCount, phenotypeIds.size()); }
From source file:org.mousephenotype.cda.selenium.PhenotypePageTest.java
License:Apache License
private void phenotypeIdsTestEngine(String testName, List<String> phenotypeIds) throws TestException { RunStatus masterStatus = new RunStatus(); String target;/*from w w w. j a v a 2 s . com*/ Date start = new Date(); WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds); if (phenotypeIds.contains("MP:0005376")) { System.out.println( "removing MP:0005376 from test as has many many phenotypes and takes a long time to return so times out"); phenotypeIds.remove("MP:0005376"); } int targetCount = testUtils.getTargetCount(env, testName, phenotypeIds, 10); testUtils.logTestStartup(logger, this.getClass(), testName, targetCount, phenotypeIds.size()); // Loop through all phenotypes, testing each one for valid page load. int i = 0; for (String phenotypeId : phenotypeIds) { if (i >= targetCount) { break; } RunStatus status = new RunStatus(); WebElement mpLinkElement = null; target = paBaseUrl + "/phenotypes/" + phenotypeId; try { PhenotypePage phenotypePage = new PhenotypePage(driver, wait, target, paBaseUrl); if (phenotypePage.hasPhenotypesTable()) { mpLinkElement = wait.until(ExpectedConditions .presenceOfElementLocated(By.cssSelector("div.inner a").linkText(phenotypeId))); status = phenotypePage.validate(); } else { // Genes that are Phenotype Started but not yet Complete have a placeholder and note that they will be available soon. // Thus, it is not an error if the PhenotypesTable doesn't exist. continue; } } catch (Exception e) { status.addError("EXCEPTION processing target URL " + target + ": " + e.getLocalizedMessage()); } if (mpLinkElement == null) { status.addError("Expected page for MP_TERM_ID " + phenotypeId + "(" + target + ") but found none."); } if (status.hasErrors()) { System.out.println("[" + i + "] [FAIL]: " + phenotypeId + ". URL: " + target + ". REASON: " + status.toStringErrorMessages()); } else { status.successCount++; System.out.println("[" + i + "] [PASS]: " + phenotypeId + ". URL: " + target); } i++; masterStatus.add(status); } testUtils.printEpilogue(testName, start, masterStatus, targetCount, phenotypeIds.size()); }
From source file:org.mousephenotype.cda.selenium.SearchPageTest.java
License:Apache License
/** * Test for Jira bug MPII-806: from the search page, searching for the characters * "fasting glu" should autosuggest 'fasting' and 'glucose'. Click on 'fasting glucose' * and verify that the correct phenotype page appears. * @throws TestException/*from w w w . ja v a2 s.c o m*/ */ @Test @Ignore public void testMPII_806() throws TestException { String testName = Thread.currentThread().getStackTrace()[1].getMethodName(); Date start = new Date(); RunStatus status = new RunStatus(); testUtils.logTestStartup(logger, this.getClass(), testName, 1, 1); String queryStr = paBaseUrl + "/search"; driver.get(queryStr); String characters = "fasting glu"; driver.findElement(By.cssSelector("input#s")).sendKeys(characters); // Wait for dropdown list to appear with candidates. String xpathSelector = "//ul[@id='ui-id-1']/li[@class='ui-menu-item']/a"; WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpathSelector))); if ((!element.getText().contains("fasting")) && (!element.getText().contains("glucose"))) { status.addError( "ERROR: Expected the terms 'fasting' and 'glucose' but found '" + element.getText() + "'"); } else { element.click(); element = wait .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[@id='resultCount']"))); String resultCountString = element.getText().toLowerCase(); if ((!resultCountString.contains("gene")) && (!resultCountString.contains("phenotype")) && (!resultCountString.contains("phenodigm"))) { status.addError( "ERROR: Expected result text to contain 'gene' or 'phenotype' or 'phenodigm'. Actual text was '" + resultCountString + "'"); } } if (!status.hasErrors()) status.successCount++; testUtils.printEpilogue(testName, start, status, 1, 1); }
From source file:org.mousephenotype.cda.selenium.SearchPageTest.java
License:Apache License
@Test @Ignore//from w ww . ja v a 2s . c o m public void testOrderButtons() throws TestException { String testName = Thread.currentThread().getStackTrace()[1].getMethodName(); Date start = new Date(); RunStatus status = new RunStatus(); testUtils.logTestStartup(logger, this.getClass(), testName, 1, 1); int buttonElementsSize = 0; String message; String target = ""; try { target = urlUtils.urlEncode(paBaseUrl + "/search?q=MGI\\:1353431#fq=*:*&facet=gene"); System.out.println("target: " + target); SearchPage searchPage = new SearchPage(driver, timeoutInSeconds, target, paBaseUrl, impcImageMap); // Use the first gene div element in the search results. List<WebElement> geneElements = driver.findElements(By.xpath("//*[@id='geneGrid']/tbody/tr[1]")); if (geneElements.isEmpty()) { fail("Can't find first 'geneGrid' div element in gene search results list. URL: " + target); } buttonElementsSize = searchPage.getProductionStatusOrderButtons(geneElements.get(0)).size(); if (buttonElementsSize < 2) { status.addError( "This test expects at least two production status order buttons. Number of buttons found: " + buttonElementsSize + ". URL: " + target); } else { for (int i = 0; i < buttonElementsSize; i++) { String path = "//*[@id='geneGrid']/tbody/tr[1]"; geneElements = driver.findElements(By.xpath(path)); WebElement geneElement = geneElements.get(0); List<WebElement> buttonElements = searchPage.getProductionStatusOrderButtons(geneElement); WebElement buttonElement = buttonElements.get(i); buttonElement.click(); // Verify that we're in the order section. boolean expectedUrlEnding = driver.getCurrentUrl().endsWith("#order2"); if (!expectedUrlEnding) { status.addError("Expected url to end in '#order2'. URL: " + driver.getCurrentUrl()); } driver.navigate().back(); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(path))); } } } catch (TestException e) { message = "ERROR: Failed to load search page URL: " + target; status.addError(message); } if (!status.hasErrors()) status.successCount++; testUtils.printEpilogue(testName, start, status, 1, 1); }
From source file:org.mousephenotype.cda.selenium.support.GenePage.java
License:Apache License
/** * * @return the title ('Gene: Akt2')/* w ww.ja v a2s . co m*/ */ public String getTitle() { WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("top"))); return element.getText(); }