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.www.testing.model.GenePage.java
License:Apache License
/** * Validates that://w ww . j a va 2 s .c om * <ul> * <li>There is a <b><i>Phenotype Association</i></b> section.</li> * <li>Gene page title starts with <b><i>Gene:</i></b></li> * <li>If there is a <b><i>genes</i></b> HTML table, validates that: * <ul> * <li>Each row has a p-value</li> * <li>Each row has a valid graph link (the graph pages themselves * are not checked here as they take too long)</li> * <li>The sex icon count matches <i>Total number of results</i> count</li> * <li><b><i>TSV</i></b> and <b><i>XLS</i></b> downloads are valid</li> * </ul> * </li> * <li>A <b><i>genes</i></b> HTML table is present if <code> * genesTableRequired</code> is <code>true</code></li> * <li>There are 3 buttons:</li> * <ul> * <li><b><i>Login to register interest</i></b></li> * <li><b><i>Order</i></b></li> * <li><b><i>KOMP</i></b></li> * </ul> * </ul> * @param genesTableRequired If set to true, there must be a phenotype * HTML table or an error is logged. If false, no error is logged if there * is no phenotype HTML table. * @return validation status */ public PageStatus validate(boolean genesTableRequired) { PageStatus status = new PageStatus(); // Validate title starts with 'Gene:' WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h1[@id='top']"))); if (!element.getText().startsWith("Gene:")) { status.addError("Expected gene page title to start with 'Gene:'."); } // Validate there is a 'Phenotype Association' section. try { wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h2[@id='section-associations']"))); } catch (Exception e) { status.addError("Expected 'Phenotype Association' section."); } // If there is a 'genes' HTML table, validate it. if (hasGenesTable) { geneTable.load(); // Load all of the genes table pageMap data. Use preAndPostQcList. List<List<String>> preAndPostQcList = geneTable.getPreAndPostQcList(); String cell; int i = 0; for (List<String> row : preAndPostQcList) { if (i++ == 0) continue; // Verify p value. cell = row.get(GeneTable.COL_INDEX_GENES_P_VALUE); if (cell == null) { status.addError("Missing or invalid P Value. URL: " + target); } cell = row.get(GeneTable.COL_INDEX_GENES_GRAPH_LINK); if ((cell == null) || (cell.trim().isEmpty())) { status.addError("Missing graph link. URL: " + target); } } // Validate the download links. status = validateDownload(); } else { if (genesTableRequired) { status.addError("Expected genes HTML table but found none."); } } // Buttons List<WebElement> buttons = driver.findElements(By.className("btn")); // ... count if (buttons.size() != 3) { status.addError("Expected 3 buttons but found " + buttons.size()); } // ... Button text String[] buttonTitlesArray = { "Login to register interest", "Order", "KOMP" }; List<String> buttonTitles = new ArrayList(Arrays.asList(buttonTitlesArray)); for (WebElement webElement : buttons) { String buttonText = webElement.getText(); if (!buttonTitles.contains(buttonText)) { status.addError("Expected button with title '" + buttonText + "' but none was found."); } } return status; }
From source file:org.mousephenotype.www.testing.model.GenePage.java
License:Apache License
/** * Waits for the gene page to load.//from www . j a v a2 s. c o m */ private void load() { driver.get(target); wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("span#enu"))); List<WebElement> elements; // Determine if this page has images. elements = driver.findElements(By.xpath("//h2[@id='section-images']")); hasImages = !elements.isEmpty(); List<WebElement> impcElements = driver.findElements(By.xpath("//h2[@id='section-impc-images']")); hasImpcImages = !impcElements.isEmpty(); // Determine if this page has phenotype associations. If it does, get the results count. try { elements = driver.findElements(By.xpath("//table[@id='genes']")); hasGenesTable = !elements.isEmpty(); if (hasGenesTable) { elements = driver.findElements(By.xpath( "//div[@id='phenotypesDiv']/div[@class='container span12']/p[@class='resultCount']")); String totResultsString = elements.get(0).getText(); int index = totResultsString.lastIndexOf(":"); String count = totResultsString.substring(index + 1).trim(); resultsCount = Utils.tryParseInt(count); } } catch (Exception e) { throw new RuntimeException( "GenePage.load(): page appears to have a 'genes' HTML table but it was not found."); } hasGraphs = (resultsCount > 0); }
From source file:org.mousephenotype.www.testing.model.GeneTable.java
License:Apache License
/** * Pulls <code>numRows</code> rows of postQc data and column access * variables from the gene page's 'genes' HTML table. * * @param numRows the number of postQc phenotype table rows to return, * including the heading row. To specify all postQc rows, set * <code>numRows</code> to null. * @return <code>numRows</code> rows of data and column access variables * from the gene page's 'genes' HTML table. *///from ww w . j a va2 s. com public GridMap load(Integer numRows) { if (numRows == null) numRows = computeTableRowCount(); String[][] dataArray; preQcList = new ArrayList(); postQcList = new ArrayList(); preAndPostQcList = new ArrayList(); String value; // Wait for page. WebElement genesTable = wait .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("table#genes"))); // Grab the headings. List<WebElement> headings = genesTable.findElements(By.cssSelector("thead tr th")); numRows = Math.min(computeTableRowCount(), numRows); // Take the lesser of: actual row count in HTML table (including heading), or requested numRows. int numCols = headings.size(); dataArray = new String[numRows][numCols]; // Allocate space for the data. int sourceColIndex = 0; for (WebElement heading : headings) { // Copy the heading values. dataArray[0][sourceColIndex] = heading.getText(); sourceColIndex++; } preQcList.add(Arrays.asList(dataArray[0])); postQcList.add(Arrays.asList(dataArray[0])); preAndPostQcList.add(Arrays.asList(dataArray[0])); // Loop through all of the tr objects for this page, gathering the data. int sourceRowIndex = 1; for (WebElement row : genesTable.findElements(By.xpath("//table[@id='genes']/tbody/tr"))) { List<WebElement> cells = row.findElements(By.cssSelector("td")); boolean isPreQcLink = false; sourceColIndex = 0; boolean skipLink = false; for (WebElement cell : cells) { if (sourceColIndex == COL_INDEX_GENES_ALLELE) { String rawAllele = cell.getText(); List<WebElement> supList = cell.findElements(By.cssSelector("sup")); if (supList.isEmpty()) { value = rawAllele; } else { String sup = supList.get(0).getText(); AlleleParser ap = new AlleleParser(rawAllele, sup); value = ap.toString(); } } else if (sourceColIndex == COL_INDEX_GENES_PHENOTYPE) { value = cell.findElement(By.cssSelector("a")).getText(); // Get the phenotype text. } else if (sourceColIndex == COL_INDEX_GENES_SEX) { // Translate the male/female symbol into a string: 'male', 'female', or 'both'. List<WebElement> sex = cell.findElements(By.xpath("img[@alt='Male' or @alt='Female']")); if (sex.size() == 2) { value = "both"; } else { value = sex.get(0).getAttribute("alt").toLowerCase(); } } else if (sourceColIndex == COL_INDEX_GENES_GRAPH_LINK) { // Extract the graph url from the <a> anchor and decode it. // NOTE: Graph links are disabled if there is no supporting data. List<WebElement> graphLinks = cell.findElements(By.cssSelector("a")); value = ""; if (!graphLinks.isEmpty()) { value = graphLinks.get(0).getAttribute("href"); } else { graphLinks = cell.findElements(By.cssSelector("i")); if (!graphLinks.isEmpty()) { value = graphLinks.get(0).getAttribute("oldtitle"); if (value.contains(NO_SUPPORTING_DATA)) { skipLink = true; } } } value = TestUtils.urlDecode(value); isPreQcLink = TestUtils.isPreQcLink(value); } else { value = cell.getText(); } dataArray[sourceRowIndex][sourceColIndex] = value; sourceColIndex++; } // If the graph link is a postQc link, increment the index and return when we have the number of requested rows. if (isPreQcLink) { preQcList.add(Arrays.asList(dataArray[sourceRowIndex])); // Add the row to the preQc list. } else { if (!skipLink) { postQcList.add(Arrays.asList(dataArray[sourceRowIndex])); // Add the row to the preQc list. if (postQcList.size() >= numRows) { // Return when we have the number of requested rows. data = new GridMap(postQcList, target); return data; } } } preAndPostQcList.add(Arrays.asList(dataArray[sourceRowIndex])); // Add the row to the preQc- and postQc-list. sourceRowIndex++; } data = new GridMap(postQcList, target); return data; }
From source file:org.mousephenotype.www.testing.model.GraphPage.java
License:Apache License
/** * Parse the tsv and xls download files. When successfully completed, the * map will contain two key/value pairs: one keyed "tsv" and one keyed * "xls". Each value contains a list of download data by section, where a * section is identified as starting with a column heading. * * @return two key/value pairs: one keyed "tsv" and one keyed "xls". Each * value contains a list of download data by section, where a section is * identified as starting with a column heading. * /*from w ww .ja v a2 s.co m*/ * @throws DownloadException */ private Map<TestUtils.DownloadType, List<String[][]>> getAllDownloadData() throws DownloadException { Map<TestUtils.DownloadType, List<String[][]>> retVal = new HashMap(); // Extract the TSV data. // Typically baseUrl is a fully-qualified hostname and path, such as http://ves-ebi-d0:8080/mi/impc/dev/phenotype-arcihve. // getDownloadTargetUrlBase() typically returns a path of the form '/mi/impc/dev/phenotype-archive/export?xxxxxxx...'. // To create the correct url for the stream, replace everything in downloadTargetUrlBase before '/export?' with the baseUrl. String downloadTargetUrlBase = wait .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='exportIconsDivGlobal']"))) .getAttribute("data-exporturl"); String downloadTargetTsv = TestUtils.patchUrl(baseUrl, downloadTargetUrlBase + "tsv", "/export?"); // Get the download stream data. try { URL url = new URL(downloadTargetTsv); DataReaderTsv dataReaderTsv = new DataReaderTsv(url); String[][] allGraphData = dataReaderTsv.getData(); retVal.put(TestUtils.DownloadType.TSV, parseDownloadStream(allGraphData)); } catch (IOException e) { throw new DownloadException("Error parsing TSV", e); } // Extract the XLS data. String downloadTargetXls = TestUtils.patchUrl(baseUrl, downloadTargetUrlBase + "xls", "/export?"); try { URL url = new URL(downloadTargetXls); DataReaderXls dataReaderXls = new DataReaderXls(url); String[][] allGraphData = dataReaderXls.getData(); retVal.put(TestUtils.DownloadType.XLS, parseDownloadStream(allGraphData)); } catch (IOException e) { throw new DownloadException("Error parsing XLS", e); } return retVal; }
From source file:org.mousephenotype.www.testing.model.GraphPage.java
License:Apache License
/** * Load the page and its section and tsv/xls download data. *///from ww w . j a v a2s.c o m private void load() throws GraphTestException { String message; driver.get(graphUrl); // Wait for page to loadScalar. Sometimes the chart isn't loaded when the 'wait()' ends, so try a few times. for (int i = 0; i < 10; i++) { try { WebElement titleElement = wait.until( ExpectedConditions.presenceOfElementLocated(By.xpath("//h2[@id='section-associations']"))); if (titleElement != null) break; } catch (Exception e) { // System.out.println("Waiting " + ((i * 10) + 10) + " milliseconds."); TestUtils.sleep(10); } } // If the page has download links, populate the download data. The map // has two keys: "tsv" and "xls". Each map's data is a list of each section's data. if (hasDownloadLinks()) { Map<TestUtils.DownloadType, List<String[][]>> downloadDataSections = new HashMap(); try { downloadDataSections = getAllDownloadData(); } catch (Exception e) { message = "Exception. URL: " + graphUrl; System.out.println(message); throw new GraphTestException(message, e); } // Populate download downloadSections data. String chartXpath = "//div[@class='section']/div[@class='inner']/div[@class='chart']"; List<WebElement> chartElements = wait .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(chartXpath))); for (int i = 0; i < chartElements.size(); i++) { WebElement chartElement = chartElements.get(i); GraphSection downloadSection = new GraphSection(driver, wait, phenotypePipelineDAO, graphUrl, chartElement, chartType); List<String[][]> allTsvSectionData = downloadDataSections.get(TestUtils.DownloadType.TSV); List<String[][]> allXlsSectionData = downloadDataSections.get(TestUtils.DownloadType.XLS); downloadSection.getDownloadDataSection().put(TestUtils.DownloadType.TSV, allTsvSectionData.get(i)); downloadSection.getDownloadDataSection().put(TestUtils.DownloadType.XLS, allXlsSectionData.get(i)); downloadSections.add(downloadSection); } if (chartElements.size() != downloadSections.size()) { throw new GraphTestException("Size mismatch: Graph page size: " + chartElements.size() + ". Download size: " + downloadDataSections.size() + ". URL: " + graphUrl); } } }
From source file:org.mousephenotype.www.testing.model.PhenotypePage.java
License:Apache License
/** * //from www . j a v a 2s . c om * @return The definition string */ public String getDefinition() { String definition = ""; try { WebElement element = wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("//div[@class='inner']/p[@class='with-label']"))); if (!element.getText().isEmpty()) { if (element.findElement(By.cssSelector("span.label")).getText().trim().equals("Definition")) { definition = element.getText(); } } } catch (Exception e) { } return definition; }
From source file:org.mousephenotype.www.testing.model.PhenotypePage.java
License:Apache License
/** * //w w w. j av a 2 s .co m * @return A list of synonyms. The list will be empty if there are no synonyms. */ public List<String> getSynonyms() { List<String> synonymList = new ArrayList(); try { WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated( By.xpath("//div[@class='inner']/p[@class='with-label']/following-sibling::p"))); if (!element.getText().isEmpty()) { if (element.findElement(By.cssSelector("span.label")).getText().trim().equals("Synonyms")) { String[] synonymArray = element.getText().replace("Synonyms", "").split(","); for (String synonym : synonymArray) { synonymList.add(synonym.trim()); } } } } catch (Exception e) { } return synonymList; }
From source file:org.mousephenotype.www.testing.model.PhenotypePage.java
License:Apache License
/** * Validates that:/*from w w w.j a v a2 s .c o m*/ * <ul> * <li>MGI MP browser has a link, and title starts with <b><i>Phenotype</i></b></li> * <li>There is either a <b><i>Phenotype Association</i></b> section * or an <b><i>Images</i></b> or both.</li> * <li>If there is a <b><i>phenotypes</i></b> HTML table, validates that: * <ul> * <li>Each row has a p-value</li> * <li>Each row has a valid graph link (the graph pages themselves * are not checked here as they take too long)</li> * <li>The sex icon count matches <i>Total number of results</i> count</li> * <li><b><i>TSV</i></b> and <b><i>XLS</i></b> downloads are valid</li> * </ul> * </li> * </ul> * @return validation status */ public PageStatus validate() { PageStatus status = new PageStatus(); // Validate title starts with 'Phenotype:' WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h1[@id='top']"))); if (!element.getText().startsWith("Phenotype:")) { status.addError("Expected phenotype page title to start with 'Phenotype:'."); } // Validate there is a 'Phenotype Association' section or at least one image. try { wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h2[@id='gene-variants']"))); } catch (Exception e) { if (!hasImages()) { status.addError("Expected either 'Phenotype Association' section or 'Images' section or both."); } } // If there is a 'phenotypes' HTML table, validate it. if (hasPhenotypesTable) { // Validate that there is a 'pheontypes' HTML table by loading it. ptPhenotype.load(); // Load all of the phenotypes table pageMap data. List<List<String>> preAndPostQcList = ptPhenotype.getPreAndPostQcList(); String cell; int i = 0; for (List<String> row : preAndPostQcList) { if (i++ == 0) continue; // Verify p value. cell = row.get(PhenotypeTable.COL_INDEX_PHENOTYPES_P_VALUE); if (cell == null) { status.addError("Missing or invalid P Value. URL: " + target); } // Validate that the graph link is not missing. cell = row.get(PhenotypeTable.COL_INDEX_PHENOTYPES_GRAPH_LINK); if ((cell == null) || (cell.trim().isEmpty())) { status.addError("Missing graph link. URL: " + target); } } // Validate the download links. status = validateDownload(); } return status; }
From source file:org.mousephenotype.www.testing.model.PhenotypePage.java
License:Apache License
/** * Waits for the pheno page to load.// www . j av a 2 s . com */ private void load() { driver.get(target); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h2[@id='gene-variants']"))); // Get results count. [NOTE: pages with no matches don't have totals] Integer i; try { WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated( By.xpath("//div[@id='phenotypesDiv']/div[@class='container span12']/p[@class='resultCount']"))); String totResultsString = element.getText(); int index = totResultsString.lastIndexOf(":"); String count = totResultsString.substring(index + 1); i = Utils.tryParseInt(count); } catch (Exception e) { i = null; } // Determine if this page has images. try { WebElement we = wait.until(ExpectedConditions.presenceOfElementLocated(By .xpath("//div[@class='inner']/div[@class='accordion-group']/div[@class='accordion-heading']"))); hasImages = (we.getText().trim().equals("Phenotype Associated Images")); } catch (Exception e) { hasImages = false; } // Determine if this page has phenotype associations. try { wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//table[@id='phenotypes']"))); hasPhenotypesTable = true; } catch (Exception e) { hasPhenotypesTable = false; } resultsCount = (i == null ? 0 : i); hasGraphs = (resultsCount > 0); }
From source file:org.mousephenotype.www.testing.model.PhenotypeTable.java
License:Apache License
/** * Pulls <code>numRows</code> rows of postQc data and column access variables from * the pheno page's 'phenotypes' HTML table. * * @param numRows the number of postQc phenotype table rows to return, including * the heading row. To specify all postQc rows, set <code>numRows</code> to null. * @return <code>numRows</code> rows of data and column access variables * from the pheno page's 'phenotypes' HTML table. *//*from w ww . j a va 2 s . com*/ public GridMap load(Integer numRows) { if (numRows == null) numRows = computeTableRowCount(); String[][] dataArray; preQcList = new ArrayList(); postQcList = new ArrayList(); preAndPostQcList = new ArrayList(); String value; // Wait for page. WebElement phenotypesTable = wait .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("table#phenotypes"))); // Grab the headings. List<WebElement> headings = phenotypesTable.findElements(By.cssSelector("thead tr th")); numRows = Math.min(computeTableRowCount(), numRows); // Take the lesser of: actual row count in HTML table (including heading), or requested numRows. int numCols = headings.size(); dataArray = new String[numRows][numCols]; // Allocate space for the data. int sourceColIndex = 0; for (WebElement heading : headings) { // Copy the heading values. dataArray[0][sourceColIndex] = heading.getText(); sourceColIndex++; } preQcList.add(Arrays.asList(dataArray[0])); postQcList.add(Arrays.asList(dataArray[0])); preAndPostQcList.add(Arrays.asList(dataArray[0])); // Loop through all of the tr objects for this page, gathering the data. int sourceRowIndex = 1; //int rowIndex = 0; for (WebElement row : phenotypesTable.findElements(By.xpath("//table[@id='phenotypes']/tbody/tr"))) { List<WebElement> cells = row.findElements(By.cssSelector("td")); boolean isPreQcLink = false; sourceColIndex = 0; boolean skipLink = false; for (WebElement cell : cells) { //System.out.println("tagName = " + cell.getTagName() + ". text = " h+ cell.getText()); //System.out.println("rowIndex = " + rowIndex++); if (sourceColIndex == COL_INDEX_PHENOTYPES_GENE_ALLELE) { String rawAllele = cell.findElement(By.cssSelector("span.smallerAlleleFont")).getText(); List<WebElement> alleleElements = cell.findElements(By.cssSelector("sup")); if (alleleElements.isEmpty()) { value = rawAllele; // Some genes don't have allele markers. Save the gene symbol. } else { String sup = cell.findElement(By.cssSelector("sup")).getText(); AlleleParser ap = new AlleleParser(rawAllele, sup); value = ap.toString(); } } else if (sourceColIndex == COL_INDEX_PHENOTYPES_PHENOTYPE) { value = cell.findElement(By.cssSelector("a")).getText(); // Get the phenotype text. } else if (sourceColIndex == COL_INDEX_PHENOTYPES_SEX) { // Translate the male/female symbol into a string: 'male', 'female', or 'both'. List<WebElement> sex = cell.findElements(By.xpath("img[@alt='Male' or @alt='Female']")); if (sex.size() == 2) { value = "both"; } else { value = sex.get(0).getAttribute("alt").toLowerCase(); } } else if (sourceColIndex == COL_INDEX_PHENOTYPES_GRAPH_LINK) { // Extract the graph url from the <a> anchor and decode it. // NOTE: Graph links are disabled if there is no supporting data. List<WebElement> graphLinks = cell.findElements(By.cssSelector("a")); value = ""; if (!graphLinks.isEmpty()) { value = graphLinks.get(0).getAttribute("href"); } else { graphLinks = cell.findElements(By.cssSelector("i")); if (!graphLinks.isEmpty()) { value = graphLinks.get(0).getAttribute("oldtitle"); if (value.contains(NO_SUPPORTING_DATA)) { skipLink = true; } } } value = TestUtils.urlDecode(value); isPreQcLink = TestUtils.isPreQcLink(value); } else { value = cell.getText(); } dataArray[sourceRowIndex][sourceColIndex] = value; sourceColIndex++; } // If the graph link is a postQc link, increment the index and return when we have the number of requested rows. if (isPreQcLink) { preQcList.add(Arrays.asList(dataArray[sourceRowIndex])); // Add the row to the preQc list. } else { if (!skipLink) { postQcList.add(Arrays.asList(dataArray[sourceRowIndex])); // Add the row to the postQc list. if (postQcList.size() >= numRows) { // Return when we have the number of requested rows. data = new GridMap(postQcList, target); return data; } } } preAndPostQcList.add(Arrays.asList(dataArray[sourceRowIndex])); // Add the row to the preQc- and postQc-list. sourceRowIndex++; } data = new GridMap(postQcList, target); return data; }